Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Improve test coverage.
James Cole75c2529d3e31
diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.phpindex 87ab51a811..2866feaf1a 100644--- a/app/Exceptions/GracefulNotFoundHandler.php+++ b/app/Exceptions/GracefulNotFoundHandler.php@@ -52,6 +52,9 @@ class GracefulNotFoundHandler extends ExceptionHandlerpublic function render($request, Exception $exception){$route = $request->route();+ if(null === $route) {+ return parent::render($request, $exception);+ }$name = $route->getName();if (!auth()->check()) {return parent::render($request, $exception);diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.phpindex e18108908d..fbcfdde080 100644--- a/app/Repositories/PiggyBank/PiggyBankRepository.php+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php@@ -431,31 +431,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterfacereturn $savePerMonth;}- /**- * @param PiggyBankEvent $event- *- * @return int|null- */- public function getTransactionWithEvent(PiggyBankEvent $event): ?int- {- $journal = $event->transactionJournal;- if (null === $journal) {- return null;- }- if ((float)$event->amount < 0) {- $transaction = $journal->transactions()->where('amount', '<', 0)->first();-- return $transaction->id ?? null;- }- if ((float)$event->amount > 0) {- $transaction = $journal->transactions()->where('amount', '>', 0)->first();-- return $transaction->id ?? null;- }-- return null;- }-/*** Get for piggy account what is left to put in piggies.*diff --git a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.phpindex e5d784760f..631d522521 100644--- a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php+++ b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php@@ -199,13 +199,6 @@ interface PiggyBankRepositoryInterface*/public function getSuggestedMonthlyAmount(PiggyBank $piggyBank): string;- /**- * @param PiggyBankEvent $event- *- * @return int|null- */- public function getTransactionWithEvent(PiggyBankEvent $event): ?int;-/*** Get for piggy account what is left to put in piggies.*diff --git a/app/Support/Import/Routine/File/ImportableConverter.php b/app/Support/Import/Routine/File/ImportableConverter.phpindex dd09471b85..c88822811f 100644--- a/app/Support/Import/Routine/File/ImportableConverter.php+++ b/app/Support/Import/Routine/File/ImportableConverter.php@@ -156,7 +156,7 @@ class ImportableConverter'transactions' => [['user' => $this->importJob->user_id,- 'type' => $transactionType,+ 'type' => strtolower($transactionType),'date' => $this->convertDateValue($importable->date) ?? Carbon::now()->format('Y-m-d H:i:s'),'order' => 0,diff --git a/app/Support/Import/Routine/Spectre/StageImportDataHandler.php b/app/Support/Import/Routine/Spectre/StageImportDataHandler.phpindex 7bc0552663..e0849fff7d 100644--- a/app/Support/Import/Routine/Spectre/StageImportDataHandler.php+++ b/app/Support/Import/Routine/Spectre/StageImportDataHandler.php@@ -81,6 +81,7 @@ class StageImportDataHandler}$totalSet = array_merge(...$totalSet);Log::debug(sprintf('Found %d transactions in total.', count($totalSet)));+$this->repository->setTransactions($this->importJob, $totalSet);}diff --git a/app/Transformers/PiggyBankEventTransformer.php b/app/Transformers/PiggyBankEventTransformer.phpindex 87241602f0..dd9f1d40ab 100644--- a/app/Transformers/PiggyBankEventTransformer.php+++ b/app/Transformers/PiggyBankEventTransformer.php@@ -82,8 +82,7 @@ class PiggyBankEventTransformer extends AbstractTransformer}// get associated journal and transaction, if any:- $journalId = $event->transaction_journal_id;- $transactionId = $this->piggyRepos->getTransactionWithEvent($event);+ $journalId = (int)$event->transaction_journal_id;$data = ['id' => (int)$event->id,@@ -94,8 +93,7 @@ class PiggyBankEventTransformer extends AbstractTransformer'currency_code' => $currency->code,'currency_symbol' => $currency->symbol,'currency_decimal_places' => $currency->decimal_places,- 'journal_id' => $journalId,- 'transaction_id' => $transactionId,+ 'transaction_journal_id' => $journalId,'links' => [['rel' => 'self',diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.phpindex 2da9fc6955..1248bb81f4 100644--- a/app/Transformers/TransactionGroupTransformer.php+++ b/app/Transformers/TransactionGroupTransformer.php@@ -101,7 +101,6 @@ class TransactionGroupTransformer extends AbstractTransformer*/public function transformObject(TransactionGroup $group): array{- //$first = $group->transactionJournals->first();$result = ['id' => (int)$group->id,'created_at' => $group->created_at->toAtomString(),@@ -174,11 +173,13 @@ class TransactionGroupTransformer extends AbstractTransformer// get foreign amount:$foreignAmount = null;+ // @codeCoverageIgnoreStartif (null !== $source->foreign_amount) {$foreignAmount = TransactionType::WITHDRAWAL !== $type? app('steam')->negative($source->foreign_amount): app('steam')->positive($source->foreign_amount);}+ // @codeCoverageIgnoreEnd$metaFieldData = $this->groupRepos->getMetaFields($journal->id, $this->metaFields);$metaDateData = $this->groupRepos->getMetaDateFields($journal->id, $this->metaDateFields);@@ -280,7 +281,7 @@ class TransactionGroupTransformer extends AbstractTransformer}$foreignAmount = null;if (null !== $row['foreign_amount']) {- $foreignAmount = TransactionType::WITHDRAWAL !== $type ? bcmul($row['foreign_amount'], '-1') : $row['foreign_amount'];+ $foreignAmount = TransactionType::WITHDRAWAL !== $type ? bcmul($row['foreign_amount'], '-1') : $row['foreign_amount']; // @codeCoverageIgnore}$metaFieldData = $this->groupRepos->getMetaFields((int)$row['transaction_journal_id'], $this->metaFields);diff --git a/app/Transformers/TransactionTransformer.php b/app/Transformers/TransactionTransformer.phpdeleted file mode 100644index 4f9ab3f8c5..0000000000--- a/app/Transformers/TransactionTransformer.php+++ /dev/null@@ -1,214 +0,0 @@-<?php-/**- * TransactionTransformer.php- * Copyright (c) 2018 [email protected]- *- * This file is part of Firefly III.- *- * Firefly III is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * Firefly III is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.- */--declare(strict_types=1);--namespace FireflyIII\Transformers;---use FireflyIII\Exceptions\FireflyException;-use FireflyIII\Models\Transaction;-use FireflyIII\Models\TransactionType;-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;-use Log;--/**- * Class TransactionTransformer- * @deprecated- */-class TransactionTransformer extends AbstractTransformer-{- /** @var JournalRepositoryInterface */- protected $repository;-- /**- * TransactionTransformer constructor.- *- * @codeCoverageIgnore- */- public function __construct()- {- $this->repository = app(JournalRepositoryInterface::class);- if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));- }- }-- /**- * Transform the journal.- *- * @param Transaction $transaction- *- * @return array- * @throws FireflyException- */- public function transform(Transaction $transaction): array- {- $journal = $transaction->transactionJournal;- $category = $this->getCategory($transaction);- $budget = $this->getBudget($transaction);-- $this->repository->setUser($journal->user);-- $notes = $this->repository->getNoteText($journal);- $tags = implode(',', $this->repository->getTags($journal));-- $data = [- 'id' => (int)$transaction->id,- 'created_at' => $transaction->created_at->toAtomString(),- 'updated_at' => $transaction->updated_at->toAtomString(),- 'description' => $transaction->description,- 'journal_description' => $transaction->description,- 'transaction_description' => $transaction->transaction_description,- 'date' => $transaction->date->toAtomString(),- 'type' => $transaction->transaction_type_type,- 'identifier' => $transaction->identifier,- 'journal_id' => (int)$transaction->journal_id,- 'reconciled' => (bool)$transaction->reconciled,- 'amount' => round($transaction->transaction_amount, (int)$transaction->transaction_currency_dp),- 'currency_id' => $transaction->transaction_currency_id,- 'currency_code' => $transaction->transaction_currency_code,- 'currency_symbol' => $transaction->transaction_currency_symbol,- 'currency_decimal_places' => $transaction->transaction_currency_dp,- 'foreign_amount' => null,- 'foreign_currency_id' => $transaction->foreign_currency_id,- 'foreign_currency_code' => $transaction->foreign_currency_code,- 'foreign_currency_symbol' => $transaction->foreign_currency_symbol,- 'foreign_currency_decimal_places' => $transaction->foreign_currency_dp,- 'bill_id' => $transaction->bill_id,- 'bill_name' => $transaction->bill_name,- 'category_id' => $category['category_id'],- 'category_name' => $category['category_name'],- 'budget_id' => $budget['budget_id'],- 'budget_name' => $budget['budget_name'],- 'notes' => $notes,- 'sepa_cc' => $this->repository->getMetaField($journal, 'sepa_cc'),- 'sepa_ct_op' => $this->repository->getMetaField($journal, 'sepa_ct_op'),- 'sepa_ct_id' => $this->repository->getMetaField($journal, 'sepa_ct_ud'),- 'sepa_db' => $this->repository->getMetaField($journal, 'sepa_db'),- 'sepa_country' => $this->repository->getMetaField($journal, 'sepa_country'),- 'sepa_ep' => $this->repository->getMetaField($journal, 'sepa_ep'),- 'sepa_ci' => $this->repository->getMetaField($journal, 'sepa_ci'),- 'sepa_batch_id' => $this->repository->getMetaField($journal, 'sepa_batch_id'),- 'interest_date' => $this->repository->getMetaDateString($journal, 'interest_date'),- 'book_date' => $this->repository->getMetaDateString($journal, 'book_date'),- 'process_date' => $this->repository->getMetaDateString($journal, 'process_date'),- 'due_date' => $this->repository->getMetaDateString($journal, 'due_date'),- 'payment_date' => $this->repository->getMetaDateString($journal, 'payment_date'),- 'invoice_date' => $this->repository->getMetaDateString($journal, 'invoice_date'),- 'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),- 'bunq_payment_id' => $this->repository->getMetaField($journal, 'bunq_payment_id'),- 'import_hash_v2' => $this->repository->getMetaField($journal, 'import_hash_v2'),- 'recurrence_id' => (int)$this->repository->getMetaField($journal, 'recurrence_id'),- 'external_id' => $this->repository->getMetaField($journal, 'external_id'),- 'original_source' => $this->repository->getMetaField($journal, 'original-source'),- 'tags' => '' === $tags ? null : $tags,- 'links' => [- [- 'rel' => 'self',- 'uri' => '/transactions/' . $transaction->id,- ],- ],- ];-- // expand foreign amount:- if (null !== $transaction->transaction_foreign_amount) {- $data['foreign_amount'] = round($transaction->transaction_foreign_amount, (int)$transaction->foreign_currency_dp);- }-- // switch on type for consistency- switch ($transaction->transaction_type_type) {- case TransactionType::WITHDRAWAL:- Log::debug(sprintf('%d is a withdrawal', $transaction->journal_id));- $data['source_id'] = $transaction->account_id;- $data['source_name'] = $transaction->account_name;- $data['source_iban'] = $transaction->account_iban;- $data['source_type'] = $transaction->account_type;- $data['destination_id'] = $transaction->opposing_account_id;- $data['destination_name'] = $transaction->opposing_account_name;- $data['destination_iban'] = $transaction->opposing_account_iban;- $data['destination_type'] = $transaction->opposing_account_type;- Log::debug(sprintf('source_id / account_id is %d', $transaction->account_id));- Log::debug(sprintf('source_name / account_name is "%s"', $transaction->account_name));- break;- case TransactionType::DEPOSIT:- case TransactionType::TRANSFER:- case TransactionType::OPENING_BALANCE:- case TransactionType::RECONCILIATION:- $data['source_id'] = $transaction->opposing_account_id;- $data['source_name'] = $transaction->opposing_account_name;- $data['source_iban'] = $transaction->opposing_account_iban;- $data['source_type'] = $transaction->opposing_account_type;- $data['destination_id'] = $transaction->account_id;- $data['destination_name'] = $transaction->account_name;- $data['destination_iban'] = $transaction->account_iban;- $data['destination_type'] = $transaction->account_type;- break;- default:- // @codeCoverageIgnoreStart- throw new FireflyException(- sprintf('Transaction transformer cannot handle transactions of type "%s"!', $transaction->transaction_type_type)- );- // @codeCoverageIgnoreEnd-- }-- // expand description.- if ('' !== (string)$transaction->transaction_description) {- $data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')';- }-- return $data;- }-- /**- * @param Transaction $transaction- *- * @return array- */- private function getBudget(Transaction $transaction): array- {- if ($transaction->transaction_type_type !== TransactionType::WITHDRAWAL) {- return [- 'budget_id' => null,- 'budget_name' => null,- ];- }-- return [- 'budget_id' => $transaction->transaction_budget_id ?? $transaction->transaction_journal_budget_id,- 'budget_name' => $transaction->transaction_budget_name ?? $transaction->transaction_journal_budget_name,- ];- }-- /**- * @param Transaction $transaction- *- * @return array- */- private function getCategory(Transaction $transaction): array- {- return [- 'category_id' => $transaction->transaction_category_id ?? $transaction->transaction_journal_category_id,- 'category_name' => $transaction->transaction_category_name ?? $transaction->transaction_journal_category_name,- ];- }-}diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xmlindex 25014c1015..adacd4f17f 100644--- a/phpunit.coverage.specific.xml+++ b/phpunit.coverage.specific.xml@@ -32,40 +32,15 @@<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /></listeners><testsuites>- <!-- test suites --><testsuite name="Api"><directory suffix="Test.php">./tests/Api</directory></testsuite>- <!-- unit tests, splitted: --><testsuite name="Unit">- <directory suffix="Test.php">./tests/Unit/Console</directory>- <directory suffix="Test.php">./tests/Unit/Factory</directory>- <directory suffix="Test.php">./tests/Unit/Generator</directory>- <directory suffix="Test.php">./tests/Unit/Handlers</directory>- <directory suffix="Test.php">./tests/Unit/Helpers</directory>- <directory suffix="Test.php">./tests/Unit/Import</directory>- <directory suffix="Test.php">./tests/Unit/Jobs</directory>- <directory suffix="Test.php">./tests/Unit/Middleware</directory>- <directory suffix="Test.php">./tests/Unit/Rules</directory>- <directory suffix="Test.php">./tests/Unit/Services</directory>- <directory suffix="Test.php">./tests/Unit/Support</directory>- <directory suffix="Test.php">./tests/Unit/TransactionRules</directory>- <directory suffix="Test.php">./tests/Unit/Transformers</directory>-- </testsuite>- <testsuite name="Feature">- <directory suffix="Test.php">./tests/Feature</directory>+ <directory suffix="Test.php">./tests/Unit</directory></testsuite>--- <!--<testsuite name="Feature"><directory suffix="Test.php">./tests/Feature</directory></testsuite>- <testsuite name="Unit">- <directory suffix="Test.php">./tests/Unit</directory>- </testsuite>- --></testsuites><filter><whitelist processUncoveredFilesFromWhitelist="true">diff --git a/phpunit.coverage.xml b/phpunit.coverage.xmlindex 887bb12f54..ef98e08323 100644--- a/phpunit.coverage.xml+++ b/phpunit.coverage.xml@@ -32,39 +32,15 @@<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /></listeners><testsuites>- <!-- test suites --><testsuite name="Api"><directory suffix="Test.php">./tests/Api</directory></testsuite>- <!-- unit tests, splitted: --><testsuite name="Unit">- <directory suffix="Test.php">./tests/Unit/Console</directory>- <directory suffix="Test.php">./tests/Unit/Factory</directory>- <directory suffix="Test.php">./tests/Unit/Generator</directory>- <directory suffix="Test.php">./tests/Unit/Handlers</directory>- <directory suffix="Test.php">./tests/Unit/Helpers</directory>- <directory suffix="Test.php">./tests/Unit/Import</directory>- <directory suffix="Test.php">./tests/Unit/Jobs</directory>- <directory suffix="Test.php">./tests/Unit/Middleware</directory>- <directory suffix="Test.php">./tests/Unit/Rules</directory>- <directory suffix="Test.php">./tests/Unit/Services</directory>- <directory suffix="Test.php">./tests/Unit/Support</directory>- <directory suffix="Test.php">./tests/Unit/TransactionRules</directory>- <directory suffix="Test.php">./tests/Unit/Transformers</directory>+ <directory suffix="Test.php">./tests/Unit</directory></testsuite><testsuite name="Feature"><directory suffix="Test.php">./tests/Feature</directory></testsuite>--- <!--- <testsuite name="Feature">- <directory suffix="Test.php">./tests/Feature</directory>- </testsuite>- <testsuite name="Unit">- <directory suffix="Test.php">./tests/Unit</directory>- </testsuite>- --></testsuites><filter><whitelist processUncoveredFilesFromWhitelist="true">diff --git a/phpunit.xml b/phpunit.xmlindex c86ba80894..c0781ce0a5 100644--- a/phpunit.xml+++ b/phpunit.xml@@ -32,38 +32,15 @@<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /></listeners><testsuites>- <!-- test suites --><testsuite name="Api"><directory suffix="Test.php">./tests/Api</directory></testsuite>- <!-- unit tests, splitted: --><testsuite name="Unit">- <!--- <directory suffix="Test.php">./tests/Unit/Console</directory>- <directory suffix="Test.php">./tests/Unit/Factory</directory>- <directory suffix="Test.php">./tests/Unit/Generator</directory>- <directory suffix="Test.php">./tests/Unit/Handlers</directory>- <directory suffix="Test.php">./tests/Unit/Helpers</directory>- <directory suffix="Test.php">./tests/Unit/Import</directory>- <directory suffix="Test.php">./tests/Unit/Jobs</directory>- <directory suffix="Test.php">./tests/Unit/Middleware</directory>- <directory suffix="Test.php">./tests/Unit/Rules</directory>- <directory suffix="Test.php">./tests/Unit/Services</directory>- <directory suffix="Test.php">./tests/Unit/Support</directory>- <directory suffix="Test.php">./tests/Unit/TransactionRules</directory>- -->- <directory suffix="Test.php">./tests/Unit/Transformers</directory>+ <directory suffix="Test.php">./tests/Unit</directory></testsuite><testsuite name="Feature"><directory suffix="Test.php">./tests/Feature</directory></testsuite>-- <!---- <testsuite name="Unit">- <directory suffix="Test.php">./tests/Unit</directory>- </testsuite>- --></testsuites><filter><whitelist processUncoveredFilesFromWhitelist="true">diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.phpindex 8826b663a2..5f26da5340 100644--- a/tests/Feature/Controllers/CurrencyControllerTest.php+++ b/tests/Feature/Controllers/CurrencyControllerTest.php@@ -509,6 +509,7 @@ class CurrencyControllerTest extends TestCase$repository->shouldReceive('update')->andReturn(new TransactionCurrency);$userRepos->shouldReceive('hasRole')->once()->andReturn(true);+ $repository->shouldReceive('currencyInUse')->atLeast()->once()->andReturn(true);Preferences::shouldReceive('mark')->atLeast()->once();$this->session(['currencies.edit.uri' => 'http://localhost']);diff --git a/tests/Feature/Controllers/Transaction/ShowControllerTest.php b/tests/Feature/Controllers/Transaction/ShowControllerTest.phpindex 324fd08a2d..00d6a28c25 100644--- a/tests/Feature/Controllers/Transaction/ShowControllerTest.php+++ b/tests/Feature/Controllers/Transaction/ShowControllerTest.php@@ -55,9 +55,9 @@ class ShowControllerTest extends TestCase$withdrawal = $this->getRandomWithdrawalGroup();$array = $this->getRandomWithdrawalGroupAsArray();- $array[0]['transactions'][0]['foreign_amount'] = '10';- $array[0]['transactions'][0]['foreign_currency_symbol'] = 'x';- $array[0]['transactions'][0]['foreign_currency_decimal_places'] = 2;+ $array['transactions'][0]['foreign_amount'] = '10';+ $array['transactions'][0]['foreign_currency_symbol'] = 'x';+ $array['transactions'][0]['foreign_currency_decimal_places'] = 2;$groupRepository = $this->mock(TransactionGroupRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);@@ -65,7 +65,7 @@ class ShowControllerTest extends TestCase// mock for transformer:$transformer->shouldReceive('setParameters')->atLeast()->once();- $transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array[0]);+ $transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array);// mock for repos$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 7558819bea..5d838e62b8 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -41,6 +41,7 @@ use FireflyIII\Models\Configuration;use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\ImportJob;use FireflyIII\Models\PiggyBank;+use FireflyIII\Models\PiggyBankEvent;use FireflyIII\Models\Preference;use FireflyIII\Models\Recurrence;use FireflyIII\Models\Rule;@@ -67,6 +68,14 @@ use RuntimeException;abstract class TestCase extends BaseTestCase{+ /**+ * @return ImportJob+ */+ public function getRandomPiggyBankEvent(): PiggyBankEvent+ {+ return PiggyBankEvent::inRandomOrder()->first();+ }+/*** @return ImportJob*/@@ -347,7 +356,6 @@ abstract class TestCase extends BaseTestCase/*** @return array- * @throws Exception*/public function getRandomWithdrawalGroupAsArray(): array{@@ -360,12 +368,15 @@ abstract class TestCase extends BaseTestCase$e->getMessage();}- return [+ return['group_title' => null,'transactions' => [[+ 'updated_at' => new Carbon,+ 'created_at' => new Carbon,'transaction_journal_id' => $withdrawal->id,+ 'transaction_type_type' => 'Withdrawal','currency_id' => $euro->id,'foreign_currency_id' => null,'date' => $date,@@ -380,8 +391,47 @@ abstract class TestCase extends BaseTestCase'budget_id' => $budget->id,],],- ],- ];+ ];+ }++ /**+ * @return array+ */+ public function getRandomDepositGroupAsArray(): array+ {+ $deposit = $this->getRandomDeposit();+ $euro = $this->getEuro();+ $budget = $this->getRandomBudget();+ try {+ $date = new Carbon;+ } catch (Exception $e) {+ $e->getMessage();+ }++ return+ [+ 'group_title' => null,+ 'transactions' => [+ [+ 'updated_at' => new Carbon,+ 'created_at' => new Carbon,+ 'transaction_journal_id' => $deposit->id,+ 'transaction_type_type' => 'Deposit',+ 'currency_id' => $euro->id,+ 'foreign_currency_id' => null,+ 'date' => $date,+ 'source_id' => 1,+ 'destination_id' => 4,+ 'currency_name' => $euro->name,+ 'currency_code' => $euro->code,+ 'currency_symbol' => $euro->symbol,+ 'currency_decimal_places' => $euro->decimal_places,+ 'amount' => '-30',+ 'foreign_amount' => null,+ 'budget_id' => $budget->id,+ ],+ ],+ ];}/**diff --git a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php b/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.phpindex 72a4fa9d21..e01688a6f5 100644--- a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php+++ b/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php@@ -65,22 +65,23 @@ class MonthReportGeneratorTest extends TestCase$dollar = $this->getDollar();$return = [[- 'description' => 'Hello',- 'amount' => '10',- 'foreign_currency_id' => null,- 'currency_id' => $euro->id,- 'source_id' => $asset->id,- 'source_name' => $asset->name,-+ 'description' => 'Hello',+ 'amount' => '10',+ 'foreign_currency_id' => null,+ 'currency_id' => $euro->id,+ 'source_id' => $asset->id,+ 'source_name' => $asset->name,+ 'transaction_journal_id' => 1,],[- 'description' => 'Hello2',- 'amount' => '10',- 'foreign_amount' => '10',- 'foreign_currency_id' => $euro->id,- 'currency_id' => $dollar->id,- 'source_id' => $asset->id,- 'source_name' => $asset->name,+ 'description' => 'Hello2',+ 'amount' => '10',+ 'foreign_amount' => '10',+ 'foreign_currency_id' => $euro->id,+ 'currency_id' => $dollar->id,+ 'source_id' => $asset->id,+ 'source_name' => $asset->name,+ 'transaction_journal_id' => 1,],];@@ -100,14 +101,15 @@ class MonthReportGeneratorTest extends TestCase// mock callsSteam::shouldReceive('balance')->times(2)->andReturn('100');$accountRepos->shouldReceive('setUser')->once();- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();+ //$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();+ $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);// mock collector:$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($return);- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();+ //$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();try {$result = $generator->getAuditReport($asset, $date);diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.phpindex 99415f967b..f6c4658271 100644--- a/tests/Unit/Middleware/BinderTest.php+++ b/tests/Unit/Middleware/BinderTest.php@@ -116,7 +116,7 @@ class BinderTest extends TestCasepublic function testAccountListEmpty(): void{Route::middleware(Binder::class)->any(- '/_test/binder/{accountList}', function (Collection $accounts) {+ '/_test/binder/{accountList}', static function (Collection $accounts) {return 'count: ' . $accounts->count();});diff --git a/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php b/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.phpindex 81a9d49140..a8a7027507 100644--- a/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php+++ b/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php@@ -144,7 +144,8 @@ class AssetAccountMapperTest extends TestCase// mock repository:$repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('setUser')->once();- $repository->shouldReceive('findByIbanNull')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);+ $repository->shouldReceive('findByIbanNull')->once()+ ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);$mapper = new AssetAccountMapper;$mapper->setUser($this->user());@@ -164,7 +165,8 @@ class AssetAccountMapperTest extends TestCase// mock repository:$repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('setUser')->once();- $repository->shouldReceive('findByName')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);+ $repository->shouldReceive('findByName')->once()+ ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);$mapper = new AssetAccountMapper;$mapper->setUser($this->user());@@ -184,7 +186,8 @@ class AssetAccountMapperTest extends TestCase// mock repository:$repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('setUser')->once();- $repository->shouldReceive('findByAccountNumber')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);+ $repository->shouldReceive('findByAccountNumber')->once()+ ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);$mapper = new AssetAccountMapper;$mapper->setUser($this->user());diff --git a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php b/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.phpindex 40a032c025..631b071e74 100644--- a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php+++ b/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php@@ -90,6 +90,9 @@ class OpposingAccountMapperTest extends TestCase$repository->shouldReceive('findNull')->andReturn($expected)->once();$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();$repository->shouldReceive('store')->withArgs([$expectedArgs])->once()->andReturn(new Account);@@ -127,8 +130,15 @@ class OpposingAccountMapperTest extends TestCase$repository->shouldReceive('findNull')->andReturn($expected)->once();$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::EXPENSE]])->andReturnNull();$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::ASSET]])->andReturnNull();+ $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::DEBT]])->andReturnNull();+ $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::MORTGAGE]])->andReturnNull();+ $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::LOAN]])->andReturnNull();+$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();+ $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();$repository->shouldReceive('store')->withArgs([$expectedArgs])->once()->andReturn(new Account);diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.phpindex cca0a6c86f..b3a7d33e89 100644--- a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php+++ b/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php@@ -74,8 +74,8 @@ class StageImportDataHandlerTest extends TestCase$today = new Carbon;// create fake transactions:- $op1 = 'Some opposing account #' . random_int(1, 100);- $op2 = 'Some opposing revenue account #' . random_int(1, 100);+ $op1 = 'Some opposing account #' . $this->randomInt();+ $op2 = 'Some opposing revenue account #' . $this->randomInt();$transactions = [new SpectreTransaction([@@ -85,7 +85,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => -123.45,'currency_code' => 'EUR',- 'description' => 'Fake description #' . random_int(1, 100),+ 'description' => 'Fake description #' . $this->randomInt(),'category' => 'some-category','duplicated' => false,'extra' => [@@ -104,7 +104,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => 563.21,'currency_code' => 'EUR',- 'description' => 'Fake second description #' . random_int(1, 100),+ 'description' => 'Fake second description #' . $this->randomInt(),'category' => 'some-other-category','duplicated' => false,'extra' => [@@ -142,28 +142,26 @@ class StageImportDataHandlerTest extends TestCase$lrRequest = $this->mock(ListTransactionsRequest::class);$mapper = $this->mock(OpposingAccountMapper::class);- // expected result$expected = [0 => [- 'type' => 'withdrawal',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",- 'external_id' => '1',- // journal data:- 'description' => $transactions[0]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // transaction here+ 'date' => $today->format('Y-m-d'),+ 'tags' => ['mode', 'active'],+ 'type' => 'withdrawal',+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",+ 'external_id' => '1',+ // journal data:+ 'description' => $transactions[0]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '-123.45','budget_id' => null,'budget_name' => null,@@ -180,28 +178,26 @@ class StageImportDataHandlerTest extends TestCase'identifier' => 0,],],-],1 => [- 'type' => 'deposit',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",- 'external_id' => '2',- // journal data:- 'description' => $transactions[1]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // transaction here+ 'date' => $today->format('Y-m-d'),+ 'tags' => ['mode', 'active'],+ 'type' => 'deposit',+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",+ 'external_id' => '2',+ // journal data:+ 'description' => $transactions[1]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '563.21','budget_id' => null,'budget_name' => null,@@ -218,14 +214,13 @@ class StageImportDataHandlerTest extends TestCase'identifier' => 0,],],-],];+$accountRepos->shouldReceive('setUser')->once();$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);$importRepos->shouldReceive('setUser')->once();- $importRepos->shouldReceive('setTransactions')->once()- ->withArgs([Mockery::any(), $expected]);+ $importRepos->shouldReceive('setTransactions')->once()->withArgs([Mockery::any(), $expected]);$lrRequest->shouldReceive('setUser')->once();$lrRequest->shouldReceive('setAccount')->once()->withArgs([Mockery::any()]);$lrRequest->shouldReceive('call')->once();@@ -273,9 +268,9 @@ class StageImportDataHandlerTest extends TestCase$today = new Carbon;// create fake transactions:- $op1 = 'Some opposing account #' . random_int(1, 100);- $op2 = 'Some opposing revenue account #' . random_int(1, 100);- $transactions = [+ $op1 = 'Some opposing account #' . $this->randomInt();+ $op2 = 'Some opposing revenue account #' . $this->randomInt();+ $transactions = [new SpectreTransaction(['id' => 1,@@ -284,7 +279,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => -123.45,'currency_code' => 'EUR',- 'description' => 'Fake description #' . random_int(1, 100),+ 'description' => 'Fake description #' . $this->randomInt(),'category' => 'some-category','duplicated' => true,'extra' => [@@ -304,7 +299,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => 563.21,'currency_code' => 'EUR',- 'description' => 'Fake second description #' . random_int(1, 100),+ 'description' => 'Fake second description #' . $this->randomInt(),'category' => 'some-other-category','duplicated' => false,'extra' => [@@ -345,29 +340,26 @@ class StageImportDataHandlerTest extends TestCase$lrRequest = $this->mock(ListTransactionsRequest::class);$mapper = $this->mock(OpposingAccountMapper::class);- // expected result$expected = [0 => [- 'type' => 'withdrawal',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active', 'possibly-duplicated'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",- 'external_id' => '1',- // journal data:- 'description' => $transactions[0]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),-- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // data here.+ 'date' => $today->format('Y-m-d'),+ 'type' => 'withdrawal',+ 'tags' => ['mode', 'active', 'possibly-duplicated'],+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",+ 'external_id' => '1',+ // journal data:+ 'description' => $transactions[0]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '-123.45','budget_id' => null,'budget_name' => null,@@ -386,26 +378,24 @@ class StageImportDataHandlerTest extends TestCase],],1 => [- 'type' => 'deposit',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active', 'cat-name'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",- 'external_id' => '2',- // journal data:- 'description' => $transactions[1]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),-- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // data here.+ 'date' => $today->format('Y-m-d'),+ 'type' => 'deposit',+ 'tags' => ['mode', 'active', 'cat-name'],+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",+ 'external_id' => '2',+ // journal data:+ 'description' => $transactions[1]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '563.21','budget_id' => null,'budget_name' => null,@@ -424,6 +414,7 @@ class StageImportDataHandlerTest extends TestCase],],];+$accountRepos->shouldReceive('setUser')->once();$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);$importRepos->shouldReceive('setUser')->once();@@ -474,8 +465,8 @@ class StageImportDataHandlerTest extends TestCase$today = new Carbon;// create fake transactions:- $op1 = 'Some opposing account #' . random_int(1, 100);- $op2 = 'Some opposing revenue account #' . random_int(1, 100);+ $op1 = 'Some opposing account #' . $this->randomInt();+ $op2 = 'Some opposing revenue account #' . $this->randomInt();$transactions = [new SpectreTransaction([@@ -485,7 +476,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => -123.45,'currency_code' => 'EUR',- 'description' => 'Fake description #' . random_int(1, 100),+ 'description' => 'Fake description #' . $this->randomInt(),'category' => 'some-category','duplicated' => true,'extra' => [@@ -504,7 +495,7 @@ class StageImportDataHandlerTest extends TestCase'made_on' => $today->toW3cString(),'amount' => 563.21,'currency_code' => 'EUR',- 'description' => 'Fake second description #' . random_int(1, 100),+ 'description' => 'Fake second description #' . $this->randomInt(),'category' => 'some-other-category','duplicated' => false,'extra' => [@@ -543,29 +534,26 @@ class StageImportDataHandlerTest extends TestCase$lrRequest = $this->mock(ListTransactionsRequest::class);$mapper = $this->mock(OpposingAccountMapper::class);- // expected result$expected = [0 => [- 'type' => 'withdrawal',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active', 'possibly-duplicated'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",- 'external_id' => '1',- // journal data:- 'description' => $transactions[0]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),-- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // data here+ 'date' => $today->format('Y-m-d'),+ 'type' => 'withdrawal',+ 'tags' => ['mode', 'active', 'possibly-duplicated'],+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",+ 'external_id' => '1',+ // journal data:+ 'description' => $transactions[0]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '-123.45','budget_id' => null,'budget_name' => null,@@ -584,26 +572,24 @@ class StageImportDataHandlerTest extends TestCase],],1 => [- 'type' => 'deposit',- 'date' => $today->format('Y-m-d'),- 'tags' => ['mode', 'active', 'cat-name'],- 'user' => $job->user_id,- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",- 'external_id' => '2',- // journal data:- 'description' => $transactions[1]->getDescription(),- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'bill_id' => null,- 'bill_name' => null,- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),-- // transaction data:- 'transactions' => [- [+ 'transactions' => [+ 0 => [+ // data here+ 'date' => $today->format('Y-m-d'),+ 'type' => 'deposit',+ 'tags' => ['mode', 'active', 'cat-name'],+ 'user' => $job->user_id,+ 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",+ 'external_id' => '2',+ // journal data:+ 'description' => $transactions[1]->getDescription(),+ 'piggy_bank_id' => null,+ 'piggy_bank_name' => null,+ 'bill_id' => null,+ 'bill_name' => null,+ 'original-source' => sprintf('spectre-v%s', config('firefly.version')),'currency_id' => null,'currency_code' => 'EUR',- 'description' => null,'amount' => '563.21','budget_id' => null,'budget_name' => null,@@ -622,6 +608,7 @@ class StageImportDataHandlerTest extends TestCase],],];+$accountRepos->shouldReceive('setUser')->once();$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);$importRepos->shouldReceive('setUser')->once();diff --git a/tests/Unit/Transformers/BillTransformerTest.php b/tests/Unit/Transformers/BillTransformerTest.phpindex 148762916a..bd78b724ce 100644--- a/tests/Unit/Transformers/BillTransformerTest.php+++ b/tests/Unit/Transformers/BillTransformerTest.php@@ -109,10 +109,7 @@ class BillTransformerTest extends TestCase$this->assertEquals('2018-03-01', $result['next_expected_match']);$this->assertEquals(['2018-01-01'], $result['pay_dates']);- $this->assertEquals(- ['2018-01-02', '2018-01-09', '2018-01-16', '2018-01-21', '2018-01-30',]- , $result['paid_dates']- );+ $this->assertEquals(['2018-01-02', '2018-01-09', '2018-01-16', '2018-01-21', '2018-01-30',], $result['paid_dates']);}}diff --git a/tests/Unit/Transformers/PiggyBankEventTransformerTest.php b/tests/Unit/Transformers/PiggyBankEventTransformerTest.phpindex f533ce0c45..6bd8e234b7 100644--- a/tests/Unit/Transformers/PiggyBankEventTransformerTest.php+++ b/tests/Unit/Transformers/PiggyBankEventTransformerTest.php@@ -68,16 +68,18 @@ class PiggyBankEventTransformerTest extends TestCase// mock calls:$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());- $piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);- $event = PiggyBankEvent::first();+ $event = $this->getRandomPiggyBankEvent();+++$transformer = app(PiggyBankEventTransformer::class);$transformer->setParameters(new ParameterBag);$result = $transformer->transform($event);$this->assertEquals($event->id, $result['id']);- $this->assertEquals(245, $result['amount']);- $this->assertEquals(123, $result['transaction_id']);+ $this->assertEquals($event->amount, $result['amount']);+ $this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);}@@ -100,18 +102,17 @@ class PiggyBankEventTransformerTest extends TestCase// mock calls:$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);- $piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->atLeast()->once();- $event = PiggyBankEvent::first();+ $event = $this->getRandomPiggyBankEvent();$transformer = app(PiggyBankEventTransformer::class);$transformer->setParameters(new ParameterBag);$result = $transformer->transform($event);$this->assertEquals($event->id, $result['id']);- $this->assertEquals(245, $result['amount']);- $this->assertEquals(123, $result['transaction_id']);+ $this->assertEquals($event->amount, $result['amount']);+ $this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);}}diff --git a/tests/Unit/Transformers/RecurrenceTransformerTest.php b/tests/Unit/Transformers/RecurrenceTransformerTest.phpindex efe64b7774..5628ab695a 100644--- a/tests/Unit/Transformers/RecurrenceTransformerTest.php+++ b/tests/Unit/Transformers/RecurrenceTransformerTest.php@@ -25,18 +25,15 @@ namespace Tests\Unit\Transformers;use Carbon\Carbon;use FireflyIII\Factory\CategoryFactory;-use FireflyIII\Models\Bill;-use FireflyIII\Models\Budget;-use FireflyIII\Models\Category;-use FireflyIII\Models\PiggyBank;-use FireflyIII\Models\Recurrence;-use FireflyIII\Models\TransactionCurrency;+use FireflyIII\Models\RecurrenceTransaction;+use FireflyIII\Models\RecurrenceTransactionMeta;use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;use FireflyIII\Transformers\RecurrenceTransformer;use Log;+use Mockery;use Symfony\Component\HttpFoundation\ParameterBag;use Tests\TestCase;@@ -56,7 +53,7 @@ class RecurrenceTransformerTest extends TestCase}/**- *+ * @covers \FireflyIII\Transformers\RecurrenceTransformer*/public function testBasic(): void{@@ -65,12 +62,13 @@ class RecurrenceTransformerTest extends TestCase$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);$factory = $this->mock(CategoryFactory::class);$budgetRepos = $this->mock(BudgetRepositoryInterface::class);- $category = Category::first();- $budget = Budget::first();- $piggy = PiggyBank::first();- $bill = Bill::first();- $foreignCurrency = TransactionCurrency::find(2);+ $category = $this->getRandomCategory();+ $budget = $this->getRandomBudget();+ $piggy = $this->getRandomPiggyBank();+ $bill = $this->getRandomBill();+ $foreignCurrency = $this->getDollar();$ranges = [new Carbon];+ $recurrence = $this->getRandomRecurrence();// mock calls:$recurrenceRepos->shouldReceive('setUser')->atLeast()->once();$billRepos->shouldReceive('setUser')->atLeast()->once();@@ -82,47 +80,21 @@ class RecurrenceTransformerTest extends TestCase$recurrenceRepos->shouldReceive('getNoteText')->once()->andReturn('Hi there');$recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr');$recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once();- $factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null, 'House'])->andReturn($category);+ $factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null,Mockery::any()])->andReturn($category);$budgetRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([2])->andReturn($budget);$piggyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($piggy);$billRepos->shouldReceive('find')->atLeast()->once()->withArgs([1])->andReturn($bill);// basic transformation:- /** @var Recurrence $recurrence */- $recurrence = Recurrence::find(1);+$transformer = app(RecurrenceTransformer::class);$transformer->setParameters(new ParameterBag);$result = $transformer->transform($recurrence);- $this->assertEquals(1, $result['id']);+ $this->assertEquals($recurrence->id, $result['id']);$this->assertEquals('withdrawal', $result['transaction_type']);$this->assertEquals(true, $result['apply_rules']);- $this->assertEquals(- [- [- 'value' => 'auto-generated',- 'tags' => ['auto-generated'],- 'name' => 'tags',- ],- [- 'name' => 'piggy_bank_id',- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'New camera',- 'value' => '1',- ],- [- 'bill_id' => 1,- 'bill_name' => 'Rent',- 'name' => 'bill_id',- 'value' => '1',-- ],- ]- , $result['meta']- );-- $this->assertEquals($foreignCurrency->code, $result['transactions'][0]['foreign_currency_code']);$this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);diff --git a/tests/Unit/Transformers/TransactionGroupTransformerTest.php b/tests/Unit/Transformers/TransactionGroupTransformerTest.phpnew file mode 100644index 0000000000..6f30836c9c--- /dev/null+++ b/tests/Unit/Transformers/TransactionGroupTransformerTest.php@@ -0,0 +1,120 @@+<?php+/**+ * TransactionGroupTransformerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++namespace Tests\Unit\Transformers;+++use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;+use FireflyIII\Support\NullArrayObject;+use FireflyIII\Transformers\TransactionGroupTransformer;+use Log;+use Mockery;+use Tests\TestCase;++/**+ * Class TransactionGroupTransformerTest+ */+class TransactionGroupTransformerTest extends TestCase+{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }++ /**+ * @covers \FireflyIII\Transformers\TransactionGroupTransformer+ */+ public function testBasic(): void+ {+ $repository = $this->mock(TransactionGroupRepositoryInterface::class);+ $group = $this->getRandomWithdrawalGroup();+ $first = $group->transactionJournals()->first();++ // mock calls+ $repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');+ $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);++ $transformer = new TransactionGroupTransformer;+ $result = $transformer->transformObject($group);++ }++ /**+ * @covers \FireflyIII\Transformers\TransactionGroupTransformer+ */+ public function testArray(): void {+ $repository = $this->mock(TransactionGroupRepositoryInterface::class);+ $group = $this->getRandomWithdrawalGroupAsArray();++ // mock calls+ $repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');+ $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);++ $transformer = new TransactionGroupTransformer;+ $result = $transformer->transform($group);+ }+++ /**+ * @covers \FireflyIII\Transformers\TransactionGroupTransformer+ */+ public function testArrayDeposit(): void {+ $repository = $this->mock(TransactionGroupRepositoryInterface::class);+ $group = $this->getRandomDepositGroupAsArray();++ // mock calls+ $repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');+ $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);++ $transformer = new TransactionGroupTransformer;+ $result = $transformer->transform($group);+ }++ /**+ * @covers \FireflyIII\Transformers\TransactionGroupTransformer+ */+ public function testDeposit(): void+ {+ $repository = $this->mock(TransactionGroupRepositoryInterface::class);+ $group = $this->getRandomDepositGroup();+ $first = $group->transactionJournals()->first();++ // mock calls+ $repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();+ $repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');+ $repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);++ $transformer = new TransactionGroupTransformer;+ $result = $transformer->transformObject($group);++ }+}\ No newline at end of file