Improve test coverage.

This commit is contained in:
James Cole
2018-09-02 20:13:25 +02:00
parent 96dd89fbeb
commit de754ca4e0
31 changed files with 861 additions and 385 deletions

View File

@@ -36,18 +36,14 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$withdrawal = $this->getRandomWithdrawal();
$category = $withdrawal->user->categories()->first();
$withdrawal->categories()->detach();
$withdrawal->categories()->save($category);
$this->assertEquals(1, $withdrawal->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}
@@ -56,19 +52,15 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredNotJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$category = $journal->user->categories()->first();
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$withdrawal = $this->getRandomWithdrawal();
$category = $withdrawal->user->categories()->first();
$otherCategory = $withdrawal->user->categories()->where('id', '!=', $category->id)->first();
$withdrawal->categories()->detach();
$withdrawal->categories()->save($category);
$this->assertEquals(1, $withdrawal->categories()->count());
$trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}
@@ -77,22 +69,18 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$withdrawal = $this->getRandomWithdrawal();
$transaction = $withdrawal->transactions()->first();
$category = $withdrawal->user->categories()->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$withdrawal->categories()->detach();
$transaction->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(0, $withdrawal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}