From 60339a0f6a0b3d0f49d2863dcf0f12032ef0090e Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 2 Mar 2018 17:29:47 +0100 Subject: [PATCH] make sure randomly selected journals match prerequisites. --- .../Controllers/TransactionControllerTest.php | 17 +++++++++++++---- .../Triggers/HasAttachmentTest.php | 12 +++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php index 2da89ce3e6..1864e3b3e6 100644 --- a/tests/Api/V1/Controllers/TransactionControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionControllerTest.php @@ -1321,10 +1321,15 @@ class TransactionControllerTest extends TestCase */ public function testShowDeposit() { - /** @var TransactionJournal $journal */ - $journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first(); + do { + // this is kind of cheating but OK. + /** @var TransactionJournal $journal */ + $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->whereNull('deleted_at')->first(); + $count = $journal->transactions()->count(); + } while ($count !== 2); $transaction = $journal->transactions()->first(); + $accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('getAccountsByType') @@ -1381,8 +1386,12 @@ class TransactionControllerTest extends TestCase */ public function testShowWithdrawal() { - /** @var TransactionJournal $journal */ - $journal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first(); + do { + // this is kind of cheating but OK. + /** @var TransactionJournal $journal */ + $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first(); + $count = $journal->transactions()->count(); + } while ($count !== 2); $transaction = $journal->transactions()->first(); $accountRepos = $this->mock(AccountRepositoryInterface::class); diff --git a/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php b/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php index dff4206d7c..5fa574641c 100644 --- a/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php +++ b/tests/Unit/TransactionRules/Triggers/HasAttachmentTest.php @@ -36,12 +36,11 @@ class HasAttachmentTest extends TestCase */ public function testTriggered() { - $count = 0; - while($count === 0) { + do { // this is kind of cheating but OK. $journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $count = $journal->attachments()->count(); - } + } while($count !== 0); $attachment = $journal->user->attachments()->first(); $journal->attachments()->save($attachment); @@ -57,12 +56,11 @@ class HasAttachmentTest extends TestCase */ public function testTriggeredFalse() { - $count = 0; - while ($count === 0) { + do { // this is kind of cheating but OK. $journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); - $count = $journal->attachments()->count(); - } + $count = $journal->attachments()->count(); + } while($count !== 0); $this->assertEquals(0, $journal->attachments()->count());