Various bugfixes and code clean up.

This commit is contained in:
James Cole
2018-07-27 04:46:21 +02:00
parent 2ad8e7f343
commit 0312ba8ad7
60 changed files with 223 additions and 353 deletions

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\FromAccountContains;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
@@ -38,13 +39,12 @@ class FromAccountContainsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '<', 0)->count();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
}
$account = $transaction->account;
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
$collection = new Collection([$account]);
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
$trigger = FromAccountContains::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
@@ -57,7 +57,12 @@ class FromAccountContainsTest extends TestCase
public function testTriggeredNot(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
$collection = new Collection([$account]);
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
$trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
@@ -70,8 +75,8 @@ class FromAccountContainsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = FromAccountContains::willMatchEverything($value);
$value = '';
$result = FromAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -81,8 +86,8 @@ class FromAccountContainsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = FromAccountContains::willMatchEverything($value);
$value = 'x';
$result = FromAccountContains::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -92,8 +97,8 @@ class FromAccountContainsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = FromAccountContains::willMatchEverything($value);
$value = null;
$result = FromAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
}