Improve tests.

This commit is contained in:
James Cole
2018-12-17 07:09:44 +01:00
parent 89942ee49c
commit 454b3ebd97
19 changed files with 494 additions and 375 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
@@ -69,12 +70,12 @@ class TransactionControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->twice()->andReturn($transfer);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@@ -107,12 +108,12 @@ class TransactionControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->twice()->andReturn($transfer);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@@ -153,15 +154,15 @@ class TransactionControllerTest extends TestCase
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -205,17 +206,17 @@ class TransactionControllerTest extends TestCase
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -256,12 +257,12 @@ class TransactionControllerTest extends TestCase
$collection = new Collection([$transaction]);
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
@@ -303,12 +304,12 @@ class TransactionControllerTest extends TestCase
$collection = new Collection([$transaction]);
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
@@ -338,11 +339,11 @@ class TransactionControllerTest extends TestCase
*/
public function testReconcile(): void
{
$data = ['transactions' => [1, 2]];
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$data = ['transactions' => [1, 2]];
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->times(1)->andReturn(new TransactionJournal);
$repository->shouldReceive('findTransaction')->andReturn(new Transaction)->twice();
@@ -363,7 +364,7 @@ class TransactionControllerTest extends TestCase
$journal->date = new Carbon('2016-01-01');
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->once()->andReturn($journal);
@@ -385,24 +386,36 @@ class TransactionControllerTest extends TestCase
public function testShow(): void
{
// mock stuff
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('getAttachments')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal)->atLeast()->once();
$journalRepos->shouldReceive('getAttachments')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
// $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
// $journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('transactions.show', [1]));
@@ -411,17 +424,16 @@ class TransactionControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Controller
* @covers \FireflyIII\Http\Controllers\TransactionController
*/
public function testShowOpeningBalance(): void
{
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);