Fix unit tests.

This commit is contained in:
James Cole
2018-07-05 19:02:22 +02:00
parent 666e9897ea
commit 146c9fd947
2 changed files with 12 additions and 6 deletions

View File

@@ -37,7 +37,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredBudget(): void
{
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@@ -54,7 +54,7 @@ class HasNoBudgetTest extends TestCase
public function testTriggeredNoBudget(): void
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$journal->budgets()->detach();
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
@@ -72,8 +72,12 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$loopCount = 0;
do {
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($loopCount < 30 && $count !== 2);
$transactions = $journal->transactions()->get();
$budget = $journal->user->budgets()->first();