. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Budget; use Amount; use Carbon\Carbon; use Exception; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Models\Budget; use FireflyIII\Models\Preference; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Support\Collection; use Log; use Mockery; use Preferences; use Tests\TestCase; /** * * Class IndexControllerTest * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class IndexControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Budget\IndexController * @dataProvider dateRangeProvider * * @param string $range */ public function testIndex(string $range): void { // mock stuff $budget = $this->getRandomBudget(); $budgetLimit = $this->getRandomBudgetLimit(); $budgetLimit->start_date = Carbon::now()->startOfMonth(); $budgetLimit->end_date = Carbon::now()->endOfMonth(); $budgetInfo = [ $budget->id => [ 'spent' => '0', 'budgeted' => '0', 'currentRep' => false, ], ]; $accountRepos = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(BudgetRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once(); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection); $repository->shouldReceive('cleanupBudgets'); $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget])); $repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection); $repository->shouldReceive('getAvailableBudget')->andReturn('100.123'); $repository->shouldReceive('spentInPeriod')->andReturn('-1'); $repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo); $repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit])); $this->mockDefaultSession(); $this->mockIntroPreference('shown_demo_budgets_index'); // list size $pref = new Preference; $pref->data = 50; Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); Amount::shouldReceive('formatAnything')->andReturn('123'); $this->be($this->user()); $this->changeDateRange($this->user(), $range); $response = $this->get(route('budgets.index')); $response->assertStatus(200); // has bread crumb $response->assertSee('