diff --git a/README.md b/README.md index 976c4f4772..d9d66ad662 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Firefly III -#### v3.4.0.7 +#### v3.4.0.8 [![Build Status](https://travis-ci.org/JC5/firefly-iii.svg?branch=develop)](https://travis-ci.org/JC5/firefly-iii) [![Project Status](http://stillmaintained.com/JC5/firefly-iii.png?a=b)](http://stillmaintained.com/JC5/firefly-iii) diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 6359ade1b6..ce160a0d88 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -33,6 +33,7 @@ class ReportHelper implements ReportHelperInterface protected $query; /** + * @codeCoverageIgnore * @param ReportQueryInterface $query * */ diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index a2fd5ee077..78f4295ea2 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -22,61 +22,6 @@ use Steam; */ class ReportQuery implements ReportQueryInterface { - - /** - * This method returns all "expense" journals in a certain period, which are both transfers to a shared account - * and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does - * not group and returns different fields. - * - * @param Carbon $start - * @param Carbon $end - * @param bool $includeShared - * - * @return Collection - * - */ - public function expenseInPeriod(Carbon $start, Carbon $end, $includeShared = false) - { - $query = $this->queryJournalsWithTransactions($start, $end); - if ($includeShared === false) { - $query->where( - function (Builder $query) { - $query->where( - function (Builder $q) { // only get withdrawals not from a shared account - $q->where('transaction_types.type', 'Withdrawal'); - $q->where('acm_from.data', '!=', '"sharedAsset"'); - } - ); - $query->orWhere( - function (Builder $q) { // and transfers from a shared account. - $q->where('transaction_types.type', 'Transfer'); - $q->where('acm_to.data', '=', '"sharedAsset"'); - } - ); - } - ); - } else { - $query->where('transaction_types.type', 'Withdrawal'); // any withdrawal is fine. - } - $query->groupBy('transaction_journals.id')->orderBy('transaction_journals.date'); - - // get everything, decrypt and return - $data = $query->get( - ['transaction_journals.id', 'transaction_journals.description', 'transaction_journals.encrypted', 'transaction_types.type', - DB::Raw('SUM(`t_from`.`amount`) as `queryAmount`'), - 'transaction_journals.date', 't_to.account_id as account_id', 'ac_to.name as name', 'ac_to.encrypted as account_encrypted'] - ); - - $data->each( - function (Model $object) { - $object->name = intval($object->account_encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; - } - ); - $data->sortByDesc('queryAmount'); - - return $data; - } - /** * See ReportQueryInterface::incomeInPeriodCorrected * @@ -184,73 +129,16 @@ class ReportQuery implements ReportQueryInterface return $set; } - /** - * This method returns all "income" journals in a certain period, which are both transfers from a shared account - * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does - * not group and returns different fields. - * - * @param Carbon $start - * @param Carbon $end - * @param bool $includeShared - * - * @return Collection - */ - public function incomeInPeriod(Carbon $start, Carbon $end, $includeShared = false) - { - $query = $this->queryJournalsWithTransactions($start, $end); - if ($includeShared === false) { - // only get deposits not to a shared account - // and transfers to a shared account. - $query->where( - function (Builder $query) { - $query->where( - function (Builder $q) { - $q->where('transaction_types.type', 'Deposit'); - $q->where('acm_to.data', '!=', '"sharedAsset"'); - } - ); - $query->orWhere( - function (Builder $q) { - $q->where('transaction_types.type', 'Transfer'); - $q->where('acm_from.data', '=', '"sharedAsset"'); - } - ); - } - ); - } else { - // any deposit is fine. - $query->where('transaction_types.type', 'Deposit'); - } - $query->groupBy('transaction_journals.id')->orderBy('transaction_journals.date'); - - // get everything, decrypt and return - $data = $query->get( - ['transaction_journals.id', - 'transaction_journals.description', - 'transaction_journals.encrypted', - 'transaction_types.type', - DB::Raw('SUM(`t_to`.`amount`) as `queryAmount`'), - 'transaction_journals.date', - 't_from.account_id as account_id', - 'ac_from.name as name', - 'ac_from.encrypted as account_encrypted' - ] - ); - - $data->each( - function (Model $object) { - $object->name = intval($object->account_encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; - } - ); - $data->sortByDesc('queryAmount'); - - return $data; - } /** * This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results * will simply list the transaction journals only. This should allow any follow up counting to be accurate with * regards to tags. + * + * This method returns all "income" journals in a certain period, which are both transfers from a shared account + * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does + * not group and returns different fields. + * * @param Carbon $start * @param Carbon $end @@ -309,31 +197,6 @@ class ReportQuery implements ReportQueryInterface return $data; } - /** - * @param Account $account - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * - * @return float - */ - public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end) - { - - return floatval( - Auth::user()->transactionjournals() - ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->transactionTypes(['Withdrawal']) - ->where('transactions.amount', '<', 0) - ->where('transactions.account_id', $account->id) - ->before($end) - ->after($start) - ->where('budget_transaction_journal.budget_id', $budget->id) - ->sum('transactions.amount') - ); - } - /** * Covers tags * diff --git a/app/Helpers/Report/ReportQueryInterface.php b/app/Helpers/Report/ReportQueryInterface.php index 1ecf9f9f21..fc46ab8255 100644 --- a/app/Helpers/Report/ReportQueryInterface.php +++ b/app/Helpers/Report/ReportQueryInterface.php @@ -16,6 +16,8 @@ interface ReportQueryInterface { /** + * See ReportQueryInterface::incomeInPeriodCorrected + * * This method returns all "expense" journals in a certain period, which are both transfers to a shared account * and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does * not group and returns different fields. @@ -27,18 +29,6 @@ interface ReportQueryInterface * @return Collection * */ - public function expenseInPeriod(Carbon $start, Carbon $end, $includeShared = false); - - /** - * See ReportQueryInterface::incomeInPeriodCorrected - * - * @param Carbon $start - * @param Carbon $end - * @param bool $includeShared - * - * @return Collection - * - */ public function expenseInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false); /** @@ -52,20 +42,6 @@ interface ReportQueryInterface */ public function getAllAccounts(Carbon $start, Carbon $end, $includeShared = false); - /** - * This method returns all "income" journals in a certain period, which are both transfers from a shared account - * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does - * not group and returns different fields. - * - * @param Carbon $start - * @param Carbon $end - * @param bool $includeShared - * - * @return Collection - * - */ - public function incomeInPeriod(Carbon $start, Carbon $end, $includeShared = false); - /** * This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results * will simply list the transaction journals only. This should allow any follow up counting to be accurate with @@ -79,16 +55,6 @@ interface ReportQueryInterface */ public function incomeInPeriodCorrected(Carbon $start, Carbon $end, $includeShared = false); - /** - * @param Account $account - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * - * @return float - */ - public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end); - /** * Covers tags as well. * diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 3d35eff2a0..1a0b4f0823 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -49,9 +49,11 @@ class BudgetRepository implements BudgetRepositoryInterface * * @return float */ - public function expensesOnDay(Budget $budget, Carbon $date) + public function expensesOnDayCorrected(Budget $budget, Carbon $date) { - return floatval($budget->transactionjournals()->lessThan(0)->transactionTypes(['Withdrawal'])->onDate($date)->sum('amount')); + $sum = floatval($budget->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount')); + + return $sum * -1; } /** @@ -255,39 +257,6 @@ class BudgetRepository implements BudgetRepositoryInterface return floatval($noBudgetSet) * -1; } - /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * @param bool $shared - * - * @return float - */ - public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true) - { - if ($shared === true) { - // get everything: - $sum = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1; - } else { - // get all journals in this month where the asset account is NOT shared. - $sum = $budget->transactionjournals() - ->before($end) - ->after($start) - ->lessThan(0) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->sum('amount'); - $sum = floatval($sum) * -1; - } - - return $sum; - } - /** * @param Budget $budget * @param Carbon $start @@ -340,17 +309,7 @@ class BudgetRepository implements BudgetRepositoryInterface return $newBudget; } - /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * - * @return float - */ - public function sumBudgetExpensesInPeriod(Budget $budget, $start, $end) - { - return floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1; - } + /** * @param Budget $budget @@ -407,17 +366,4 @@ class BudgetRepository implements BudgetRepositoryInterface } - - /** - * @param Budget $budget - * @param Carbon $date - * - * @return float - */ - public function expensesOnDayCorrected(Budget $budget, Carbon $date) - { - $sum = floatval($budget->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount')); - - return $sum * -1; - } } diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 384893acef..b928ed35df 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -26,14 +26,6 @@ interface BudgetRepositoryInterface */ public function destroy(Budget $budget); - /** - * @param Budget $budget - * @param Carbon $date - * - * @return float - */ - public function expensesOnDay(Budget $budget, Carbon $date); - /** * Takes tags into account. * @@ -132,17 +124,6 @@ interface BudgetRepositoryInterface */ public function getWithoutBudgetSum(Carbon $start, Carbon $end); - - /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * @param boolean $shared - * - * @return float - */ - public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true); - /** * * Same as ::spentInPeriod but corrects journals for their amount (tags). @@ -163,15 +144,6 @@ interface BudgetRepositoryInterface */ public function store(array $data); - /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * - * @return float - */ - public function sumBudgetExpensesInPeriod(Budget $budget, $start, $end); - /** * @param Budget $budget * @param array $data diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 55963029bf..a6c7de1d3c 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -58,36 +58,6 @@ class CategoryRepository implements CategoryRepositoryInterface return $set; } - /** - * @param Carbon $start - * @param Carbon $end - * - * @return Collection - */ - public function getCategoriesAndExpenses($start, $end) - { - return TransactionJournal:: - where('transaction_journals.user_id', Auth::user()->id) - ->leftJoin( - 'transactions', - function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); - } - ) - ->leftJoin( - 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' - ) - ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->before($end) - ->where('categories.user_id', Auth::user()->id) - ->after($start) - ->where('transaction_types.type', 'Withdrawal') - ->groupBy('categories.id') - ->orderBy('sum', 'DESC') - ->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]); - } - /** * * @param Carbon $start @@ -205,48 +175,6 @@ class CategoryRepository implements CategoryRepositoryInterface ->get(['transaction_journals.*']); } - /** - * @param Category $category - * @param Carbon $start - * @param Carbon $end - * - * @param bool $shared - * - * @return float - */ - public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false) - { - if ($shared === true) { - // shared is true. - // always ignore transfers between accounts! - $sum = floatval( - $category->transactionjournals() - ->transactionTypes(['Withdrawal']) - ->before($end)->after($start)->lessThan(0)->sum('amount') - ) * -1; - - } else { - // do something else, SEE budgets. - // get all journals in this month where the asset account is NOT shared. - $sum = $category->transactionjournals() - ->before($end) - ->after($start) - ->transactionTypes(['Withdrawal']) - ->lessThan(0) - ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') - ->leftJoin( - 'account_meta', function (JoinClause $join) { - $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); - } - ) - ->where('account_meta.data', '!=', '"sharedAsset"') - ->sum('amount'); - $sum = floatval($sum) * -1; - } - - return $sum; - } - /** * @param Category $category * @param Carbon $start @@ -289,17 +217,6 @@ class CategoryRepository implements CategoryRepositoryInterface return $sum; } - /** - * @param Category $category - * @param Carbon $date - * - * @return float - */ - public function spentOnDaySum(Category $category, Carbon $date) - { - return floatval($category->transactionjournals()->onDate($date)->lessThan(0)->sum('amount')) * -1; - } - /** * Corrected for tags * diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index 9f282c84fe..524b2ce443 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -32,14 +32,6 @@ interface CategoryRepositoryInterface */ public function getCategories(); - /** - * @param Carbon $start - * @param Carbon $end - * - * @return Collection - */ - public function getCategoriesAndExpenses($start, $end); - /** * Corrected for tags. * @@ -80,17 +72,6 @@ interface CategoryRepositoryInterface */ public function getWithoutCategory(Carbon $start, Carbon $end); - /** - * @param Category $category - * @param \Carbon\Carbon $start - * @param \Carbon\Carbon $end - * - * @param bool $shared - * - * @return float - */ - public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false); - /** * Corrected for tags. * @@ -104,14 +85,6 @@ interface CategoryRepositoryInterface */ public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false); - /** - * @param Category $category - * @param Carbon $date - * - * @return float - */ - public function spentOnDaySum(Category $category, Carbon $date); - /** * * Corrected for tags. diff --git a/tests/controllers/TransactionControllerTest.php b/tests/controllers/TransactionControllerTest.php index c76270c5cd..c2d3924963 100644 --- a/tests/controllers/TransactionControllerTest.php +++ b/tests/controllers/TransactionControllerTest.php @@ -275,6 +275,65 @@ class TransactionControllerTest extends TestCase } + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testStoreTransfer() + { + // account types: + FactoryMuffin::create('FireflyIII\Models\AccountType'); + FactoryMuffin::create('FireflyIII\Models\AccountType'); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account2 = FactoryMuffin::create('FireflyIII\Models\Account'); + $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + + $piggy = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $this->be($account->user); + + $account2->user_id = $account->user_id; + $account->account_type_id = $asset->id; + $account2->account_type_id = $asset->id; + $piggy->account_id = $account->id; + $account->save(); + $account2->save(); + $piggy->save(); + + $data = [ + 'reminder_id' => '', + 'what' => 'transfer', + 'description' => 'Bla bla bla', + 'account_from_id' => $account->id, + 'account_to_id' => $account2->id, + 'amount' => '100', + 'amount_currency_id' => $currency->id, + 'date' => '2015-05-05', + 'budget_id' => '0', + 'create_another' => '1', + 'category' => '', + 'tags' => '', + 'piggy_bank_id' => $piggy->id, + '_token' => 'replaceMe', + ]; + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface'); + + // fake! + $repository->shouldReceive('store')->andReturn($journal); + $repository->shouldReceive('deactivateReminder')->andReturnNull(); + + + $this->call('POST', '/transactions/store/withdrawal', $data); + + //$this->assertSessionHas('errors','bla'); + $this->assertResponseStatus(302); + $this->assertSessionHas('success'); + + } /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) diff --git a/tests/controllers/charts/ChartAccountControllerTest.php b/tests/controllers/charts/ChartAccountControllerTest.php index ed6c9fd02d..5e5cf56996 100644 --- a/tests/controllers/charts/ChartAccountControllerTest.php +++ b/tests/controllers/charts/ChartAccountControllerTest.php @@ -1,5 +1,10 @@ markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + FactoryMuffin::create('FireflyIII\Models\AccountType'); + FactoryMuffin::create('FireflyIII\Models\AccountType'); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $one = FactoryMuffin::create('FireflyIII\Models\Account'); + $two = FactoryMuffin::create('FireflyIII\Models\Account'); + $one->account_type_id = $asset->id; + $two->account_type_id = $asset->id; + $one->save(); + $two->save(); + $accounts = new Collection([$one, $two]); + $date = new Carbon; + $this->be($user); + + // make one shared: + AccountMeta::create( + [ + 'account_id' => $one->id, + 'name' => 'accountRole', + 'data' => 'sharedAsset' + ] + ); + + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + // fake! + $repository->shouldReceive('getAccounts')->once()->andReturn($accounts); + + $this->call('GET', '/chart/account/month/' . $date->format('Y/m')); + $this->assertResponseOk(); + } + + public function testAllShared() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $accounts = new Collection([$account]); + $date = new Carbon; + $this->be($user); + + // make it shared: + AccountMeta::create( + [ + 'account_id' => $account->id, + 'name' => 'accountRole', + 'data' => 'sharedAsset' + ] + ); + + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + // fake! + $repository->shouldReceive('getAccounts')->once()->andReturn($accounts); + + + $this->call('GET', '/chart/account/month/' . $date->format('Y/m') . '/shared'); + $this->assertResponseOk(); } public function testFrontpage() { - $this->markTestIncomplete(); + $accounts = new Collection([FactoryMuffin::create('FireflyIII\Models\Account')]); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + // fake! + $repository->shouldReceive('getFrontpageAccounts')->andReturn($accounts); + + $this->call('GET', '/chart/account/frontpage'); + $this->assertResponseOk(); + } public function testSingle() { - $this->markTestIncomplete(); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $this->be($account->user); + + $this->call('GET', '/chart/account/' . $account->id); + $this->assertResponseOk(); + } } diff --git a/tests/controllers/charts/ChartBillControllerTest.php b/tests/controllers/charts/ChartBillControllerTest.php index 7d90eb5e0c..a83372d93b 100644 --- a/tests/controllers/charts/ChartBillControllerTest.php +++ b/tests/controllers/charts/ChartBillControllerTest.php @@ -1,5 +1,9 @@ be($user); + + } public function testFrontpage() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + // set! + $bills = new Collection([FactoryMuffin::create('FireflyIII\Models\Bill'), FactoryMuffin::create('FireflyIII\Models\Bill')]); + $journals = new Collection( + [FactoryMuffin::create('FireflyIII\Models\TransactionJournal'), FactoryMuffin::create('FireflyIII\Models\TransactionJournal')] + ); + $creditCards = new Collection([FactoryMuffin::create('FireflyIII\Models\Account'), FactoryMuffin::create('FireflyIII\Models\Account')]); + $ranges = [['start' => new Carbon, 'end' => new Carbon]]; + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface'); + $accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + + // fake! + $repository->shouldReceive('getActiveBills')->andReturn($bills); + $repository->shouldReceive('getRanges')->andReturn($ranges); + $repository->shouldReceive('getJournalsInRange')->andReturn(new Collection, $journals); + $accounts->shouldReceive('getCreditCards')->andReturn($creditCards); + $accounts->shouldReceive('getTransfersInRange')->andReturn(new Collection); + $repository->shouldReceive('createFakeBill')->andReturn($bills->first()); + Steam::shouldReceive('balance')->andReturn(-10,0); + + + $this->call('GET', '/chart/bill/frontpage'); + $this->assertResponseOk(); + } public function testSingle() { - $this->markTestIncomplete(); + $bill = FactoryMuffin::create('FireflyIII\Models\Bill'); + $this->be($bill->user); + + // set + $journals = new Collection([FactoryMuffin::create('FireflyIII\Models\TransactionJournal')]); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface'); + $repository->shouldReceive('getJournals')->andReturn($journals); + + // fake! + + $this->call('GET', '/chart/bill/' . $bill->id); + $this->assertResponseOk(); + } diff --git a/tests/controllers/charts/ChartBudgetControllerTest.php b/tests/controllers/charts/ChartBudgetControllerTest.php index 2cfe66339c..6017478d96 100644 --- a/tests/controllers/charts/ChartBudgetControllerTest.php +++ b/tests/controllers/charts/ChartBudgetControllerTest.php @@ -1,4 +1,8 @@ markTestIncomplete(); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); + $this->be($budget->user); + + $this->call('GET', '/chart/budget/' . $budget->id); + $this->assertResponseOk(); + + + } + + public function testBudgetLimit() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); + /** @var \FireflyIII\Models\BudgetLimit $limit */ + $limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit'); + /** @var \FireflyIII\Models\LimitRepetition $repetition */ + $repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition'); + + $start = Carbon::now()->startOfMonth(); + $end = Carbon::now()->endOfMonth(); + + $budget->user_id = $user->id; + $limit->budget_id = $budget->id; + $limit->startdate = $start; + $repetition->budget_limit_id = $limit->id; + $repetition->startdate = $start; + $repetition->enddate = $end; + + $budget->save(); + $limit->save(); + $repetition->save(); + + + $this->be($user); + + $this->call('GET', '/chart/budget/' . $budget->id . '/' . $repetition->id); + $this->assertResponseOk(); } public function testFrontpage() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $start = Carbon::now()->startOfMonth(); + $end = Carbon::now()->endOfMonth(); + $budgets = new Collection; + $limits = []; + $repetitions = []; + + for ($i = 0; $i < 5; $i++) { + /** @var \FireflyIII\Models\Budget $budget */ + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); + $budgets->push($budget); + + /** @var \FireflyIII\Models\BudgetLimit $limit */ + $limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit'); + $limit->budget_id = $budget->id; + $limit->startdate = $start; + $limit->save(); + + $set = new Collection([$limit]); + $limits[] = $set; + + /** @var \FireflyIII\Models\LimitRepetition $repetition */ + $repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition'); + $repetition->budget_limit_id = $limit->id; + $repetition->startdate = $start; + $repetition->enddate = $end; + $repetition->save(); + $set = new Collection([$repetition]); + $repetitions[] = $set; + } + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + + // fake! + $repository->shouldReceive('getBudgets')->andReturn($budgets); + $repository->shouldReceive('getBudgetLimitRepetitions')->andReturn($repetitions[0], $repetitions[1], new Collection); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(10); + $repository->shouldReceive('getWithoutBudgetSum')->andReturn(10); + + $this->call('GET', '/chart/budget/frontpage'); + $this->assertResponseOk(); } public function testYear() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); + $collection = new Collection([$budget]); + $this->be($user); + + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + + // fake! + $repository->shouldReceive('getBudgets')->andReturn($collection); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(0); + + + $this->call('GET', '/chart/budget/year/2015'); + $this->assertResponseOk(); + } + + public function testYearShared() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $this->call('GET', '/chart/budget/year/2015/shared'); + $this->assertResponseOk(); } } diff --git a/tests/controllers/charts/ChartCategoryControllerTest.php b/tests/controllers/charts/ChartCategoryControllerTest.php index ee491763ac..f533e7459b 100644 --- a/tests/controllers/charts/ChartCategoryControllerTest.php +++ b/tests/controllers/charts/ChartCategoryControllerTest.php @@ -1,5 +1,8 @@ markTestIncomplete(); + + $category = FactoryMuffin::create('FireflyIII\Models\Category'); + $this->be($category->user); + + $this->call('GET', '/chart/category/'.$category->id.'/all'); + $this->assertResponseOk(); + + } public function testFrontpage() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + // make data: + $set = [ + ['name' => 'Something', 'sum' => 100], + ['name' => 'Something Else', 'sum' => 200], + ['name' => 'Something Else Entirely', 'sum' => 200] + ]; + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); + + // fake! + $repository->shouldReceive('getCategoriesAndExpensesCorrected')->andReturn($set); + + //getCategoriesAndExpensesCorrected + + $this->call('GET', '/chart/category/frontpage'); + $this->assertResponseOk(); } public function testMonth() { - $this->markTestIncomplete(); + $category = FactoryMuffin::create('FireflyIII\Models\Category'); + $this->be($category->user); + + $this->call('GET', '/chart/category/'.$category->id.'/month'); + $this->assertResponseOk(); } public function testYear() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $categories = new Collection([FactoryMuffin::create('FireflyIII\Models\Category')]); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); + + // fake! + $repository->shouldReceive('getCategories')->andReturn($categories); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(0); + + $this->call('GET', '/chart/category/year/2015'); + $this->assertResponseOk(); + } + + public function testYearShared() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $categories = new Collection([FactoryMuffin::create('FireflyIII\Models\Category')]); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); + + // fake! + $repository->shouldReceive('getCategories')->andReturn($categories); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(0); + + $this->call('GET', '/chart/category/year/2015/shared'); + $this->assertResponseOk(); } } diff --git a/tests/controllers/charts/ChartPiggyBankControllerTest.php b/tests/controllers/charts/ChartPiggyBankControllerTest.php index 2d61d83da2..bdb9038254 100644 --- a/tests/controllers/charts/ChartPiggyBankControllerTest.php +++ b/tests/controllers/charts/ChartPiggyBankControllerTest.php @@ -1,5 +1,7 @@ markTestIncomplete(); + $piggy = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); + $this->be($piggy->account->user); + + // data: + $obj = new stdClass; + $obj->sum = 100; + $obj->date = '2015-01-01'; + $set = [ + $obj + ]; + + // mock! + $repository = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface'); + + // fake! + $repository->shouldReceive('getEventSummarySet')->andReturn($set); + + $this->call('GET', '/chart/piggyBank/' . $piggy->id); + $this->assertResponseOk(); } } diff --git a/tests/controllers/charts/ChartReportControllerTest.php b/tests/controllers/charts/ChartReportControllerTest.php index 68a40914f3..0579fddafe 100644 --- a/tests/controllers/charts/ChartReportControllerTest.php +++ b/tests/controllers/charts/ChartReportControllerTest.php @@ -1,5 +1,7 @@ markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $this->call('GET', '/chart/report/in-out/2015'); + $this->assertResponseOk(); + + } + + public function testYearInOutShared() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $this->call('GET', '/chart/report/in-out/2015/shared'); + $this->assertResponseOk(); + } public function testYearInOutSummarized() { - $this->markTestIncomplete(); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $this->call('GET', '/chart/report/in-out-sum/2015'); + $this->assertResponseOk(); + } + + public function testYearInOutSummarizedShared() + { + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $this->call('GET', '/chart/report/in-out-sum/2015/shared'); + $this->assertResponseOk(); } } diff --git a/tests/helpers/ReminderHelperTest.php b/tests/helpers/ReminderHelperTest.php index 622788c42e..38b4b0b5cd 100644 --- a/tests/helpers/ReminderHelperTest.php +++ b/tests/helpers/ReminderHelperTest.php @@ -87,6 +87,27 @@ class ReminderHelperTest extends TestCase $this->assertEquals(0, $result->metadata->leftToSave); } + /** + * + */ + public function testCreateReminders() + { + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); + $piggyBank->account_id = $account->id; + $piggyBank->startdate = new Carbon('2015-01-01'); + $piggyBank->targetdate = new Carbon('2015-12-31'); + $piggyBank->reminder = 'monthly'; + $piggyBank->remind_me = true; + $piggyBank->save(); + $this->be($account->user); + + $this->object->createReminders($piggyBank, new Carbon('2015-05-05')); + + $this->assertCount(1, $piggyBank->reminders()->get()); + + } + public function testGetReminderRangesNull() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); diff --git a/tests/helpers/ReportHelperTest.php b/tests/helpers/ReportHelperTest.php index 9d6e1b71c9..9fc169d107 100644 --- a/tests/helpers/ReportHelperTest.php +++ b/tests/helpers/ReportHelperTest.php @@ -1,10 +1,12 @@ object = new ReportHelper($query); } @@ -38,6 +40,307 @@ class ReportHelperTest extends TestCase parent::tearDown(); } + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getAccountReport + * @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts + */ + public function testGetAccountReport() + { + FactoryMuffin::create('FireflyIII\Models\AccountType'); + FactoryMuffin::create('FireflyIII\Models\AccountType'); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $user = FactoryMuffin::create('FireflyIII\User'); + for ($i = 0; $i < 5; $i++) { + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account->user_id = $user->id; + $account->account_type_id = $asset->id; + $account->save(); + } + $this->be($user); + /** @var AccountCollection $object */ + $object = $this->object->getAccountReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); + + $this->assertCount(5, $object->getAccounts()); + $this->assertEquals(0, $object->getDifference()); + $this->assertEquals(0, $object->getEnd()); + $this->assertEquals(0, $object->getStart()); + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getBalanceReport + * @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts + * @covers FireflyIII\Helpers\Report\ReportQuery::spentInBudgetCorrected + */ + public function testGetBalanceReport() + { + // factory! + FactoryMuffin::create('FireflyIII\Models\AccountType'); + FactoryMuffin::create('FireflyIII\Models\AccountType'); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $user = FactoryMuffin::create('FireflyIII\User'); + $rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition'); + for ($i = 0; $i < 5; $i++) { + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account->user_id = $user->id; + $account->account_type_id = $asset->id; + $account->save(); + } + + $set = new Collection; + for ($i = 0; $i < 5; $i++) { + $set->push(FactoryMuffin::create('FireflyIII\Models\Budget')); + } + + $this->be($user); + + // mock! + $budgetRepos = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + $tagRepos = $this->mock('FireflyIII\Repositories\Tag\TagRepositoryInterface'); + + // fake! + $budgetRepos->shouldReceive('getBudgets')->andReturn($set); + $budgetRepos->shouldReceive('getCurrentRepetition')->andReturn($rep); + $tagRepos->shouldReceive('coveredByBalancingActs')->andReturn(0); + + // test! + $object = $this->object->getBalanceReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); + $this->assertCount(8, $object->getBalanceLines()); + $this->assertCount(5, $object->getBalanceHeader()->getAccounts()); + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getBillReport + */ + public function testGetBillReport() + { + // factory! + $set = new Collection; + $journals = new Collection; + $left = FactoryMuffin::create('FireflyIII\Models\Account'); + $right = FactoryMuffin::create('FireflyIII\Models\Account'); + for ($i = 0; $i < 5; $i++) { + $set->push(FactoryMuffin::create('FireflyIII\Models\Bill')); + } + + for ($i = 0; $i < 5; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + Transaction::create( + [ + 'account_id' => $left->id, + 'transaction_journal_id' => $journal->id, + 'amount' => rand(-100, 100) + ] + ); + Transaction::create( + [ + 'account_id' => $right->id, + 'transaction_journal_id' => $journal->id, + 'amount' => rand(-100, 100) + ] + ); + $journals->push($journal); + } + + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface'); + + // fake! + $repository->shouldReceive('getBills')->andReturn($set); + $repository->shouldReceive('getJournalsInRange')->withAnyArgs()->andReturn(new Collection, $journals); + + // test! + $object = $this->object->getBillReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); + $this->assertCount(5, $object->getBills()); + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getBudgetReport + */ + public function testGetBudgetReport() + { + // factory! + $user = FactoryMuffin::create('FireflyIII\User'); + $set = new Collection; + $rep1 = new Collection; + $rep2 = new Collection; + for ($i = 0; $i < 5; $i++) { + $set->push(FactoryMuffin::create('FireflyIII\Models\Budget')); + } + for ($i = 0; $i < 5; $i++) { + $rep1->push(FactoryMuffin::create('FireflyIII\Models\LimitRepetition')); + } + + $this->be($user); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + + // fake! + $repository->shouldReceive('getBudgets')->andReturn($set); + $repository->shouldReceive('getBudgetLimitRepetitions')->andReturn($rep1, $rep2); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(rand(0, 100)); + $repository->shouldReceive('getWithoutBudgetSum')->andReturn(rand(0, 100)); + + // test! + $object = $this->object->getBudgetReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); + + $this->assertCount(10, $object->getBudgetLines()); + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getCategoryReport + */ + public function testGetCategoryReport() + { + // factory! + $user = FactoryMuffin::create('FireflyIII\User'); + $set = new Collection; + for ($i = 0; $i < 5; $i++) { + $set->push(FactoryMuffin::create('FireflyIII\Models\Category')); + } + + $this->be($user); + + // mock! + $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); + + // fake! + $repository->shouldReceive('getCategories')->andReturn($set); + $repository->shouldReceive('spentInPeriodCorrected')->andReturn(rand(0, 100)); + + // test! + $object = $this->object->getCategoryReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false); + $this->assertCount(5, $object->getCategories()); + } + + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getExpenseReport + * @covers FireflyIII\Helpers\Report\ReportQuery::expenseInPeriodCorrected + */ + public function testGetExpenseReport() + { + // factory! + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + + // create five journals in this month for the report: + $date = Carbon::now()->startOfMonth()->addDay(); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $left = FactoryMuffin::create('FireflyIII\Models\Account'); + $right = FactoryMuffin::create('FireflyIII\Models\Account'); + $left->account_type_id = $asset->id; + $right->account_type_id = $asset->id; + $right->save(); + $left->save(); + + // save meta for account: + AccountMeta::create([ + 'account_id' => $left->id, + 'name' => 'accountRole', + 'data' => 'defaultAsset' + ]); + AccountMeta::create([ + 'account_id' => $right->id, + 'name' => 'accountRole', + 'data' => 'defaultAsset' + ]); + + + for ($i = 0; $i < 5; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->date = $date; + $journal->transaction_type_id = $type->id; + $journal->user_id = $user->id; + $journal->save(); + Transaction::create( + [ + 'account_id' => $left->id, + 'transaction_journal_id' => $journal->id, + 'amount' => 100 + ] + ); + Transaction::create( + [ + 'account_id' => $right->id, + 'transaction_journal_id' => $journal->id, + 'amount' => -100 + ] + ); + } + + // test! + $object = $this->object->getExpenseReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true); + $this->assertCount(1, $object->getExpenses()); + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::getIncomeReport + * @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected + */ + public function testGetIncomeReport() + { + // factory! + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + + // create five journals in this month for the report: + $date = Carbon::now()->startOfMonth()->addDay(); + $left = FactoryMuffin::create('FireflyIII\Models\Account'); + $right = FactoryMuffin::create('FireflyIII\Models\Account'); + $asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); + $left->account_type_id = $asset->id; + $right->account_type_id = $asset->id; + + // save meta for account: + AccountMeta::create([ + 'account_id' => $left->id, + 'name' => 'accountRole', + 'data' => 'defaultAsset' + ]); + AccountMeta::create([ + 'account_id' => $right->id, + 'name' => 'accountRole', + 'data' => 'defaultAsset' + ]); + + $right->save(); + $left->save(); + for ($i = 0; $i < 5; $i++) { + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $journal->date = $date; + $journal->transaction_type_id = $type->id; + $journal->user_id = $user->id; + $journal->save(); + Transaction::create( + [ + 'account_id' => $left->id, + 'transaction_journal_id' => $journal->id, + 'amount' => 100 + ] + ); + Transaction::create( + [ + 'account_id' => $right->id, + 'transaction_journal_id' => $journal->id, + 'amount' => -100 + ] + ); + } + + // test! + $object = $this->object->getIncomeReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true); + $this->assertCount(1, $object->getIncomes()); + + } + + /** + * @covers FireflyIII\Helpers\Report\ReportHelper::listOfMonths + */ public function testListOfMonths() { // start of year up until now diff --git a/tests/repositories/BudgetRepositoryTest.php b/tests/repositories/BudgetRepositoryTest.php index eddd87c644..d16ae370df 100644 --- a/tests/repositories/BudgetRepositoryTest.php +++ b/tests/repositories/BudgetRepositoryTest.php @@ -70,13 +70,13 @@ class BudgetRepositoryTest extends TestCase } /** - * @covers FireflyIII\Repositories\Budget\BudgetRepository::expensesOnDay + * @covers FireflyIII\Repositories\Budget\BudgetRepository::expensesOnDayCorrected */ - public function testExpensesOnDay() + public function testExpensesOnDayCorrected() { $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); - $result = $this->object->expensesOnDay($budget, new Carbon); + $result = $this->object->expensesOnDayCorrected($budget, new Carbon); $this->assertEquals(0, $result); } @@ -289,13 +289,13 @@ class BudgetRepositoryTest extends TestCase } /** - * @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriod + * @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected */ - public function testSpentInPeriod() + public function testSpentInPeriodCorrected() { $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); - $amount = $this->object->spentInPeriod($budget, new Carbon, new Carbon); + $amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon); $this->assertEquals(0, $amount); } @@ -316,16 +316,6 @@ class BudgetRepositoryTest extends TestCase $this->assertEquals($result->name, $data['name']); } - /** - * @covers FireflyIII\Repositories\Budget\BudgetRepository::sumBudgetExpensesInPeriod - */ - public function testSumBudgetExpensesInPeriod() - { - $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); - $result = $this->object->sumBudgetExpensesInPeriod($budget, new Carbon, new Carbon); - $this->assertEquals(0, $result); - } - /** * @covers FireflyIII\Repositories\Budget\BudgetRepository::update */ diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.php index 10121ec76d..0e5b0d92a1 100644 --- a/tests/repositories/CategoryRepositoryTest.php +++ b/tests/repositories/CategoryRepositoryTest.php @@ -79,9 +79,9 @@ class CategoryRepositoryTest extends TestCase } /** - * @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpenses + * @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpensesCorrected */ - public function testGetCategoriesAndExpenses() + public function testGetCategoriesAndExpensesCorrected() { $user = FactoryMuffin::create('FireflyIII\User'); $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); @@ -100,9 +100,11 @@ class CategoryRepositoryTest extends TestCase } $this->be($user); - $set = $this->object->getCategoriesAndExpenses(new Carbon('2015-02-01'), new Carbon('2015-02-28')); + $set = $this->object->getCategoriesAndExpensesCorrected(new Carbon('2015-02-01'), new Carbon('2015-02-28')); $this->assertCount(5, $set); - $this->assertEquals(0, $set->first()->sum); + reset($set); + + $this->assertEquals(0, current($set)['sum']); } /** @@ -189,12 +191,12 @@ class CategoryRepositoryTest extends TestCase } /** - * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriod + * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected */ - public function testSpentInPeriodSum() + public function testSpentInPeriodSumCorrected() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); - $sum = $this->object->spentInPeriod($category, new Carbon, new Carbon); + $sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon); $this->assertEquals(0, $sum); @@ -202,12 +204,12 @@ class CategoryRepositoryTest extends TestCase } /** - * @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySum + * @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySumCorrected */ - public function testSpentOnDaySum() + public function testSpentOnDaySumCorrected() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); - $sum = $this->object->spentOnDaySum($category, new Carbon); + $sum = $this->object->spentOnDaySumCorrected($category, new Carbon); $this->assertEquals(0, $sum); }