. */ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Triggers\FromAccountIs; use Illuminate\Support\Collection; use Tests\TestCase; /** * Class FromAccountIsTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class FromAccountIsTest extends TestCase { /** * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs */ public function testTriggered(): void { $repository = $this->mock(JournalRepositoryInterface::class); /** @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 = FromAccountIs::makeFromStrings($account->name, false); $result = $trigger->triggered($journal); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs */ public function testTriggeredNot(): void { $repository = $this->mock(JournalRepositoryInterface::class); /** @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 = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false); $result = $trigger->triggered($journal); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs */ public function testWillMatchEverythingEmpty(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = ''; $result = FromAccountIs::willMatchEverything($value); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs */ public function testWillMatchEverythingNotNull(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = 'x'; $result = FromAccountIs::willMatchEverything($value); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\FromAccountIs */ public function testWillMatchEverythingNull(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = null; $result = FromAccountIs::willMatchEverything($value); $this->assertTrue($result); } }