Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix some tests.
James Cole3e22c9860e14
diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.phpindex 9f549dbfe7..8001c5e80a 100644--- a/app/Http/Requests/SplitJournalFormRequest.php+++ b/app/Http/Requests/SplitJournalFormRequest.php@@ -65,10 +65,10 @@ class SplitJournalFormRequest extends Requestswitch ($data['type']) {case 'withdrawal':$sourceId = $this->integer('journal_source_account_id');- $destinationName = $transaction['destination_name'];+ $destinationName = $transaction['destination_name'] ?? '';break;case 'deposit':- $sourceName = $transaction['source_name'];+ $sourceName = $transaction['source_name'] ?? '';$destinationId = $this->integer('journal_destination_account_id');break;case 'transfer':diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.phpindex d8a3fda122..64ad4b7f0b 100644--- a/app/Transformers/AccountTransformer.php+++ b/app/Transformers/AccountTransformer.php@@ -150,7 +150,7 @@ class AccountTransformer extends TransformerAbstractif (strlen($role) === 0 || $type !== AccountType::ASSET) {$role = null;}- $currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');+ $currencyId = intval($this->repository->getMetaValue($account, 'currency_id'));$currencyCode = null;$decimalPlaces = 2;if ($currencyId > 0) {@@ -197,7 +197,7 @@ class AccountTransformer extends TransformerAbstract'currency_code' => $currencyCode,'current_balance' => round(app('steam')->balance($account, $date), $decimalPlaces),'current_balance_date' => $date->format('Y-m-d'),- 'notes' => $this->repository->getNote($account),+ 'notes' => $this->repository->getNoteText($account),'monthly_payment_date' => $monthlyPaymentDate,'credit_card_type' => $creditCardType,'account_number' => $this->repository->getMetaValue($account, 'accountNumber'),diff --git a/tests/Unit/Transformers/AccountTransformerTest.php b/tests/Unit/Transformers/AccountTransformerTest.phpindex 6282f23aee..d87b6778be 100644--- a/tests/Unit/Transformers/AccountTransformerTest.php+++ b/tests/Unit/Transformers/AccountTransformerTest.php@@ -31,6 +31,7 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Transformers\AccountTransformer;+use Mockery;use Symfony\Component\HttpFoundation\ParameterBag;use Tests\TestCase;@@ -50,7 +51,9 @@ class AccountTransformerTest extends TestCase$accountRepos->shouldReceive('setUser');$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNoteText')->andReturn('');+// make new account:$account = Account::create([@@ -86,7 +89,8 @@ class AccountTransformerTest extends TestCase$accountRepos->shouldReceive('setUser');$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNoteText')->andReturn('');// make new account:$account = Account::create([@@ -119,12 +123,6 @@ class AccountTransformerTest extends TestCase*/public function testCCDataAsset(){- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $accountRepos->shouldReceive('setUser');- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');- $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);- $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);-// make new account:$account = Account::create([@@ -137,14 +135,6 @@ class AccountTransformerTest extends TestCase'encrypted' => 0,]);- // add currency preference:- AccountMeta::create(- [- 'account_id' => $account->id,- 'name' => 'currency_id',- 'data' => 1, // euro- ]- );// add a note:$note = Note::create(@@ -156,6 +146,27 @@ class AccountTransformerTest extends TestCase]);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $accountRepos->shouldReceive('setUser');+ $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');+ $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('2018-02-01');+ $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');+ $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('monthlyFull');+ $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');+ $accountRepos->shouldReceive('getNoteText')->andReturn($note->text);+ $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);+ $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);++ // add currency preference:+ AccountMeta::create(+ [+ 'account_id' => $account->id,+ 'name' => 'currency_id',+ 'data' => 1, // euro+ ]+ );++// add credit card meta data (will be ignored)AccountMeta::create([@@ -202,9 +213,6 @@ class AccountTransformerTest extends TestCase*/public function testIgnoreCCExpense(){- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $accountRepos->shouldReceive('setUser');- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');// make new account:$account = Account::create(@@ -218,15 +226,6 @@ class AccountTransformerTest extends TestCase'encrypted' => 0,]);- // add currency preference:- AccountMeta::create(- [- 'account_id' => $account->id,- 'name' => 'currency_id',- 'data' => 1, // euro- ]- );-// add a note:$note = Note::create([@@ -237,6 +236,22 @@ class AccountTransformerTest extends TestCase]);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $accountRepos->shouldReceive('setUser');+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNoteText')->andReturn($note->text);+++ // add currency preference:+ AccountMeta::create(+ [+ 'account_id' => $account->id,+ 'name' => 'currency_id',+ 'data' => 1, // euro+ ]+ );++// add credit card meta data (will be ignored)AccountMeta::create([@@ -287,7 +302,8 @@ class AccountTransformerTest extends TestCase$accountRepos->shouldReceive('setUser');$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn('45.67');$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNoteText')->andReturn('');// make new account:$account = Account::create([@@ -344,7 +360,8 @@ class AccountTransformerTest extends TestCase$accountRepos->shouldReceive('setUser');$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNote')->andReturn('');// make new account:$account = Account::create([@@ -384,11 +401,6 @@ class AccountTransformerTest extends TestCase*/public function testWithNotes(){- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $accountRepos->shouldReceive('setUser');- $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);- $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);- $accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');// make new account:$account = Account::create([@@ -401,15 +413,6 @@ class AccountTransformerTest extends TestCase'encrypted' => 0,]);- // add currency preference:- AccountMeta::create(- [- 'account_id' => $account->id,- 'name' => 'currency_id',- 'data' => 1, // euro- ]- );-// add a note:$note = Note::create([@@ -420,6 +423,23 @@ class AccountTransformerTest extends TestCase]);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $accountRepos->shouldReceive('setUser');+ $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);+ $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);+ $accountRepos->shouldReceive('getMetaValue')->andReturn('1');+ $accountRepos->shouldReceive('getNoteText')->andReturn($note->text);++ // add currency preference:+ AccountMeta::create(+ [+ 'account_id' => $account->id,+ 'name' => 'currency_id',+ 'data' => 1, // euro+ ]+ );++$transformer = new AccountTransformer(new ParameterBag);$result = $transformer->transform($account);