. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Category; use Carbon\Carbon; use Exception; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Models\Preference; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Log; use Mockery; use Navigation; use Preferences; use Tests\TestCase; /** * * Class ShowControllerTest * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class ShowControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Category\ShowController * * @dataProvider dateRangeProvider * * @param string $range * @throws Exception */ public function testShow(string $range): void { $withdrawal = $this->getRandomWithdrawalAsArray(); $categoryRepos = $this->mock(CategoryRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $collector = $this->mock(GroupCollectorInterface::class); $this->mockDefaultSession(); $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); $pref = new Preference; $pref->data = 50; Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); // mock stuff $categoryRepos->shouldReceive('spentInPeriodCollection')->andReturn(new Collection); $categoryRepos->shouldReceive('earnedInPeriodCollection')->andReturn(new Collection); $categoryRepos->shouldReceive('firstUseDate')->andReturnNull(); $collector->shouldReceive('setPage')->andReturnSelf()->once(); $collector->shouldReceive('setLimit')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->times(2); $collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once(); $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once(); $collector->shouldReceive('withAccountInformation')->andReturnSelf()->once(); $collector->shouldReceive('setCategory')->andReturnSelf()->atLeast()->times(2); $collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once(); $collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once(); $collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once(); 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('