. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Report; use Amount; use Carbon\Carbon; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface; use FireflyIII\Repositories\Category\OperationsRepositoryInterface; use Illuminate\Support\Collection; use Log; use Preferences; use Tests\Support\TestDataTrait; use Tests\TestCase; /** * Class CategoryControllerTest * * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CategoryControllerTest extends TestCase { use TestDataTrait; /** * */ public function setUp(): void { self::markTestIncomplete('Incomplete for refactor.'); return; parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Report\CategoryController */ public function testExpenses(): void { $this->mockDefaultSession(); $first = [1 => ['entries' => ['1', '1']]]; $second = ['entries' => ['1', '1']]; $repository = $this->mock(CategoryRepositoryInterface::class); $opsRepos = $this->mock(OperationsRepositoryInterface::class); $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class); $date = new Carbon; $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses()); $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses()); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x'); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $repository->shouldReceive('getCategories')->andReturn(new Collection); $repository->shouldReceive('periodExpenses')->andReturn($first); $repository->shouldReceive('periodExpensesNoCategory')->andReturn($second); $this->be($this->user()); $response = $this->get(route('report-data.category.expenses', ['1', '20120101', '20120131'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Report\CategoryController */ public function testIncome(): void { $this->mockDefaultSession(); $first = [ 1 => ['entries' => ['1', '1']], 2 => ['entries' => ['0']], ]; $second = ['entries' => ['1', '1']]; $repository = $this->mock(CategoryRepositoryInterface::class); $opsRepository = $this->mock(OperationsRepositoryInterface::class); $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class); $date = new Carbon; $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome()); $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome()); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x'); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $repository->shouldReceive('getCategories')->andReturn(new Collection); $repository->shouldReceive('periodIncome')->andReturn($first); $repository->shouldReceive('periodIncomeNoCategory')->andReturn($second); $this->be($this->user()); $response = $this->get(route('report-data.category.income', ['1', '20120101', '20120131'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Report\CategoryController */ public function testOperations(): void { $this->mockDefaultSession(); $repository = $this->mock(CategoryRepositoryInterface::class); $opsRepository = $this->mock(OperationsRepositoryInterface::class); $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class); $category = $this->getRandomCategory(); $fiscalHelper = $this->mock(FiscalHelperInterface::class); $date = new Carbon; $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome()); $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome()); $opsRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses()); $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses()); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x'); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $repository->shouldReceive('getCategories')->andReturn(new Collection([$category])); $repository->shouldReceive('spentInPeriod')->andReturn([]); $repository->shouldReceive('earnedInPeriod')->andReturn([]); $this->be($this->user()); $response = $this->get(route('report-data.category.operations', ['1', '20120101', '20120131'])); $response->assertStatus(200); $response->assertDontSee('An error prevented Firefly III from rendering: %s. Apologies.'); } }