Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix test coverage.
James Colef6d88521ddec
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.phpindex 5ab98a0e02..c290fe557b 100644--- a/app/Http/Controllers/Chart/CategoryController.php+++ b/app/Http/Controllers/Chart/CategoryController.php@@ -158,7 +158,7 @@ class CategoryController extends Controller** @return JsonResponse*/- public function frontpage(CategoryRepositoryInterface $repository, AccountRepositoryInterface $accountRepository): JsonResponse+ public function frontPage(CategoryRepositoryInterface $repository, AccountRepositoryInterface $accountRepository): JsonResponse{$start = session('start', Carbon::now()->startOfMonth());$end = session('end', Carbon::now()->endOfMonth());@@ -168,7 +168,7 @@ class CategoryController extends Controller$cache->addProperty($end);$cache->addProperty('chart.category.frontpage');if ($cache->has()) {- return response()->json($cache->get()); // @codeCoverageIgnore+ //return response()->json($cache->get()); // @codeCoverageIgnore}// currency repos:@@ -200,14 +200,15 @@ class CategoryController extends Controller}}}+// no category per currency:$noCategory = $repository->spentInPeriodPcWoCategory(new Collection, $start, $end);foreach ($noCategory as $currencyId => $spent) {$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);$tempData[] = ['name' => trans('firefly.no_category'),- 'spent' => bcmul($spent, '-1'),- 'spent_float' => (float)bcmul($spent, '-1'),+ 'spent' => bcmul($spent['spent'], '-1'),+ 'spent_float' => (float)bcmul($spent['spent'], '-1'),'currency_id' => $currencyId,];}diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.phpindex f665e5b4b2..53f45f5344 100644--- a/app/Transformers/AccountTransformer.php+++ b/app/Transformers/AccountTransformer.php@@ -133,9 +133,9 @@ class AccountTransformer extends AbstractTransformer** @param string $accountType*- * @return string+ * @return string|null*/- private function getAccountRole(Account $account, string $accountType): string+ private function getAccountRole(Account $account, string $accountType): ?string{$accountRole = $this->repository->getMetaValue($account, 'accountRole');if ('asset' !== $accountType || '' === (string)$accountRole) {@@ -146,13 +146,13 @@ class AccountTransformer extends AbstractTransformer}/**- * @param Account $account- * @param string $accountRole- * @param string $accountType+ * @param Account $account+ * @param string|null $accountRole+ * @param string $accountType** @return array*/- private function getCCInfo(Account $account, string $accountRole, string $accountType): array+ private function getCCInfo(Account $account, ?string $accountRole, string $accountType): array{$monthlyPaymentDate = null;$creditCardType = null;diff --git a/routes/web.php b/routes/web.phpindex ec19b2da72..10be4ae45c 100644--- a/routes/web.php+++ b/routes/web.php@@ -371,7 +371,7 @@ Route::group(['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Chart', 'prefix' => 'chart/category', 'as' => 'chart.category.'],function () {- Route::get('frontpage', ['uses' => 'CategoryController@frontpage', 'as' => 'frontpage']);+ Route::get('frontpage', ['uses' => 'CategoryController@frontPage', 'as' => 'frontpage']);Route::get('period/{category}', ['uses' => 'CategoryController@currentPeriod', 'as' => 'current']);Route::get('period/{category}/{date}', ['uses' => 'CategoryController@specificPeriod', 'as' => 'specific']);Route::get('all/{category}', ['uses' => 'CategoryController@all', 'as' => 'all']);diff --git a/tests/Api/V1/Controllers/PreferencesControllerTest.php b/tests/Api/V1/Controllers/PreferencesControllerTest.phpindex 704d54ef34..42771a27d6 100644--- a/tests/Api/V1/Controllers/PreferencesControllerTest.php+++ b/tests/Api/V1/Controllers/PreferencesControllerTest.php@@ -60,6 +60,11 @@ class PreferencesControllerTest extends TestCaseforeach ($available as $pref) {Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), $pref])->once();}+ // extra call for frontpage preference+ $pref = new Preference;+ $pref->data =[1];+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'frontPageAccounts',[]])->once()+ ->andReturn($pref);// mock calls to transformer:$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();diff --git a/tests/Feature/Controllers/Chart/AccountControllerTest.php b/tests/Feature/Controllers/Chart/AccountControllerTest.phpindex 02a56627fe..aaa73902a9 100644--- a/tests/Feature/Controllers/Chart/AccountControllerTest.php+++ b/tests/Feature/Controllers/Chart/AccountControllerTest.php@@ -80,7 +80,7 @@ class AccountControllerTest extends TestCase$end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];// return them when collected:- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->andReturn($accounts);+ $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])->andReturn($accounts);// and return start and end balances:Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);diff --git a/tests/Feature/Controllers/Chart/CategoryControllerTest.php b/tests/Feature/Controllers/Chart/CategoryControllerTest.phpindex 974c1131de..cc26def5a6 100644--- a/tests/Feature/Controllers/Chart/CategoryControllerTest.php+++ b/tests/Feature/Controllers/Chart/CategoryControllerTest.php@@ -83,16 +83,37 @@ class CategoryControllerTest extends TestCase** @param string $range*/- public function testFrontpage(string $range): void+ public function testFrontPage(string $range): void{$repository = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$generator = $this->mock(GeneratorInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+// spent per currency data:- $spentData = [- 1 => '-123.45',- 2 => '567.21',+ $spentNoCategory = [+ 1 =>+ [+ 'spent' => '-123.45',+ 'currency_id' => 1,+ 'currency_code' => 'X',+ 'currency_symbol' => 'x',+ 'currency_decimal_places' => 2,+ ],+ ];+ $spentData = [+ 1 => [+ 'name' => 'Car',+ 'spent' => [+ 1 => [+ 'spent' => '-123.45',+ 'currency_id' => 2,+ 'currency_code' => 'a',+ 'currency_symbol' => 'b',+ 'currency_decimal_places' => 2,+ ],+ ],+ ],];// grab two categories from the user@@ -105,20 +126,10 @@ class CategoryControllerTest extends TestCase$repository->shouldReceive('getCategories')->andReturn($categories)->once();$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn($accounts);- $repository->shouldReceive('spentInPeriodPerCurrency')- ->times(2)->andReturn($spentData);- $repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentData);+ $repository->shouldReceive('spentInPeriodPerCurrency')->times(2)->andReturn($spentData);+ $repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentNoCategory);$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));- $currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));-- //$category = factory(Category::class)->make();- //$account = factory(Account::class)->make();--- // $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));- // $repository->shouldReceive('spentInPeriod')->andReturn('0');- // $repository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');$generator->shouldReceive('multiSet')->andReturn([]);$this->be($this->user());@@ -132,10 +143,10 @@ class CategoryControllerTest extends TestCase*/public function testReportPeriod(): void{- $repository = $this->mock(CategoryRepositoryInterface::class);- $generator = $this->mock(GeneratorInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $generator = $this->mock(GeneratorInterface::class);+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('periodExpenses')->andReturn([])->once();@@ -152,10 +163,10 @@ class CategoryControllerTest extends TestCase*/public function testReportPeriodNoCategory(): void{- $repository = $this->mock(CategoryRepositoryInterface::class);- $generator = $this->mock(GeneratorInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $generator = $this->mock(GeneratorInterface::class);+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();@@ -179,8 +190,8 @@ class CategoryControllerTest extends TestCase$accountRepos = $this->mock(AccountRepositoryInterface::class);$generator = $this->mock(GeneratorInterface::class);$account = factory(Account::class)->make();- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);