Skip to content

Firefly III: a personal finances manager

New tests.

James Cole83ec60254c44
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index a49478d8b5..c60cf458f4 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -25,7 +25,7 @@ class AccountController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index 9d6934277a..67e88779a8 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -26,7 +26,7 @@ class BillController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index f84e19d2e4..45bd8a2a44 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -27,7 +27,7 @@ class BudgetController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 866ff6a4d0..28f4f17bf5 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -26,7 +26,7 @@ class CategoryController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/PiggyBankController.php b/app/Http/Controllers/Chart/PiggyBankController.php
index 22e2a0790e..e73437bd21 100644
--- a/app/Http/Controllers/Chart/PiggyBankController.php
+++ b/app/Http/Controllers/Chart/PiggyBankController.php
@@ -23,7 +23,7 @@ class PiggyBankController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index 7e1b435e8d..4026d222ae 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -23,7 +23,7 @@ class ReportController extends Controller
protected $generator;
/**
- *
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/tests/helpers/ConnectJournalToPiggyBankTest.php b/tests/helpers/ConnectJournalToPiggyBankTest.php
index c580db3fce..09967aa788 100644
--- a/tests/helpers/ConnectJournalToPiggyBankTest.php
+++ b/tests/helpers/ConnectJournalToPiggyBankTest.php
@@ -88,74 +88,22 @@ class ConnectJournalToPiggyBankTest extends TestCase
}
/**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
*/
public function testWithRepetition()
{
- FactoryMuffin::create('FireflyIII\Models\TransactionType');
- FactoryMuffin::create('FireflyIII\Models\TransactionType');
-
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
- $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
- $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
- $account1 = FactoryMuffin::create('FireflyIII\Models\Account');
- $account2 = FactoryMuffin::create('FireflyIII\Models\Account');
- $account1->user_id = $user->id;
- $account2->user_id = $user->id;
- $piggyBank->account_id = $account1->id;
- $account1->save();
- $account2->save();
- $piggyBank->save();
-
- $start = clone $journal->date;
- $end = clone $journal->date;
- $start->subDay();
- $end->addDay();
-
- PiggyBankRepetition::create(
- [
- 'piggy_bank_id' => $piggyBank->id,
- 'startdate' => $start->format('Y-m-d'),
- 'targetdate' => $end->format('Y-m-d'),
- 'currentamount' => 0,
- ]
- );
+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
+ $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
- $event = new JournalCreated($journal, $piggyBank->id);
- $class = new ConnectJournalToPiggyBank();
- $result = $class->handle($event);
-
-
- $this->assertTrue($result);
- $this->assertCount(1, $piggyBank->piggyBankEvents()->get());
- }
-
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
- */
- public function testWithRepetitionReversed()
- {
- FactoryMuffin::create('FireflyIII\Models\TransactionType');
- FactoryMuffin::create('FireflyIII\Models\TransactionType');
-
- $user = FactoryMuffin::create('FireflyIII\User');
- $this->be($user);
-
- $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
- $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
- $account1 = FactoryMuffin::create('FireflyIII\Models\Account');
- $account2 = FactoryMuffin::create('FireflyIII\Models\Account');
- $account1->user_id = $user->id;
- $account2->user_id = $user->id;
- $piggyBank->account_id = $account1->id;
- $account1->save();
- $account2->save();
- $piggyBank->save();
+ $journal->user_id = $user->id;
+ $journal->save();
+ // create piggy bank event to continue handler:
$start = clone $journal->date;
$end = clone $journal->date;
$start->subDay();
@@ -170,13 +118,22 @@ class ConnectJournalToPiggyBankTest extends TestCase
]
);
+
+ /** @var Transaction $transaction */
+ foreach ($journal->transactions()->get() as $transaction) {
+ if ($transaction->amount < 0) {
+ $piggyBank->account_id = $transaction->account_id;
+ $account = $transaction->account;
+ $account->user_id = $user->id;
+ $account->save();
+ $piggyBank->account_id = $account->id;
+ $piggyBank->save();
+ }
+ }
$event = new JournalCreated($journal, $piggyBank->id);
$class = new ConnectJournalToPiggyBank();
$result = $class->handle($event);
-
$this->assertTrue($result);
- $this->assertCount(1, $piggyBank->piggyBankEvents()->get());
}
-
}