. */ declare(strict_types=1); namespace Tests\Unit\TransactionRules\Triggers; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\TransactionRules\Triggers\ToAccountStarts; use Illuminate\Support\Collection; use Tests\TestCase; /** * Class ToAccountStartsTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class ToAccountStartsTest extends TestCase { /** * Set up test */ public function setUp(): void { self::markTestIncomplete('Incomplete for refactor.'); return; } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ public function testTriggered(): void { $repository = $this->mock(JournalRepositoryInterface::class); /** @var TransactionJournal $journal */ $journal = $this->user()->transactionJournals()->inRandomOrder()->first(); $account = $this->user()->accounts()->inRandomOrder()->first(); $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account); $trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false); $result = $trigger->triggered($journal); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ public function testTriggeredLonger(): void { $repository = $this->mock(JournalRepositoryInterface::class); /** @var TransactionJournal $journal */ $journal = $this->user()->transactionJournals()->inRandomOrder()->first(); $account = $this->user()->accounts()->inRandomOrder()->first(); $repository->shouldReceive('getDestinationAccount')->once()->andReturn($account); $trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false); $result = $trigger->triggered($journal); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ 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('getDestinationAccount')->once()->andReturn($account); $trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false); $result = $trigger->triggered($journal); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ public function testWillMatchEverythingEmpty(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = ''; $result = ToAccountStarts::willMatchEverything($value); $this->assertTrue($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ public function testWillMatchEverythingNotNull(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = 'x'; $result = ToAccountStarts::willMatchEverything($value); $this->assertFalse($result); } /** * @covers \FireflyIII\TransactionRules\Triggers\ToAccountStarts */ public function testWillMatchEverythingNull(): void { $repository = $this->mock(JournalRepositoryInterface::class); $value = null; $result = ToAccountStarts::willMatchEverything($value); $this->assertTrue($result); } }