Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some new tests and a bug fix for piggy banks.
James Cole5160f2c29896
diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.phpindex 701daa11c7..cc75dca89f 100644--- a/app/Handlers/Events/ConnectJournalToPiggyBank.php+++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php@@ -51,9 +51,15 @@ class ConnectJournalToPiggyBankif (is_null($repetition)) {return false;}-- $amount = $journal->correct_amount;bcscale(2);++ $amount = $journal->actual_amount;+ // if piggy account matches source account, the amount is positive+ if ($piggyBank->account_id == $journal->source_account->id) {+ $amount = $amount * -1;+ }++$repetition->currentamount = bcadd($repetition->currentamount, $amount);$repetition->save();diff --git a/app/User.php b/app/User.phpindex ea86714ca0..4b05eab202 100644--- a/app/User.php+++ b/app/User.php@@ -9,6 +9,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait;/*** Class User+ * @codeCoverageIgnore** @package FireflyIII* @property integer $iddiff --git a/tests/controllers/HomeControllerTest.php b/tests/controllers/HomeControllerTest.phpindex c4872d64bb..deb442fbd0 100644--- a/tests/controllers/HomeControllerTest.php+++ b/tests/controllers/HomeControllerTest.php@@ -73,6 +73,11 @@ class HomeControllerTest extends TestCase$user = FactoryMuffin::create('FireflyIII\User');$this->be($user);+ // create at least one tag:+ $tag = FactoryMuffin::create('FireflyIII\Models\Tag');+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $journal->tags()->save($tag);+$this->call('GET', '/flush');$this->assertResponseStatus(302);diff --git a/tests/controllers/TransactionControllerTest.php b/tests/controllers/TransactionControllerTest.phpindex 30aa7b08f5..c0a0787734 100644--- a/tests/controllers/TransactionControllerTest.php+++ b/tests/controllers/TransactionControllerTest.php@@ -147,6 +147,98 @@ class TransactionControllerTest extends TestCase$this->assertResponseOk();}+ /**+ * @covers FireflyIII\Http\Controllers\TransactionController::edit+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ */+ public function testEditCashDestination()+ {+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+ // make complete journal:+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ //$expense = FactoryMuffin::create('FireflyIII\Models\Account'); // expense account+ //$revenue = FactoryMuffin::create('FireflyIII\Models\Account'); // revenue account+ $asset = FactoryMuffin::create('FireflyIII\Models\Account'); // asset account+ $cash = FactoryMuffin::create('FireflyIII\Models\Account'); // cash account++ $journal->transactions[0]->account_id = $asset->id;+ $journal->transactions[0]->amount = -300;+ $journal->transactions[0]->save();++ $journal->transactions[0]->account_id = $cash->id;+ $journal->transactions[0]->amount = 300;+ $journal->transactions[0]->save();++ $this->be($journal->user);+ // mock!+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');++ // fake!+ $repository->shouldReceive('getAccounts')->andReturn(new Collection);++ $this->call('GET', '/transaction/edit/' . $journal->id);++ $this->assertResponseOk();+ }++ /**+ * @covers FireflyIII\Http\Controllers\TransactionController::edit+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ */+ public function testEditDeposit()+ {+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+ // make complete journal:+ $accountType = FactoryMuffin::create('FireflyIII\Models\AccountType');+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $account = FactoryMuffin::create('FireflyIII\Models\Account');+ $transaction1 = FactoryMuffin::create('FireflyIII\Models\Transaction');+ $transaction2 = FactoryMuffin::create('FireflyIII\Models\Transaction');++ $accountType->type = 'Asset account';+ $account->account_type_id = $accountType->id;++ $account->save();+ $transaction1->account_id = $account->id;+ $transaction1->transaction_journal_id = $journal->id;+ $transaction1->save();++ $transaction2->account_id = $account->id;+ $transaction2->transaction_journal_id = $journal->id;+ $transaction2->save();++ // also add some tags:+ $tag = FactoryMuffin::create('FireflyIII\Models\Tag');+ $tag->transactionJournals()->save($journal);++ // and a category and a budget:+ $budget = FactoryMuffin::create('FireflyIII\Models\Budget');+ $category = FactoryMuffin::create('FireflyIII\Models\Category');+ $category->transactionJournals()->save($journal);+ $budget->transactionJournals()->save($journal);++ // and a piggy bank event:+ $pbEvent = FactoryMuffin::create('FireflyIII\Models\PiggyBankEvent');+ $pbEvent->transaction_journal_id = $journal->id;+ $pbEvent->save();++ $this->be($journal->user);+++ // mock!+ $repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');+++ // fake!+ $repository->shouldReceive('getAccounts')->andReturn(new Collection);++ $this->call('GET', '/transaction/edit/' . $journal->id);+ $this->assertResponseOk();+ }+/*** @covers FireflyIII\Http\Controllers\TransactionController::index*/@@ -259,7 +351,7 @@ class TransactionControllerTest extends TestCase* @SuppressWarnings(PHPMD.ExcessiveMethodLength)* @covers FireflyIII\Http\Controllers\TransactionController::store*/- public function testStoreCreateAnother()+ public function testStore(){$account = FactoryMuffin::create('FireflyIII\Models\Account');$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');@@ -278,7 +370,6 @@ class TransactionControllerTest extends TestCase'amount_currency_id' => $currency->id,'date' => '2015-05-05','budget_id' => '0',- 'create_another' => '1','category' => '','tags' => 'fat-test','piggy_bank_id' => '0',@@ -304,7 +395,7 @@ class TransactionControllerTest extends TestCase* @SuppressWarnings(PHPMD.ExcessiveMethodLength)* @covers FireflyIII\Http\Controllers\TransactionController::store*/- public function testStore()+ public function testStoreCreateAnother(){$account = FactoryMuffin::create('FireflyIII\Models\Account');$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');@@ -323,6 +414,7 @@ class TransactionControllerTest extends TestCase'amount_currency_id' => $currency->id,'date' => '2015-05-05','budget_id' => '0',+ 'create_another' => '1','category' => '','tags' => 'fat-test','piggy_bank_id' => '0',