Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code for #595
James Colec62e3dcb78c4
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.phpindex d76c829e2a..b625c634b8 100644--- a/app/Http/Controllers/CategoryController.php+++ b/app/Http/Controllers/CategoryController.php@@ -234,91 +234,147 @@ class CategoryController extends Controller* @param Request $request* @param JournalCollectorInterface $collector* @param Category $category+ * @param string $moment** @return View*/- public function show(Request $request, JournalCollectorInterface $collector, Category $category)+ public function show(Request $request, JournalCollectorInterface $collector, Category $category, string $moment = ''){- $range = Preferences::get('viewRange', '1M')->data;- $start = session('start', Navigation::startOfPeriod(new Carbon, $range));- $end = session('end', Navigation::endOfPeriod(new Carbon, $range));- $hideCategory = true; // used in list.- $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));- $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);+ // default values:+ /** @var CategoryRepositoryInterface $repository */+ $repository = app(CategoryRepositoryInterface::class);$subTitle = $category->name;$subTitleIcon = 'fa-bar-chart';- $entries = $this->getGroupedEntries($category);- $method = 'default';+ $page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));+ $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);+ $count = 0;+ $loop = 0;+ $range = Preferences::get('viewRange', '1M')->data;+ $start = null;+ $end = null;+ $periods = new Collection;- // get journals- $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation();- $journals = $collector->getPaginatedJournals();- $journals->setPath('categories/show/' . $category->id);+ // prep for "all" view.+ if ($moment === 'all') {+ $subTitle = trans('firefly.all_journals_for_category', ['name' => $category->name]);+ $start = $repository->firstUseDate($category);+ $end = new Carbon;+ }- return view('categories.show', compact('category', 'method', 'journals', 'entries', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));- }+ // prep for "specific date" view.+ if (strlen($moment) > 0 && $moment !== 'all') {+ $start = new Carbon($moment);+ $end = Navigation::endOfPeriod($start, $range);+ $subTitle = trans(+ 'firefly.journals_in_period_for_category',+ ['name' => $category->name,+ 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]+ );+ $periods = $this->periodEntries($category);+ }- /**- * @param Request $request- * @param CategoryRepositoryInterface $repository- * @param Category $category- *- * @return View- */- public function showAll(Request $request, CategoryRepositoryInterface $repository, Category $category)- {- $range = Preferences::get('viewRange', '1M')->data;- $start = $repository->firstUseDate($category);- if ($start->year == 1900) {- $start = new Carbon;+ // prep for current period+ if (strlen($moment) === 0) {+ $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));+ $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));+ $periods = $this->periodEntries($category);+ $subTitle = trans(+ 'firefly.journals_in_period_for_category',+ ['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]+ );+ }+ // grab journals, but be prepared to jump a period back to get the right ones:+ Log::info('Now at transaction loop start.');+ while ($count === 0 && $loop < 3) {+ $loop++;+ Log::info('Count is zero, search for journals.');+ /** @var JournalCollectorInterface $collector */+ $collector = app(JournalCollectorInterface::class);+ $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()+ ->setCategory($category)->withBudgetInformation()->withCategoryInformation();+ $journals = $collector->getPaginatedJournals();+ $journals->setPath('categories/show/' . $category->id);+ $count = $journals->getCollection()->count();+ if ($count === 0) {+ $start->subDay();+ $start = Navigation::startOfPeriod($start, $range);+ $end = Navigation::endOfPeriod($start, $range);+ Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d')));+ }}- $end = Navigation::endOfPeriod(new Carbon, $range);- $subTitle = $category->name;- $subTitleIcon = 'fa-bar-chart';- $hideCategory = true; // used in list.- $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));- $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);- $method = 'all';- /** @var JournalCollectorInterface $collector */- $collector = app(JournalCollectorInterface::class);- $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setCategory($category)->withBudgetInformation();- $journals = $collector->getPaginatedJournals();- $journals->setPath('categories/show/' . $category->id . '/all');+ // fix title:+ if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {+ $subTitle = trans(+ 'firefly.journals_in_period_for_category',+ ['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]+ );+ }- return view('categories.show', compact('category', 'method', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));+ return view('categories.show', compact('category', 'moment', 'journals', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));}- /**- * @param Request $request- * @param Category $category- * @param string $date- *- * @return View- */- public function showByDate(Request $request, Category $category, string $date)- {- $carbon = new Carbon($date);- $range = Preferences::get('viewRange', '1M')->data;- $start = Navigation::startOfPeriod($carbon, $range);- $end = Navigation::endOfPeriod($carbon, $range);- $subTitle = $category->name;- $subTitleIcon = 'fa-bar-chart';- $hideCategory = true; // used in list.- $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));- $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);- $entries = $this->getGroupedEntries($category);- $method = 'date';-- /** @var JournalCollectorInterface $collector */- $collector = app(JournalCollectorInterface::class);- $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation();- $journals = $collector->getPaginatedJournals();- $journals->setPath('categories/show/' . $category->id . '/' . $date);-- return view('categories.show', compact('category', 'method', 'entries', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));- }+ // /**+ // * @param Request $request+ // * @param CategoryRepositoryInterface $repository+ // * @param Category $category+ // *+ // * @return View+ // */+ // public function showAll(Request $request, CategoryRepositoryInterface $repository, Category $category)+ // {+ // $range = Preferences::get('viewRange', '1M')->data;+ // $start = $repository->firstUseDate($category);+ // if ($start->year == 1900) {+ // $start = new Carbon;+ // }+ // $end = Navigation::endOfPeriod(new Carbon, $range);+ // $subTitle = $category->name;+ // $subTitleIcon = 'fa-bar-chart';+ // $hideCategory = true; // used in list.+ // $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));+ // $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);+ // $method = 'all';+ //+ // /** @var JournalCollectorInterface $collector */+ // $collector = app(JournalCollectorInterface::class);+ // $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setCategory($category)->withBudgetInformation();+ // $journals = $collector->getPaginatedJournals();+ // $journals->setPath('categories/show/' . $category->id . '/all');+ //+ // return view('categories.show', compact('category', 'method', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));+ // }+ //+ // /**+ // * @param Request $request+ // * @param Category $category+ // * @param string $date+ // *+ // * @return View+ // */+ // public function showByDate(Request $request, Category $category, string $date)+ // {+ // $carbon = new Carbon($date);+ // $range = Preferences::get('viewRange', '1M')->data;+ // $start = Navigation::startOfPeriod($carbon, $range);+ // $end = Navigation::endOfPeriod($carbon, $range);+ // $subTitle = $category->name;+ // $subTitleIcon = 'fa-bar-chart';+ // $hideCategory = true; // used in list.+ // $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));+ // $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);+ // $entries = $this->getGroupedEntries($category);+ // $method = 'date';+ //+ // /** @var JournalCollectorInterface $collector */+ // $collector = app(JournalCollectorInterface::class);+ // $collector->setLimit($pageSize)->setPage($page)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category)->withBudgetInformation();+ // $journals = $collector->getPaginatedJournals();+ // $journals->setPath('categories/show/' . $category->id . '/' . $date);+ //+ // return view('categories.show', compact('category', 'method', 'entries', 'journals', 'hideCategory', 'subTitle', 'subTitleIcon', 'start', 'end'));+ // }/*** @param CategoryFormRequest $request@@ -368,53 +424,6 @@ class CategoryController extends Controllerreturn redirect($this->getPreviousUri('categories.edit.uri'));}- /**- * @param Category $category- *- * @return Collection- */- private function getGroupedEntries(Category $category): Collection- {- /** @var CategoryRepositoryInterface $repository */- $repository = app(CategoryRepositoryInterface::class);- /** @var AccountRepositoryInterface $accountRepository */- $accountRepository = app(AccountRepositoryInterface::class);- $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);- $first = $repository->firstUseDate($category);- if ($first->year == 1900) {- $first = new Carbon;- }- $range = Preferences::get('viewRange', '1M')->data;- $first = Navigation::startOfPeriod($first, $range);- $end = Navigation::endOfX(new Carbon, $range);- $entries = new Collection;-- // properties for entries with their amounts.- $cache = new CacheProperties();- $cache->addProperty($first);- $cache->addProperty($end);- $cache->addProperty('categories.entries');- $cache->addProperty($category->id);-- if ($cache->has()) {- return $cache->get(); // @codeCoverageIgnore- }- while ($end >= $first) {- $end = Navigation::startOfPeriod($end, $range);- $currentEnd = Navigation::endOfPeriod($end, $range);- $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);- $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);- $dateStr = $end->format('Y-m-d');- $dateName = Navigation::periodShow($end, $range);- $entries->push([$dateStr, $dateName, $spent, $earned, clone $end]);- $end = Navigation::subtractPeriod($end, $range, 1);- }- $cache->store($entries);-- return $entries;- }--/*** @return Collection*/@@ -490,4 +499,58 @@ class CategoryController extends Controllerreturn $entries;}+ /**+ * @param Category $category+ *+ * @return Collection+ */+ private function periodEntries(Category $category): Collection+ {+ /** @var CategoryRepositoryInterface $repository */+ $repository = app(CategoryRepositoryInterface::class);+ /** @var AccountRepositoryInterface $accountRepository */+ $accountRepository = app(AccountRepositoryInterface::class);+ $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);+ $first = $repository->firstUseDate($category);+ if ($first->year == 1900) {+ $first = new Carbon;+ }+ $range = Preferences::get('viewRange', '1M')->data;+ $first = Navigation::startOfPeriod($first, $range);+ $end = Navigation::endOfX(new Carbon, $range);+ $entries = new Collection;++ // properties for entries with their amounts.+ $cache = new CacheProperties();+ $cache->addProperty($first);+ $cache->addProperty($end);+ $cache->addProperty('categories.entries');+ $cache->addProperty($category->id);++ if ($cache->has()) {+ return $cache->get(); // @codeCoverageIgnore+ }+ while ($end >= $first) {+ $end = Navigation::startOfPeriod($end, $range);+ $currentEnd = Navigation::endOfPeriod($end, $range);+ $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);+ $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $end, $currentEnd);+ $dateStr = $end->format('Y-m-d');+ $dateName = Navigation::periodShow($end, $range);+ $entries->push(+ [+ 'string' => $dateStr,+ 'name' => $dateName,+ 'spent' => $spent,+ 'earned' => $earned,+ 'date' => clone $end,+ ]+ );+ $end = Navigation::subtractPeriod($end, $range, 1);+ }+ $cache->store($entries);++ return $entries;+ }+}diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 106c8a77d7..38cea0b744 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -124,6 +124,7 @@ return ['journals_in_period_for_account' => 'All transactions for account :name between :start and :end','transferred' => 'Transferred','all_withdrawal' => 'All expenses',+ 'all_transactions' => 'All transactions','title_withdrawal_between' => 'All expenses between :start and :end','all_deposit' => 'All revenue','title_deposit_between' => 'All revenue between :start and :end',@@ -131,6 +132,8 @@ return ['title_transfers_between' => 'All transfers between :start and :end','all_transfer' => 'All transfers','title_transfer_between' => 'All transfers between :start and :end',+ 'all_journals_for_category' => 'All transactions for category :name',+ 'journals_in_period_for_category' => 'All transactions for category :name between :start and :end',// repeat frequencies:diff --git a/resources/views/budgets/show.twig b/resources/views/budgets/show.twigindex e1750adff8..93f7cabe37 100644--- a/resources/views/budgets/show.twig+++ b/resources/views/budgets/show.twig@@ -43,7 +43,7 @@<h3 class="box-title">{{ 'transactions'|_ }}</h3></div><div class="box-body">- {% include 'list.journals-tasker' %}+ {% include 'list.journals-tasker' with {hideBudgets:true, hideBills:true} %}</div></div></div>@@ -101,8 +101,9 @@{% block scripts %}<script type="text/javascript">var budgetID = {{ budget.id }};+ var budgetLimitID = 0;{% if budgetLimit.id %}- var budgetLimitID = {{ budgetLimit.id }};+ budgetLimitID = {{ budgetLimit.id }};var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, budgetLimit.id] ) }}';{% else %}var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}';diff --git a/resources/views/categories/show.twig b/resources/views/categories/show.twigindex c798a6b587..24d490fb72 100644--- a/resources/views/categories/show.twig+++ b/resources/views/categories/show.twig@@ -1,12 +1,12 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category, start, end) }}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, category, moment, start, end) }}{% endblock %}{% block content %}<div class="row">- {% if method == 'default' %}+ {% if moment != 'all' and moment != '' %}{# both charts #}<div class="col-lg-6 col-md-6 col-sm-12"><div class="box">@@ -14,7 +14,7 @@<h3 class="box-title">{{ 'overview'|_ }} ({{ 'per_period'|_|lower }})</h3></div><div class="box-body">- <canvas id="period" style="width:100%" height="350"></canvas>+ <canvas id="period-specific-period" style="width:100%" height="350"></canvas></div></div></div>@@ -29,20 +29,20 @@</div></div>{% endif %}- {% if method == 'date' %}+ {% if moment == '' %}{# single chart #}<div class="col-lg-12 col-md-12 col-sm-12"><div class="box"><div class="box-header with-border">- <h3 class="box-title">{{ 'overview'|_ }} ({{ 'current_period'|_|lower }})</h3>+ <h3 class="box-title">{{ subTitle }}</h3></div><div class="box-body">- <canvas id="period-specific-period" style="width:100%;height:350px;" height="350"></canvas>+ <canvas id="period" style="width:100%;height:350px;" height="350"></canvas></div></div></div>{% endif %}- {% if method == 'all' %}+ {% if moment == 'all' %}{# all chart #}<div class="col-lg-12 col-md-12 col-sm-12"><div class="box">@@ -56,16 +56,16 @@</div>{% endif %}</div>- {% if entries %}+ {% if periods.count > 0 %}<div class="row"><div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">- <p class="small text-center"><a href="{{ route('categories.show.all',[category.id]) }}">{{ 'showEverything'|_ }}</a></p>+ <p class="small text-center"><a href="{{ route('categories.show',[category.id,'all']) }}">{{ 'showEverything'|_ }}</a></p></div></div>{% endif %}<div class="row">- <div class="{% if entries %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">+ <div class="{% if periods.count > 0 %}col-lg-10 col-md-8 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}"><div class="box"><div class="box-header with-border">@@ -76,7 +76,7 @@{% if entries %}<p><i class="fa fa-calendar" aria-hidden="true"></i>- <a href="{{ route('categories.show.all', [category.id]) }}">+ <a href="{{ route('categories.show', [category.id,'all']) }}">{{ 'show_all_no_filter'|_ }}</a></p>@@ -91,34 +91,27 @@</div></div></div>- {% if entries %}+ {% if periods.count > 0 %}<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">- {% for entry in entries %}- {% if entry[2] != 0 or entry[3] != 0 %}- <div class="box {% if entry[4] == start %}box-solid box-primary{% endif %}">- <div class="box-header with-border">- <h3 class="box-title"><a href="{{ route('categories.show.date',[category.id,entry[0]]) }}">{{ entry[1] }}</a>- </h3>- </div>- <div class="box-body no-padding">- <table class="table table-hover">- {% if entry[2] != 0 %}- <tr>- <td style="width:33%;">{{ 'spent'|_ }}</td>- <td style="text-align: right;">{{ entry[2]|formatAmount }}</td>- </tr>- {% endif %}- {% if entry[3] != 0 %}- <tr>- <td style="width:33%;">{{ 'earned'|_ }}</td>- <td style="text-align: right;">{{ entry[3]|formatAmount }}</td>- </tr>- {% endif %}- </table>- </div>+ {% for period in periods %}+ <div class="box {% if period.date == start %}box-solid box-primary{% endif %}">+ <div class="box-header with-border">+ <h3 class="box-title"><a href="{{ route('categories.show',[category.id,period.string]) }}">{{ period.name }}</a>+ </h3></div>- {% endif %}-+ <div class="box-body no-padding">+ <table class="table table-hover">+ <tr>+ <td style="width:33%;">{{ 'spent'|_ }}</td>+ <td style="text-align: right;">{{ period.spent|formatAmount }}</td>+ </tr>+ <tr>+ <td style="width:33%;">{{ 'earned'|_ }}</td>+ <td style="text-align: right;">{{ period.earned|formatAmount }}</td>+ </tr>+ </table>+ </div>+ </div>{% endfor %}</div>{% endif %}diff --git a/routes/web.php b/routes/web.phpindex f8b9c47ab2..90d770af33 100755--- a/routes/web.php+++ b/routes/web.php@@ -162,9 +162,7 @@ Route::group(Route::get('edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'edit']);Route::get('delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'delete']);- Route::get('show/{category}', ['uses' => 'CategoryController@show', 'as' => 'show']);- Route::get('show/{category}/all', ['uses' => 'CategoryController@showAll', 'as' => 'show.all']);- Route::get('show/{category}/{date}', ['uses' => 'CategoryController@showByDate', 'as' => 'show.date']);+ Route::get('show/{category}/{moment?}', ['uses' => 'CategoryController@show', 'as' => 'show']);Route::get('list/no-category/{moment?}', ['uses' => 'CategoryController@noCategory', 'as' => 'no-category']);Route::post('store', ['uses' => 'CategoryController@store', 'as' => 'store']);diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.phpindex 902c148665..3254ade196 100644--- a/tests/Feature/Controllers/AccountControllerTest.php+++ b/tests/Feature/Controllers/AccountControllerTest.php@@ -15,6 +15,7 @@ use Carbon\Carbon;use FireflyIII\Helpers\Collector\JournalCollectorInterface;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;+use FireflyIII\Models\Preference;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Account\AccountRepositoryInterface;@@ -23,6 +24,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use Illuminate\Pagination\LengthAwarePaginator;use Illuminate\Support\Collection;+use Preferences;use Steam;use Tests\TestCase;@@ -320,8 +322,8 @@ class AccountControllerTest extends TestCasepublic function testStore(){// mock stuff- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $repository = $this->mock(AccountRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('find')->andReturn(new Account)->once();$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.phpindex 53fdbe9db9..e2887d1272 100644--- a/tests/Feature/Controllers/CategoryControllerTest.php+++ b/tests/Feature/Controllers/CategoryControllerTest.php@@ -14,6 +14,7 @@ namespace Tests\Feature\Controllers;use Carbon\Carbon;use FireflyIII\Helpers\Collector\JournalCollectorInterface;use FireflyIII\Models\Category;+use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Category\CategoryRepositoryInterface;@@ -229,6 +230,7 @@ class CategoryControllerTest extends TestCase*/public function testShow(string $range){+ $transaction = factory(Transaction::class)->make();$journalRepos = $this->mock(JournalRepositoryInterface::class);$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);@@ -247,8 +249,11 @@ class CategoryControllerTest extends TestCase$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();$collector->shouldReceive('setRange')->andReturnSelf()->once();$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();+$collector->shouldReceive('setCategory')->andReturnSelf()->once();- $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();$this->be($this->user());$this->changeDateRange($this->user(), $range);@@ -266,22 +271,28 @@ class CategoryControllerTest extends TestCasepublic function testShowAll(string $range){// mock stuff+ $transaction = factory(Transaction::class)->make();$journalRepos = $this->mock(JournalRepositoryInterface::class);$repository = $this->mock(CategoryRepositoryInterface::class);$collector = $this->mock(JournalCollectorInterface::class);+$collector->shouldReceive('setPage')->andReturnSelf()->once();$collector->shouldReceive('setLimit')->andReturnSelf()->once();$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();+ $collector->shouldReceive('setRange')->andReturnSelf()->once();$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();$collector->shouldReceive('setCategory')->andReturnSelf()->once();- $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();+$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);$this->be($this->user());$this->changeDateRange($this->user(), $range);- $response = $this->get(route('categories.show.all', [1]));+ $response = $this->get(route('categories.show', [1, 'all']));$response->assertStatus(200);$response->assertSee('<ol class="breadcrumb">');}@@ -296,6 +307,7 @@ class CategoryControllerTest extends TestCasepublic function testShowByDate(string $range){// mock stuff+ $transaction = factory(Transaction::class)->make();$repository = $this->mock(CategoryRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$collector = $this->mock(JournalCollectorInterface::class);@@ -309,8 +321,10 @@ class CategoryControllerTest extends TestCase$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();$collector->shouldReceive('setRange')->andReturnSelf()->once();$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();$collector->shouldReceive('setCategory')->andReturnSelf()->once();- $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once();$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);$repository->shouldReceive('spentInPeriod')->andReturn('-1');@@ -319,7 +333,7 @@ class CategoryControllerTest extends TestCase$this->be($this->user());$this->changeDateRange($this->user(), $range);- $response = $this->get(route('categories.show.date', [1, '2015-01-01']));+ $response = $this->get(route('categories.show', [1, '2015-01-01']));$response->assertStatus(200);$response->assertSee('<ol class="breadcrumb">');}