. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Account; use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Support\Collection; use Log; use Mockery; use Preferences; use Tests\TestCase; /** * * Class EditControllerTest * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class EditControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Account\EditController * @covers \FireflyIII\Http\Requests\AccountFormRequest */ public function testEdit(): void { $repository = $this->mock(CurrencyRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $asset = $this->getRandomAsset(); $euro = $this->getEuro(); // mock default session stuff $this->mockDefaultSession(); // mock hasRole for user repository: $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once(); $repository->shouldReceive('get')->andReturn(new Collection)->atLeast()->once(); $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->once(); $accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once(); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull()->atLeast()->once(); $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull()->atLeast()->once(); //$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('123')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1')->atLeast()->once(); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly')->atLeast()->once(); // get all types: $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once(); $this->be($this->user()); $response = $this->get(route('accounts.edit', [$asset->id])); $response->assertStatus(200); // has bread crumb $response->assertSee('