mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-16 22:58:09 +00:00
Improve test coverage.
This commit is contained in:
@@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -33,6 +33,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -61,13 +62,39 @@ class CategoryControllerTest extends TestCase
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$firstUse = new Carbon;
|
||||
$firstUse->subDays(3);
|
||||
$firstUseDate = null;
|
||||
switch ($range) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('No case for %s', $range));
|
||||
case '1D':
|
||||
$firstUseDate = Carbon::now()->subDays(3);
|
||||
break;
|
||||
case '1W':
|
||||
$firstUseDate = Carbon::now()->subDays(12);
|
||||
break;
|
||||
case '1M':
|
||||
$firstUseDate = Carbon::now()->subDays(40);
|
||||
break;
|
||||
case '3M':
|
||||
$firstUseDate = Carbon::now()->subDays(120);
|
||||
break;
|
||||
case '6M':
|
||||
$firstUseDate = Carbon::now()->subDays(160);
|
||||
break;
|
||||
case '1Y':
|
||||
$firstUseDate = Carbon::now()->subDays(365);
|
||||
break;
|
||||
case 'custom':
|
||||
$firstUseDate = Carbon::now()->subDays(20);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||
$repository->shouldReceive('firstUseDate')->andReturn($firstUse)->once();
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('0')->atLeast()->once();
|
||||
$repository->shouldReceive('earnedInPeriod')->andReturn('0')->atLeast()->once();
|
||||
$repository->shouldReceive('firstUseDate')->andReturn($firstUseDate)->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
|
||||
$generator->shouldReceive('multiSet')->once()->andReturn([]);
|
||||
|
||||
@@ -90,6 +117,9 @@ class CategoryControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
// spent per currency data:
|
||||
$spentNoCategory = [
|
||||
1 =>
|
||||
@@ -147,6 +177,10 @@ class CategoryControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
|
||||
@@ -167,6 +201,10 @@ class CategoryControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
|
||||
@@ -189,9 +227,13 @@ class CategoryControllerTest extends TestCase
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$account = factory(Account::class)->make();
|
||||
$account = $this->getRandomAsset();
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user