Skip to content

Firefly III: a personal finances manager

Fix and expand tests for #2723

James Colefc8400cdf9fb
diff --git a/app/TransactionRules/Triggers/FromAccountNumberContains.php b/app/TransactionRules/Triggers/FromAccountNumberContains.php
index 6d7a7d27c7..8c6dcadfdb 100644
--- a/app/TransactionRules/Triggers/FromAccountNumberContains.php
+++ b/app/TransactionRules/Triggers/FromAccountNumberContains.php
@@ -74,14 +74,14 @@ final class FromAccountNumberContains extends AbstractTrigger implements Trigger
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$source = $repository->getSourceAccount($journal);
- $strpos1 = stripos($source->iban, $this->triggerValue);
+ $strpos1 = stripos((string)$source->iban, $this->triggerValue);
$strpos2 = stripos($source->account_number, $this->triggerValue);
if (!(false === $strpos1) || !(false === $strpos2)) {
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" or "%s" contains "%s", return true.',
- get_class($this), $journal->id, $source->iban, $source->account_number, $this->triggerValue
+ get_class($this), $journal->id, (string)$source->iban, $source->account_number, $this->triggerValue
)
);
@@ -91,7 +91,7 @@ final class FromAccountNumberContains extends AbstractTrigger implements Trigger
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" and "%s" does not contain "%s", return false.',
- get_class($this), $journal->id, $source->iban, $source->account_number, $this->triggerValue
+ get_class($this), $journal->id, (string)$source->iban, $source->account_number, $this->triggerValue
)
);
diff --git a/app/TransactionRules/Triggers/FromAccountNumberEnds.php b/app/TransactionRules/Triggers/FromAccountNumberEnds.php
index 2228c9fad4..98104ce315 100644
--- a/app/TransactionRules/Triggers/FromAccountNumberEnds.php
+++ b/app/TransactionRules/Triggers/FromAccountNumberEnds.php
@@ -77,7 +77,7 @@ final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInte
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);
- $part1 = substr($source->iban, $searchLength * -1);
+ $part1 = substr((string)$source->iban, $searchLength * -1);
$part2 = substr($source->account_number, $searchLength * -1);
if (strtolower($part1) === $search
diff --git a/app/TransactionRules/Triggers/FromAccountNumberIs.php b/app/TransactionRules/Triggers/FromAccountNumberIs.php
index 71970341a8..edd2ffb9f4 100644
--- a/app/TransactionRules/Triggers/FromAccountNumberIs.php
+++ b/app/TransactionRules/Triggers/FromAccountNumberIs.php
@@ -76,11 +76,11 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
$source = $repository->getSourceAccount($journal);
$search = strtolower($this->triggerValue);
- if (strtolower($source->iban) === $search || strtolower($source->account_number) === $search) {
+ if (strtolower((string)$source->iban) === $search || strtolower($source->account_number) === $search) {
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
- get_class($this), $source->iban, $source->account_number, $search
+ get_class($this), (string)$source->iban, $source->account_number, $search
)
);
@@ -90,7 +90,7 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" and "%s" are NOT "%s", return false.',
- get_class($this), $journal->id, $source->iban, $source->account_number, $search
+ get_class($this), $journal->id, (string)$source->iban, $source->account_number, $search
)
);
diff --git a/app/TransactionRules/Triggers/FromAccountNumberStarts.php b/app/TransactionRules/Triggers/FromAccountNumberStarts.php
index e9fcabdd8c..7a2f16ec2f 100644
--- a/app/TransactionRules/Triggers/FromAccountNumberStarts.php
+++ b/app/TransactionRules/Triggers/FromAccountNumberStarts.php
@@ -75,7 +75,7 @@ final class FromAccountNumberStarts extends AbstractTrigger implements TriggerIn
$repository = app(JournalRepositoryInterface::class);
$source = $repository->getSourceAccount($journal);
$search = strtolower($this->triggerValue);
- $part1 = strtolower(substr($source->iban, 0, strlen($search)));
+ $part1 = strtolower(substr((string)$source->iban, 0, strlen($search)));
$part2 = strtolower(substr($source->account_number, 0, strlen($search)));
if ($part1 === $search || $part2 === $search) {
diff --git a/app/TransactionRules/Triggers/FromAccountStarts.php b/app/TransactionRules/Triggers/FromAccountStarts.php
index 00f75d25e1..143c495784 100644
--- a/app/TransactionRules/Triggers/FromAccountStarts.php
+++ b/app/TransactionRules/Triggers/FromAccountStarts.php
@@ -75,7 +75,7 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
$repository = app(JournalRepositoryInterface::class);
$source = $repository->getSourceAccount($journal);
$search = strtolower($this->triggerValue);
- $part = substr($source->name, 0, strlen($search));
+ $part = strtolower(substr($source->name, 0, strlen($search)));
if ($part === $search) {
Log::debug(
diff --git a/app/TransactionRules/Triggers/ToAccountNumberContains.php b/app/TransactionRules/Triggers/ToAccountNumberContains.php
index 0099c5dcce..31426d02d2 100644
--- a/app/TransactionRules/Triggers/ToAccountNumberContains.php
+++ b/app/TransactionRules/Triggers/ToAccountNumberContains.php
@@ -74,14 +74,14 @@ final class ToAccountNumberContains extends AbstractTrigger implements TriggerIn
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$dest = $repository->getDestinationAccount($journal);
- $strpos1 = stripos($dest->iban, $this->triggerValue);
+ $strpos1 = stripos((string)$dest->iban, $this->triggerValue);
$strpos2 = stripos($dest->account_number, $this->triggerValue);
if (!(false === $strpos1) || !(false === $strpos2)) {
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" or "%s" contains "%s", return true.',
- get_class($this), $journal->id, $dest->iban, $dest->account_number, $this->triggerValue
+ get_class($this), $journal->id, (string)$dest->iban, $dest->account_number, $this->triggerValue
)
);
@@ -91,7 +91,7 @@ final class ToAccountNumberContains extends AbstractTrigger implements TriggerIn
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" and "%s" does not contain "%s", return false.',
- get_class($this), $journal->id, $dest->iban, $dest->account_number, $this->triggerValue
+ get_class($this), $journal->id, (string)$dest->iban, $dest->account_number, $this->triggerValue
)
);
diff --git a/app/TransactionRules/Triggers/ToAccountNumberEnds.php b/app/TransactionRules/Triggers/ToAccountNumberEnds.php
index 8e20d8ecfe..3bbb3841d6 100644
--- a/app/TransactionRules/Triggers/ToAccountNumberEnds.php
+++ b/app/TransactionRules/Triggers/ToAccountNumberEnds.php
@@ -77,7 +77,7 @@ final class ToAccountNumberEnds extends AbstractTrigger implements TriggerInterf
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);
- $part1 = substr($dest->iban, $searchLength * -1);
+ $part1 = substr((string)$dest->iban, $searchLength * -1);
$part2 = substr($dest->account_number, $searchLength * -1);
if (strtolower($part1) === $search
diff --git a/app/TransactionRules/Triggers/ToAccountNumberIs.php b/app/TransactionRules/Triggers/ToAccountNumberIs.php
index 0fc44eabc7..48091d490c 100644
--- a/app/TransactionRules/Triggers/ToAccountNumberIs.php
+++ b/app/TransactionRules/Triggers/ToAccountNumberIs.php
@@ -76,11 +76,11 @@ final class ToAccountNumberIs extends AbstractTrigger implements TriggerInterfac
$dest = $repository->getDestinationAccount($journal);
$search = strtolower($this->triggerValue);
- if (strtolower($dest->iban) === $search || strtolower($dest->account_number) === $search) {
+ if (strtolower((string)$dest->iban) === $search || strtolower($dest->account_number) === $search) {
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
- get_class($this), $dest->iban, $dest->account_number, $search
+ get_class($this), (string)$dest->iban, $dest->account_number, $search
)
);
@@ -90,7 +90,7 @@ final class ToAccountNumberIs extends AbstractTrigger implements TriggerInterfac
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" and "%s" are NOT "%s", return false.',
- get_class($this), $journal->id, $dest->iban, $dest->account_number, $search
+ get_class($this), $journal->id, (string)$dest->iban, $dest->account_number, $search
)
);
diff --git a/app/TransactionRules/Triggers/ToAccountNumberStarts.php b/app/TransactionRules/Triggers/ToAccountNumberStarts.php
index 618552c9ab..3f9d65d075 100644
--- a/app/TransactionRules/Triggers/ToAccountNumberStarts.php
+++ b/app/TransactionRules/Triggers/ToAccountNumberStarts.php
@@ -75,7 +75,7 @@ final class ToAccountNumberStarts extends AbstractTrigger implements TriggerInte
$repository = app(JournalRepositoryInterface::class);
$dest = $repository->getDestinationAccount($journal);
$search = strtolower($this->triggerValue);
- $part1 = strtolower(substr($dest->iban, 0, strlen($search)));
+ $part1 = strtolower(substr((string)$dest->iban, 0, strlen($search)));
$part2 = strtolower(substr($dest->account_number, 0, strlen($search)));
if ($part1 === $search || $part2 === $search) {
diff --git a/app/TransactionRules/Triggers/ToAccountStarts.php b/app/TransactionRules/Triggers/ToAccountStarts.php
index a96c321239..0a76fde8be 100644
--- a/app/TransactionRules/Triggers/ToAccountStarts.php
+++ b/app/TransactionRules/Triggers/ToAccountStarts.php
@@ -76,7 +76,7 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
$repository = app(JournalRepositoryInterface::class);
$dest = $repository->getDestinationAccount($journal);
$search = strtolower($this->triggerValue);
- $part = substr($dest->name, 0, strlen($search));
+ $part = strtolower(substr($dest->name, 0, strlen($search)));
if ($part === $search) {
Log::debug(
diff --git a/tests/Unit/Support/NavigationTest.php b/tests/Unit/Support/NavigationTest.php
index b290f45b89..a8f01fddfb 100644
--- a/tests/Unit/Support/NavigationTest.php
+++ b/tests/Unit/Support/NavigationTest.php
@@ -73,7 +73,7 @@ class NavigationTest extends TestCase
['1M', 0, '2019-01-30', '2019-02-28'], // jump to end of next month.
['1M', 0, '2019-01-31', '2019-02-28'], // jump to end of next month.
['1M', 0, '2019-02-01', '2019-03-01'],
- ['1M', 1, '2019-02-01', '2019-03-31'], // weird but OK.
+ ['1M', 1, '2019-02-01', '2019-04-01'], // fixed
['1M', 2, '2019-01-01', '2019-04-01'],
['quarter', 0, '2019-01-01', '2019-04-01'],
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php
index 2972e6d883..c1dc83cbfd 100644
--- a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php
@@ -46,8 +46,7 @@ class FromAccountContainsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountContains::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
@@ -64,8 +63,7 @@ class FromAccountContainsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php
index 0c547c917b..cf2e3e8695 100644
--- a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php
@@ -45,8 +45,7 @@ class FromAccountEndsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
@@ -63,8 +62,7 @@ class FromAccountEndsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -81,8 +79,7 @@ class FromAccountEndsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountEnds::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php
index bc31f8b5bb..143e7ad154 100644
--- a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php
@@ -46,8 +46,7 @@ class FromAccountIsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountIs::makeFromStrings($account->name, false);
@@ -65,8 +64,7 @@ class FromAccountIsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php
new file mode 100644
index 0000000000..20147a6652
--- /dev/null
+++ b/tests/Unit/TransactionRules/Triggers/FromAccountNumberContainsTest.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * FromAccountNumberContainsTest.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+declare(strict_types=1);
+
+namespace Tests\Unit\TransactionRules\Triggers;
+
+use FireflyIII\Models\AccountMeta;
+use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\TransactionRules\Triggers\FromAccountNumberContains;
+use Tests\TestCase;
+
+/**
+ * Class FromAccountNumberContainsTest
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ * @SuppressWarnings(PHPMD.TooManyPublicMethods)
+ */
+class FromAccountNumberContainsTest extends TestCase
+{
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testTriggeredBoth(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+
+ /** @var TransactionJournal $journal */
+ $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+
+ $account->iban = 'FR7620041010053537027625181';
+ $account->save();
+ $meta = new AccountMeta;
+ $meta->account_id = $account->id;
+ $meta->name = 'account_number';
+ $meta->data= '7027625181';
+ $meta->save();
+
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
+
+ $trigger = FromAccountNumberContains::makeFromStrings('7027', false);
+ $result = $trigger->triggered($journal);
+ $this->assertTrue($result);
+
+ $meta->forceDelete();
+
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testTriggeredIban(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+
+ /** @var TransactionJournal $journal */
+ $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $account->iban = 'FR7620041010053537027625181';
+ $account->save();
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
+
+ $trigger = FromAccountNumberContains::makeFromStrings('7027', false);
+ $result = $trigger->triggered($journal);
+ $this->assertTrue($result);
+
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testTriggeredNot(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+
+ /** @var TransactionJournal $journal */
+ $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
+
+ $trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
+ $result = $trigger->triggered($journal);
+ $this->assertFalse($result);
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testTriggeredNumber(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+
+ /** @var TransactionJournal $journal */
+ $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
+
+ $meta = new AccountMeta;
+ $meta->account_id = $account->id;
+ $meta->name = 'account_number';
+ $meta->data= '7027625181';
+ $meta->save();
+
+ $trigger = FromAccountNumberContains::makeFromStrings('276251', false);
+ $result = $trigger->triggered($journal);
+ $this->assertTrue($result);
+ $meta->forceDelete();
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testWillMatchEverythingEmpty(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $value = '';
+ $result = FromAccountContains::willMatchEverything($value);
+ $this->assertTrue($result);
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testWillMatchEverythingNotNull(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $value = 'x';
+ $result = FromAccountContains::willMatchEverything($value);
+ $this->assertFalse($result);
+ }
+
+ /**
+ * @covers \FireflyIII\TransactionRules\Triggers\FromAccountContains
+ */
+ public function testWillMatchEverythingNull(): void
+ {
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $value = null;
+ $result = FromAccountContains::willMatchEverything($value);
+ $this->assertTrue($result);
+ }
+}
diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php
index 85ff8f55be..81081a2ee2 100644
--- a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php
@@ -57,8 +57,7 @@ class FromAccountStartsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
$result = $trigger->triggered($journal);
@@ -76,8 +75,7 @@ class FromAccountStartsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -95,8 +93,7 @@ class FromAccountStartsTest extends TestCase
/** @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);
+ $repository->shouldReceive('getSourceAccount')->once()->andReturn($account);
$trigger = FromAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php
index cee8af3b48..a344170b37 100644
--- a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php
@@ -46,8 +46,7 @@ class ToAccountContainsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountContains::makeFromStrings($account->name, false);
@@ -65,8 +64,7 @@ class ToAccountContainsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php
index 18cf4e78dc..05448e1190 100644
--- a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php
@@ -46,8 +46,7 @@ class ToAccountEndsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
@@ -64,8 +63,7 @@ class ToAccountEndsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -82,8 +80,7 @@ class ToAccountEndsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountEnds::makeFromStrings((string)$this->randomInt(), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php
index 0f28c9dbc2..fc6878e0bc 100644
--- a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php
@@ -46,8 +46,7 @@ class ToAccountIsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountIs::makeFromStrings($account->name, false);
@@ -65,8 +64,7 @@ class ToAccountIsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);
diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php
index b3d21bfd4a..7b28478b45 100644
--- a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php
+++ b/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php
@@ -46,8 +46,7 @@ class ToAccountStartsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
@@ -65,8 +64,7 @@ class ToAccountStartsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -83,8 +81,7 @@ class ToAccountStartsTest extends TestCase
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
- $collection = new Collection([$account]);
- $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
+ $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account);
$trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);