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

@@ -74,7 +74,7 @@ class ReportControllerTest extends TestCase
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(500);
$response->assertStatus(200);
}
/**

View File

@@ -58,6 +58,8 @@ class MassControllerTest extends TestCase
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
$withdrawals = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();

View File

@@ -845,6 +845,11 @@ class SingleControllerTest extends TestCase
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);
$attRepos->shouldReceive('saveAttachmentsForModel');

View File

@@ -351,6 +351,9 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.show', [1]));

View File

@@ -57,7 +57,6 @@ class VersionCheckEventHandlerTest extends TestCase
$repos->shouldReceive('hasRole')->andReturn(true)->once();
// report on config variables:
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
@@ -91,7 +90,6 @@ class VersionCheckEventHandlerTest extends TestCase
$version = config('firefly.version');
$first = new Release(['id' => '1', 'title' => $version . '.1', 'updated' => '2017-05-01', 'content' => '']);
// report on config variables:
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
@@ -139,7 +137,6 @@ class VersionCheckEventHandlerTest extends TestCase
$repos->shouldReceive('hasRole')->andReturn(true)->once();
// report on config variables:
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
@@ -164,7 +161,6 @@ class VersionCheckEventHandlerTest extends TestCase
// report on config variables:
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);

View File

@@ -79,8 +79,8 @@ class MetaPieChartTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
$helper = new MetaPieChart();
$helper->setUser($this->user());
@@ -135,8 +135,8 @@ class MetaPieChartTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
$helper = new MetaPieChart();
$helper->setCollectOtherObjects(true);
@@ -190,8 +190,8 @@ class MetaPieChartTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
$helper = new MetaPieChart();
$helper->setUser($this->user());
@@ -245,8 +245,8 @@ class MetaPieChartTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
$helper = new MetaPieChart();
$helper->setCollectOtherObjects(true);

View File

@@ -1,75 +0,0 @@
<?php
/**
* RabobankDescriptionTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\Specifics;
use FireflyIII\Import\Specifics\RabobankDescription;
use Tests\TestCase;
/**
* Class RabobankDescriptionTest
*/
class RabobankDescriptionTest extends TestCase
{
/**
* Default behaviour
* @covers \FireflyIII\Import\Specifics\RabobankDescription
*/
public function testRunBasic(): void
{
$row = ['','','','','','','','','','',''];
$parser = new RabobankDescription;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
/**
* No opposite name or iban
* @covers \FireflyIII\Import\Specifics\RabobankDescription
*/
public function testRunUseDescription(): void
{
$row = ['','','','','','','','','','','Hello'];
$parser = new RabobankDescription;
$result = $parser->run($row);
$this->assertEquals('Hello', $result[6]);
$this->assertEquals('', $result[10]);
}
/**
* Has opposite name or iban
* @covers \FireflyIII\Import\Specifics\RabobankDescription
*/
public function testRunUseFilledIn(): void
{
$row = ['','','','','','ABC','','','','',''];
$parser = new RabobankDescription;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
}

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);
}
}

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
@@ -38,13 +39,11 @@ class FromAccountEndsTest 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 = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
@@ -57,13 +56,12 @@ class FromAccountEndsTest extends TestCase
public function testTriggeredLonger(): 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 = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -76,7 +74,12 @@ class FromAccountEndsTest 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 = FromAccountEnds::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -25,6 +25,7 @@ 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;
use Log;
/**
@@ -38,20 +39,12 @@ class FromAccountIsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
$loops++;
// do this until: account is not null, journal has two transactions, loops is below 30
} while (!(null !== $account && 2 === $count && $loops < 30));
/** @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);
@@ -65,7 +58,12 @@ class FromAccountIsTest 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 = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
@@ -48,26 +49,12 @@ class FromAccountStartsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
Log::debug('In testTriggered()');
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
$name = $account->name ?? '';
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
$loops++;
// do this while the following is untrue:
// 1) account is not null,
// 2) journal has two transactions
// 3) loops is less than 30
// 4) $name is longer than 3
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
/** @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 = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
$result = $trigger->triggered($journal);
@@ -80,26 +67,12 @@ class FromAccountStartsTest extends TestCase
public function testTriggeredLonger(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
Log::debug('In testTriggeredLonger()');
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
$name = $account->name ?? '';
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
$loops++;
// do this while the following is untrue:
// 1) account is not null,
// 2) journal has two transactions
// 3) loops is less than 30
// 4) $name is longer than 3
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
/** @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 = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -112,7 +85,12 @@ class FromAccountStartsTest 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 = FromAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountContains;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**
@@ -39,14 +40,11 @@ class ToAccountContainsTest extends TestCase
{
$repository = $this->mock(JournalRepositoryInterface::class);
$count = 0;
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$transactionCount = $journal->transactions()->count();
$account = null === $transaction ? null : $transaction->account;
$count++;
} while ($account === null && $count < 30 && $transactionCount !== 2);
/** @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);
$trigger = ToAccountContains::makeFromStrings($account->name, false);
@@ -60,14 +58,12 @@ class ToAccountContainsTest extends TestCase
public function testTriggeredNot(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$count = 0;
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$transactionCount = $journal->transactions()->count();
$account = null === $transaction ? null : $transaction->account;
$count++;
} while ($account === null && $count < 30 && $transactionCount !== 2);
/** @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);
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
@@ -39,26 +40,12 @@ class ToAccountEndsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
$name = $account->name ?? '';
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
$loops++;
// do this while the following is untrue:
// 1) account is not null,
// 2) journal has two transactions
// 3) loops is less than 30
// 4) $name is longer than 3
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
/** @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);
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
@@ -71,25 +58,12 @@ class ToAccountEndsTest extends TestCase
public function testTriggeredLonger(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
$name = $account->name ?? '';
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
$loops++;
// do this while the following is untrue:
// 1) account is not null,
// 2) journal has two transactions
// 3) loops is less than 30
// 4) $name is longer than 3
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
/** @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);
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -102,25 +76,12 @@ class ToAccountEndsTest extends TestCase
public function testTriggeredNot(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
$name = $account->name ?? '';
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
$loops++;
// do this while the following is untrue:
// 1) account is not null,
// 2) journal has two transactions
// 3) loops is less than 30
// 4) $name is longer than 3
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
/** @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);
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 1234), false);
$result = $trigger->triggered($journal);

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
@@ -39,20 +40,12 @@ class ToAccountIsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
$loops++;
// do this until: account is not null, journal has two transactions, loops is below 30
} while (!(null !== $account && 2 === $count && $loops < 30));
/** @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);
@@ -67,20 +60,12 @@ class ToAccountIsTest extends TestCase
public function testTriggeredNot(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
$loops++;
// do this until: account is not null, journal has two transactions, loops is below 30
} while (!(null !== $account && 2 === $count && $loops < 30));
/** @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);
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
@@ -39,22 +40,12 @@ class ToAccountStartsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
Log::debug('Now in testTriggered');
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null === $account));
$loops++;
// do this until: account is not null, journal has two transactions, loops is below 30
} while (!(null !== $account && 2 === $count && $loops < 30));
/** @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);
$trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
@@ -68,23 +59,12 @@ class ToAccountStartsTest extends TestCase
public function testTriggeredLonger(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
Log::debug('Now in testTriggeredLonger');
$loops = 0; // FINAL LOOP METHOD.
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = null === $transaction ? null : $transaction->account;
$count = $journal->transactions()->count();
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null === $account));
$loops++;
// do this until: account is not null, journal has two transactions, loops is below 30
} while (!(null !== $account && 2 === $count && $loops < 30));
/** @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);
$trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
$result = $trigger->triggered($journal);
@@ -97,7 +77,12 @@ class ToAccountStartsTest 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('getJournalDestinationAccounts')->once()->andReturn($collection);
$trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
$result = $trigger->triggered($journal);