Mock more repositories in tests.

This commit is contained in:
James Cole
2018-09-03 18:52:46 +02:00
parent 480b636c7e
commit 46ba0a5a5a
137 changed files with 496 additions and 222 deletions

View File

@@ -33,9 +33,10 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
use Mockery;
/**
*
* Class CreateControllerTest
@@ -48,7 +49,7 @@ class CreateControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
@@ -66,7 +67,7 @@ class CreateControllerTest extends TestCase
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
// get all types:
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
@@ -90,8 +91,8 @@ class CreateControllerTest extends TestCase
public function testStore(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -119,8 +120,8 @@ class CreateControllerTest extends TestCase
public function testStoreAnother(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);

View File

@@ -27,7 +27,6 @@ namespace Tests\Feature\Controllers\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
@@ -47,7 +46,7 @@ class DeleteControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
@@ -57,14 +56,14 @@ class DeleteControllerTest extends TestCase
public function testDelete(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$this->be($this->user());
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
@@ -81,8 +80,8 @@ class DeleteControllerTest extends TestCase
public function testDestroy(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
$repository->shouldReceive('destroy')->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);

View File

@@ -49,7 +49,7 @@ class EditControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
@@ -57,10 +57,10 @@ class EditControllerTest extends TestCase
*/
public function testEdit(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
@@ -103,10 +103,10 @@ class EditControllerTest extends TestCase
*/
public function testEditLiability(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@@ -149,10 +149,10 @@ class EditControllerTest extends TestCase
public function testEditNull(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();

View File

@@ -50,7 +50,7 @@ class IndexControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
@@ -71,7 +71,7 @@ class IndexControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');

View File

@@ -47,7 +47,7 @@ class ReconcileControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
@@ -106,9 +106,12 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcile(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@@ -129,6 +132,10 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileInitialBalance(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transaction = Transaction::leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->where('accounts.user_id', $this->user()->id)->where('accounts.account_type_id', 6)->first(['account_id']);
$this->be($this->user());
@@ -143,9 +150,12 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileNoDates(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@@ -167,9 +177,12 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileNoEndDate(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@@ -207,15 +220,19 @@ class ReconcileControllerTest extends TestCase
*/
public function testShow(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn(TransactionCurrency::find(1));
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('getAssetTransaction')->once()->andReturn($journal->transactions()->first());
@@ -238,9 +255,9 @@ class ReconcileControllerTest extends TestCase
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('getAssetTransaction')->once()->andReturnNull();
@@ -279,8 +296,8 @@ class ReconcileControllerTest extends TestCase
*/
public function testSubmit(): void
{
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -310,7 +327,7 @@ class ReconcileControllerTest extends TestCase
*/
public function testUpdate(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
@@ -336,6 +353,9 @@ class ReconcileControllerTest extends TestCase
*/
public function testUpdateNotReconcile(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$data = ['amount' => '5',];
@@ -351,6 +371,9 @@ class ReconcileControllerTest extends TestCase
*/
public function testUpdateZero(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$data = ['amount' => '0',];

View File

@@ -51,7 +51,7 @@ class ShowControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
@@ -67,13 +67,15 @@ class ShowControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff:
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@@ -121,10 +123,11 @@ class ShowControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@@ -159,12 +162,16 @@ class ShowControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Account\ShowController
* @expectedExceptionMessage End is after start!
*/
public function testShowBrokenBadDates(): void
{
// mock
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('isLiability')->atLeast()->once()->andReturn(false);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->session(['start' => '2018-01-01', 'end' => '2017-12-01']);
@@ -172,6 +179,7 @@ class ShowControllerTest extends TestCase
$account = $this->user()->accounts()->where('account_type_id', 3)->orderBy('id', 'ASC')->whereNull('deleted_at')->first();
$response = $this->get(route('accounts.show', [$account->id, '2018-01-01', '2017-12-01']));
$response->assertStatus(500);
$response->assertSee('End is after start!');
}
/**
@@ -181,6 +189,9 @@ class ShowControllerTest extends TestCase
{
// mock
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
@@ -209,7 +220,7 @@ class ShowControllerTest extends TestCase
$repository = $this->mock(AccountRepositoryInterface::class);
// mock hasRole for user repository:
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAccounts')->andReturnSelf();
@@ -244,6 +255,8 @@ class ShowControllerTest extends TestCase
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$date = new Carbon;