Improve test filter.

This commit is contained in:
James Cole
2018-07-01 16:13:22 +02:00
parent b0b9055e2e
commit 5676aeac80

View File

@@ -36,13 +36,15 @@ class ToAccountIsTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$count = 0; $count = 0;
$transactionCount = 0;
do { do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first(); $transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account; $transactionCount = $journal->transactions()->count();
$account = $transaction->account;
$count++; $count++;
} while ($account === null && $count < 30); } while ($account === null && $count < 30 && $transactionCount !== 2);
$trigger = ToAccountIs::makeFromStrings($account->name, false); $trigger = ToAccountIs::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
@@ -54,13 +56,15 @@ class ToAccountIsTest extends TestCase
*/ */
public function testTriggeredNot(): void public function testTriggeredNot(): void
{ {
$count = 0; $count = 0;
$transactionCount = 0;
do { do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first(); $transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account; $transactionCount = $journal->transactions()->count();
$account = $transaction->account;
$count++; $count++;
} while ($account === null && $count < 30); } while ($account === null && $count < 30 && $transactionCount !== 2);
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false); $trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);