Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix tests for current feature set.
James Colec0ab0b5af584
diff --git a/tests/Feature/Controllers/Import/JobStatusControllerTest.php b/tests/Feature/Controllers/Import/JobStatusControllerTest.phpindex 07ae4f8a0f..be26b78d6a 100644--- a/tests/Feature/Controllers/Import/JobStatusControllerTest.php+++ b/tests/Feature/Controllers/Import/JobStatusControllerTest.php@@ -93,6 +93,8 @@ class JobStatusControllerTest extends TestCase$job->file_type = '';$job->save();+ $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);+// call thing.$this->be($this->user());$response = $this->get(route('import.job.status.json', [$job->key]));@@ -120,6 +122,8 @@ class JobStatusControllerTest extends TestCase$job->tag()->associate($tag);$job->save();+ $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);+// call thing.$this->be($this->user());$response = $this->get(route('import.job.status.json', [$job->key]));@@ -143,6 +147,8 @@ class JobStatusControllerTest extends TestCase$second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first();$tag->transactionJournals()->sync([$journal->id, $second->id]);+ $importRepos->shouldReceive('countTransactions')->once()->andReturn(2);+$job = new ImportJob;$job->user_id = $this->user()->id;$job->key = 'Dfake_job_' . random_int(1, 10000);@@ -175,6 +181,8 @@ class JobStatusControllerTest extends TestCase$journal = $this->user()->transactionJournals()->first();$tag->transactionJournals()->sync([$journal->id]);+ $importRepos->shouldReceive('countTransactions')->once()->andReturn(1);+$job = new ImportJob;$job->user_id = $this->user()->id;$job->key = 'Efake_job_' . random_int(1, 10000);diff --git a/tests/Feature/Controllers/Json/ReconcileControllerTest.php b/tests/Feature/Controllers/Json/ReconcileControllerTest.phpindex e8dca4ece0..2a10f538dd 100644--- a/tests/Feature/Controllers/Json/ReconcileControllerTest.php+++ b/tests/Feature/Controllers/Json/ReconcileControllerTest.php@@ -57,14 +57,22 @@ class ReconcileControllerTest extends TestCase*/public function testOverview(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$recurringRepos = $this->mock(RecurringRepositoryInterface::class);- $transactions = $this->user()->transactions()->inRandomOrder()->take(3)->get();- $repository = $this->mock(JournalRepositoryInterface::class);+ $transactions = $this->user()->transactions()->inRandomOrder()->take(3)->get();+ $transactions =$transactions->each(+ function (Transaction $transaction) {+ $transaction->transaction_amount = '5';+ }+ );+ $repository = $this->mock(JournalRepositoryInterface::class);$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);$repository->shouldReceive('getTransactionsById')->andReturn($transactions)->twice();+ $accountRepos->shouldReceive('findNull')->andReturn($this->getRandomAsset())->atLeast()->once();+ $accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn(1);+$parameters = ['startBalance' => '0','endBalance' => '10',@@ -83,8 +91,8 @@ class ReconcileControllerTest extends TestCase*/public function testOverviewNotAsset(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$recurringRepos = $this->mock(RecurringRepositoryInterface::class);$account = $this->user()->accounts()->where('account_type_id', '!=', 3)->first();@@ -107,8 +115,8 @@ class ReconcileControllerTest extends TestCase*/public function testTransactions(): void{- $repository = $this->mock(CurrencyRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $repository = $this->mock(CurrencyRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);$recurringRepos = $this->mock(RecurringRepositoryInterface::class);$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();@@ -125,8 +133,8 @@ class ReconcileControllerTest extends TestCase*/public function testTransactionsInitialBalance(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);$recurringRepos = $this->mock(RecurringRepositoryInterface::class);diff --git a/tests/Unit/Import/Storage/ImportArrayStorageTest.php b/tests/Unit/Import/Storage/ImportArrayStorageTest.phpindex 4e6491b7d4..6f1a224dc5 100644--- a/tests/Unit/Import/Storage/ImportArrayStorageTest.php+++ b/tests/Unit/Import/Storage/ImportArrayStorageTest.php@@ -86,6 +86,7 @@ class ImportArrayStorageTest extends TestCase// mock calls:$repository->shouldReceive('setUser')->once();$journalRepos->shouldReceive('setUser')->once();+ $repository->shouldReceive('getTransactions')->once()->andReturn([]);$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -120,7 +121,8 @@ class ImportArrayStorageTest extends TestCase$job->provider = 'fake';$job->file_type = '';$job->configuration = ['apply-rules' => true];- $job->transactions = [$this->singleTransfer(), $this->singleWithdrawal(), $this->basedOnTransfer($transfer)];+ $job->transactions = ['count' => 3];+ $transactions = [$this->singleTransfer(), $this->singleWithdrawal(), $this->basedOnTransfer($transfer)];$job->save();@@ -138,7 +140,7 @@ class ImportArrayStorageTest extends TestCase$tagRepos = $this->mock(TagRepositoryInterface::class);$ruleRepos = $this->mock(RuleRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);-+ $repository->shouldReceive('getTransactions')->times(2)->andReturn($transactions);// mock calls:$collector->shouldReceive('setUser')->times(2);@@ -156,7 +158,6 @@ class ImportArrayStorageTest extends TestCase[Mockery::any(), 'Row #2 ("' . $transfer->description . '") could not be imported. Such a transfer already exists.'])->once();-// mock collector so it will return some transfers:$collector->shouldReceive('setAllAssetAccounts')->times(1)->andReturnSelf();$collector->shouldReceive('setTypes')->withArgs([[TransactionType::TRANSFER]])->once()->andReturnSelf();@@ -201,7 +202,7 @@ class ImportArrayStorageTest extends TestCase$job->provider = 'fake';$job->file_type = '';$job->configuration = ['apply-rules' => true];- $job->transactions = $transactions;+ $job->transactions = ['count' => 2];$job->save();// get some stuff:@@ -222,6 +223,7 @@ class ImportArrayStorageTest extends TestCase$journalRepos = $this->mock(JournalRepositoryInterface::class);// mock calls:+ $repository->shouldReceive('getTransactions')->times(2)->andReturn($transactions);$repository->shouldReceive('setUser')->once();$repository->shouldReceive('setStatus')->withAnyArgs();$ruleRepos->shouldReceive('setUser')->once();@@ -276,6 +278,7 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setUser')->once();$repository->shouldReceive('setStatus')->withAnyArgs();$journalRepos->shouldReceive('setUser')->once();+ $repository->shouldReceive('getTransactions')->times(2)->andReturn([]);$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -318,6 +321,7 @@ class ImportArrayStorageTest extends TestCase$journalRepos = $this->mock(JournalRepositoryInterface::class);// mock calls:+ $repository->shouldReceive('getTransactions')->times(2)->andReturn([]);$repository->shouldReceive('setUser')->once();$repository->shouldReceive('setStatus')->withAnyArgs();$ruleRepos->shouldReceive('setUser')->once();@@ -344,7 +348,8 @@ class ImportArrayStorageTest extends TestCase$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());// make fake job- $job = new ImportJob;+ $transactions = [$this->singleWithdrawal()];+ $job = new ImportJob;$job->user()->associate($this->user());$job->key = 'e_storage' . random_int(1, 10000);$job->status = 'new';@@ -352,7 +357,7 @@ class ImportArrayStorageTest extends TestCase$job->provider = 'fake';$job->file_type = '';$job->configuration = ['apply-rules' => true];- $job->transactions = [$this->singleWithdrawal()];+ $job->transactions = ['count' => 1];$job->save();// get some stuff:@@ -377,6 +382,7 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->once();$journalRepos->shouldReceive('store')->once()->andReturn($journal);$journalRepos->shouldReceive('findByHash')->andReturn(null)->times(2);+ $repository->shouldReceive('getTransactions')->times(2)->andReturn($transactions);$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -398,7 +404,8 @@ class ImportArrayStorageTest extends TestCase$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());// make fake job- $job = new ImportJob;+ $job = new ImportJob;+ $transactions = [$this->singleWithdrawal()];$job->user()->associate($this->user());$job->key = 'f_storage' . random_int(1, 10000);$job->status = 'new';@@ -406,7 +413,7 @@ class ImportArrayStorageTest extends TestCase$job->provider = 'fake';$job->file_type = '';$job->configuration = ['apply-rules' => true];- $job->transactions = [$this->singleWithdrawal()];+ $job->transactions = ['count' => 1];$job->save();// get some stuff:@@ -435,6 +442,7 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->once();$journalRepos->shouldReceive('store')->once()->andReturn($journal);$journalRepos->shouldReceive('findByHash')->andReturn(null)->times(2);+ $repository->shouldReceive('getTransactions')->times(2)->andReturn($transactions);$storage = new ImportArrayStorage;@@ -458,6 +466,7 @@ class ImportArrayStorageTest extends TestCase// make fake job$job = new ImportJob;+ $transactions = [$this->singleTransfer(), $this->singleWithdrawal()];$job->user()->associate($this->user());$job->key = 'g_storage' . random_int(1, 10000);$job->status = 'new';@@ -465,7 +474,7 @@ class ImportArrayStorageTest extends TestCase$job->provider = 'fake';$job->file_type = '';$job->configuration = ['apply-rules' => true];- $job->transactions = [$this->singleTransfer(), $this->singleWithdrawal()];+ $job->transactions = ['count' => 2];$job->save();// get a transfer:@@ -506,6 +515,7 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->once();$journalRepos->shouldReceive('store')->twice()->andReturn($journal);$journalRepos->shouldReceive('findByHash')->andReturn(null)->times(4);+ $repository->shouldReceive('getTransactions')->times(2)->andReturn($transactions);// mock collector so it will return some transfers:$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();@@ -587,6 +597,7 @@ class ImportArrayStorageTest extends TestCase/*** @return array+ * @throws \Exception*/private function singleTransfer(): array{@@ -635,6 +646,7 @@ class ImportArrayStorageTest extends TestCase/*** @return array+ * @throws \Exception*/private function singleWithdrawal(): array{