. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Category; use Tests\TestCase; use Log; use Carbon\Carbon; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Filter\InternalTransferFilter; use FireflyIII\Models\Category; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Navigation; /** * * Class ShowControllerTest */ class ShowControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::debug(sprintf('Now in %s.', \get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Category\ShowController * * @dataProvider dateRangeProvider * * @param string $range */ public function testShow(string $range): void { Log::debug('Test show()'); $transaction = factory(Transaction::class)->make(); $categoryRepos = $this->mock(CategoryRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first()); // mock stuff $categoryRepos->shouldReceive('spentInPeriod')->andReturn('0'); $categoryRepos->shouldReceive('earnedInPeriod')->andReturn('0'); $accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection); $collector = $this->mock(JournalCollectorInterface::class); $collector->shouldReceive('setPage')->andReturnSelf()->once(); $collector->shouldReceive('setLimit')->andReturnSelf()->once(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->atLeast(2); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast(2); $collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf()->atLeast(2); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once(); $collector->shouldReceive('withOpposingAccount')->andReturnSelf()->atLeast(2); $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2); $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10))->once(); $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1); $collector->shouldReceive('getJournals')->andReturn(new Collection)->atLeast(1); Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon); Navigation::shouldReceive('updateEndDate')->andReturn(new Carbon); Navigation::shouldReceive('startOfPeriod')->andReturn(new Carbon); Navigation::shouldReceive('endOfPeriod')->andReturn(new Carbon); Navigation::shouldReceive('periodShow')->andReturn('Some date'); Navigation::shouldReceive('blockPeriods')->andReturn([['period' => '1M', 'start' => new Carbon, 'end' => new Carbon]])->once(); $this->be($this->user()); $this->changeDateRange($this->user(), $range); $response = $this->get(route('categories.show', [1])); $response->assertStatus(200); $response->assertSee('