mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
New tests.
This commit is contained in:
@@ -25,7 +25,7 @@ class AccountController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -26,7 +26,7 @@ class BillController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -27,7 +27,7 @@ class BudgetController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -26,7 +26,7 @@ class CategoryController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -23,7 +23,7 @@ class PiggyBankController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -23,7 +23,7 @@ class ReportController extends Controller
|
|||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -88,28 +88,22 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
|
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
|
||||||
*/
|
*/
|
||||||
public function testWithRepetition()
|
public function testWithRepetition()
|
||||||
{
|
{
|
||||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
||||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
||||||
|
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->be($user);
|
$this->be($user);
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
|
||||||
|
|
||||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
$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;
|
$start = clone $journal->date;
|
||||||
$end = clone $journal->date;
|
$end = clone $journal->date;
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
@@ -124,59 +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);
|
$event = new JournalCreated($journal, $piggyBank->id);
|
||||||
$class = new ConnectJournalToPiggyBank();
|
$class = new ConnectJournalToPiggyBank();
|
||||||
$result = $class->handle($event);
|
$result = $class->handle($event);
|
||||||
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$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();
|
|
||||||
|
|
||||||
$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,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$event = new JournalCreated($journal, $piggyBank->id);
|
|
||||||
$class = new ConnectJournalToPiggyBank();
|
|
||||||
$result = $class->handle($event);
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertCount(1, $piggyBank->piggyBankEvents()->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user