Remove old tests. To be reinstated later.

This commit is contained in:
James Cole
2020-10-10 11:20:52 +02:00
parent d75f33558d
commit 76cfdef27d
252 changed files with 0 additions and 50457 deletions

View File

@@ -1,147 +0,0 @@
<?php
/**
* DecryptDatabaseTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands;
use Crypt;
use FireflyConfig;
use FireflyIII\Models\Account;
use FireflyIII\Models\Configuration;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class DecryptDatabaseTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class DecryptDatabaseTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\DecryptDatabase
*/
public function testHandle(): void
{
// create encrypted account:
$name = 'Encrypted name';
$iban = 'HR1723600001101234565';
$account = Account::create(
[
'user_id' => 1,
'account_type_id' => 1,
'name' => Crypt::encrypt($name),
'iban' => Crypt::encrypt($iban),
]);
FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn(null);
FireflyConfig::shouldReceive('set')->withArgs([Mockery::any(), true])->atLeast()->once();
$this->artisan('firefly-iii:decrypt-all')
->expectsOutput('Done!')
->assertExitCode(0);
$this->assertCount(1, Account::where('id', $account->id)->where('name', $name)->get());
$this->assertCount(1, Account::where('id', $account->id)->where('iban', $iban)->get());
}
/**
* @covers \FireflyIII\Console\Commands\DecryptDatabase
*/
public function testHandleDecrypted(): void
{
// create encrypted account:
$name = 'Encrypted name';
$iban = 'HR1723600001101234565';
$encryptedName = Crypt::encrypt($name);
$encryptedIban = Crypt::encrypt($iban);
$account = Account::create(
[
'user_id' => 1,
'account_type_id' => 1,
'name' => $encryptedName,
'iban' => $encryptedIban,
]);
// pretend its not yet decrypted.
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn($true);
$this->artisan('firefly-iii:decrypt-all')
->expectsOutput('Done!')
->assertExitCode(0);
$this->assertCount(1, Account::where('id', $account->id)->where('name', $encryptedName)->get());
$this->assertCount(1, Account::where('id', $account->id)->where('iban', $encryptedIban)->get());
}
/**
* Try to decrypt data that isn't actually encrypted.
*
* @covers \FireflyIII\Console\Commands\DecryptDatabase
*/
public function testHandleNotEncrypted(): void
{
// create encrypted account:
$name = 'Encrypted name';
$iban = 'HR1723600001101234565';
$account = Account::create(
[
'user_id' => 1,
'account_type_id' => 1,
'name' => $name,
'iban' => $iban,
]);
// pretend its not yet decrypted.
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs([Mockery::any(), false])->atLeast()->once()->andReturn($true);
$this->artisan('firefly-iii:decrypt-all')
->expectsOutput('Done!')
->assertExitCode(0);
$this->assertCount(1, Account::where('id', $account->id)->where('name', $name)->get());
$this->assertCount(1, Account::where('id', $account->id)->where('iban', $iban)->get());
}
}

View File

@@ -1,156 +0,0 @@
<?php
/**
* ReportEmptyObjectsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Integrity;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use Log;
use Tests\TestCase;
/**
* Class ReportEmptyObjectsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ReportEmptyObjectsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Run basic test routine.
*
* @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
*/
public function testHandleBudget(): void
{
$user = $this->user();
$budget = Budget::create(
[
'user_id' => $user->id,
'name' => 'Some budget',
]);
$budgetLine = sprintf('User #%d (%s) has budget #%d ("%s") which has no transaction journals.',
$user->id, $user->email, $budget->id, $budget->name);
$budgetLimitLine = sprintf('User #%d (%s) has budget #%d ("%s") which has no budget limits.',
$user->id, $user->email, $budget->id, $budget->name);
$this->artisan('firefly-iii:report-empty-objects')
->expectsOutput($budgetLine)
->expectsOutput($budgetLimitLine)
->assertExitCode(0);
$budget->forceDelete();
// this method changes no objects so there is nothing to verify.
}
/**
* Run basic test routine.
*
* @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
*/
public function testHandleCategory(): void
{
$user = $this->user();
$category = Category::create(
[
'user_id' => $user->id,
'name' => 'Some category',
]);
$categoryLine = sprintf('User #%d (%s) has category #%d ("%s") which has no transaction journals.',
$user->id, $user->email, $category->id, $category->name);
$this->artisan('firefly-iii:report-empty-objects')
->expectsOutput($categoryLine)
->assertExitCode(0);
$category->forceDelete();
// this method changes no objects so there is nothing to verify.
}
/**
* Run basic test routine.
*
* @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
*/
public function testHandleTag(): void
{
$user = $this->user();
$tag = Tag::create(
[
'user_id' => $user->id,
'tag' => 'Some tag',
'tagMode' => 'nothing',
]);
$tagLine = sprintf('User #%d (%s) has tag #%d ("%s") which has no transaction journals.',
$user->id, $user->email, $tag->id, $tag->tag);
$this->artisan('firefly-iii:report-empty-objects')
->expectsOutput($tagLine)
->assertExitCode(0);
$tag->forceDelete();
// this method changes no objects so there is nothing to verify.
}
/**
* Run basic test routine.
*
* @covers \FireflyIII\Console\Commands\Integrity\ReportEmptyObjects
*/
public function testHandleAccount(): void
{
$user = $this->user();
$account = Account::create(
[
'user_id' => $user->id,
'name' => 'Some account',
'account_type_id' => 1,
]);
$tagLine = sprintf('User #%d (%s) has account #%d ("%s") which has no transactions.',
$user->id, $user->email, $account->id, $account->name);
$this->artisan('firefly-iii:report-empty-objects')
->expectsOutput($tagLine)
->assertExitCode(0);
$account->forceDelete();
// this method changes no objects so there is nothing to verify.
}
}

View File

@@ -1,93 +0,0 @@
<?php
/**
* ReportSumTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Integrity;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class ReportSumTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ReportSumTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Integrity\ReportSum
*/
public function testHandle(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$this->artisan('firefly-iii:report-sum')
->expectsOutput(sprintf('Amount integrity OK for user #%d', $this->user()->id))
->assertExitCode(0);
// this method changes no objects so there is nothing to verify.
}
/**
* Create transaction to make balance uneven.
* @covers \FireflyIII\Console\Commands\Integrity\ReportSum
*/
public function testHandleUneven(): void
{
$transaction = Transaction::create(
[
'transaction_journal_id' => $this->getRandomWithdrawal()->id,
'user_id' => 1,
'account_id' => $this->getRandomAsset()->id,
'amount' => 10,
]
);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$this->artisan('firefly-iii:report-sum')
->expectsOutput(sprintf('Error: Transactions for user #%d (%s) are off by %s!', $this->user()->id, $this->user()->email, '10.0'))
->assertExitCode(0);
$transaction->forceDelete();
// this method changes no objects so there is nothing to verify.
}
}

View File

@@ -1,459 +0,0 @@
<?php
/**
* ApplyRulesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Tools;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngine;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class ApplyRulesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ApplyRulesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic call with everything perfect (and ALL rules).
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandle(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleEngine = $this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// data
$asset = $this->getRandomAsset();
$journal = $this->getRandomWithdrawal();
$group = $this->user()->ruleGroups()->first();
$rule = $this->user()->rules()->first();
$groups = new Collection([$group]);
$rules = new Collection([$rule]);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
$journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
$ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
$ruleEngine->shouldReceive('processJournalArray')->times(3);
$ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
$parameters = [
'--user=1',
'--token=token',
'--accounts=1',
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
->assertExitCode(0);
// this method changes no objects so there is nothing to verify.
}
/**
* Basic call with everything perfect (and ALL rules), but no rules will be selected.
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandEmpty(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleEngine = $this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// data
$asset = $this->getRandomAsset();
$journal = $this->getRandomWithdrawal();
$group = $this->user()->ruleGroups()->first();
$groups = new Collection([$group]);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
$journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
$ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn(new Collection);
$parameters = [
'--user=1',
'--token=token',
'--accounts=1',
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('No rules or rule groups have been included.')
->assertExitCode(1);
}
/**
* Basic call with everything perfect (and ALL rules) and dates.
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandleDate(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleEngine = $this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// data
$asset = $this->getRandomAsset();
$group = $this->user()->ruleGroups()->first();
$rule = $this->user()->rules()->first();
$groups = new Collection([$group]);
$rules = new Collection([$rule]);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
$ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
$ruleEngine->shouldReceive('processJournalArray')->times(3);
$ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
$parameters = [
'--user=1',
'--token=token',
'--accounts=1',
'--all_rules',
'--start_date=2019-01-31',
'--end_date=2019-01-01',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
->assertExitCode(0);
}
/**
* Will submit some rules to apply.
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandleRules(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleEngine = $this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// data
$asset = $this->getRandomAsset();
$journal = $this->getRandomWithdrawal();
$group = $this->user()->ruleGroups()->first();
$groups = new Collection([$group]);
$activeRule = $this->user()->rules()->where('active', 1)->inRandomOrder()->first();
$inactiveRule = $this->user()->rules()->where('active', 0)->inRandomOrder()->first();
$rules = new Collection([$activeRule]);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
$journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
$ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeRule->id])->andReturn($activeRule);
$ruleRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveRule->id])->andReturn($inactiveRule);
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
$ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
$ruleEngine->shouldReceive('processJournalArray')->times(3);
$ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
$parameters = [
'--user=1',
'--token=token',
'--accounts=1',
sprintf('--rules=%d,%d', $activeRule->id, $inactiveRule->id),
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
->assertExitCode(0);
}
/**
* Basic call with two rule groups. One active, one inactive.
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandleRuleGroups(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleEngine = $this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$activeGroup = $this->user()->ruleGroups()->where('active', 1)->inRandomOrder()->first();
$inactiveGroup = $this->user()->ruleGroups()->where('active', 0)->inRandomOrder()->first();
// data
$asset = $this->getRandomAsset();
$journal = $this->getRandomWithdrawal();
$rule = $this->user()->rules()->first();
$groups = new Collection([$activeGroup]);
$rules = new Collection([$rule]);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($asset);
$journalRepos->shouldReceive('firstNull')->atLeast()->once()->andReturn($journal);
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn($groups);
$ruleGroupRepos->shouldReceive('getActiveStoreRules')->atLeast()->once()->andReturn($rules);
$ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$activeGroup->id])->andReturn($activeGroup);
$ruleGroupRepos->shouldReceive('find')->atLeast()->once()->withArgs([$inactiveGroup->id])->andReturn($inactiveGroup);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([[], [], []]);
$ruleEngine->shouldReceive('setUser')->atLeast()->once();
$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
$ruleEngine->shouldReceive('processJournalArray')->times(3);
$ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once()->withArgs([RuleEngine::TRIGGER_STORE]);
$parameters = [
'--user=1',
'--token=token',
'--accounts=1',
sprintf('--rule_groups=%d,%d', $activeGroup->id, $inactiveGroup->id),
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput(sprintf('Will ignore inactive rule group #%d ("%s")', $inactiveGroup->id, $inactiveGroup->title))
// one rule out of 2 groups:
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
->assertExitCode(0);
}
/**
* Basic call but no accounts submitted.
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandleNoAccounts(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(GroupCollectorInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(RuleEngine::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$parameters = [
'--user=1',
'--token=token',
'--accounts=',
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Please use the --accounts option to indicate the accounts to apply rules to.')
->assertExitCode(1);
}
/**
* Basic call but only one expense account submitted
*
* @covers \FireflyIII\Console\Commands\Tools\ApplyRules
*/
public function testHandleExpenseAccounts(): void
{
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(RuleEngine::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(GroupCollectorInterface::class);
// data
$expense = $this->getRandomExpense();
// expected calls:
$userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());
$ruleRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$expense->id])->andReturn($expense);
$parameters = [
'--user=1',
'--token=token',
'--accounts=' . $expense->id,
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Please make sure all accounts in --accounts are asset accounts or liabilities.')
->assertExitCode(1);
}
}

View File

@@ -1,358 +0,0 @@
<?php
/**
* AccountCurrenciesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class AccountCurrenciesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AccountCurrenciesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Perfect run without opening balance.
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$account = $this->getRandomAsset();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput('All accounts are OK.')
->assertExitCode(0);
// nothing changed, so nothing to verify.
}
/**
* Perfect run without opening balance.
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleNotNull(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$account = $this->getRandomAsset();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journal = $this->getRandomWithdrawal();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
// account reports USD
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('2');
// journal is EUR.
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name))
->assertExitCode(0);
// check if currency has been changed for the journal + transactions.
$this->assertCount(1, TransactionJournal::where('id', $journal->id)->where('transaction_currency_id', 2)->get());
$this->assertCount(2, Transaction::where('transaction_journal_id', $journal->id)->where('transaction_currency_id', 2)->get());
}
/**
* Perfect run with opening balance.
*
* TODO this method crashes some times but not sure why.
* 2019-07-27 should be fixed.
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleOpeningBalance(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journal = $this->getRandomWithdrawal();
$euro = $this->getEuro();
$journal->transaction_currency_id = $euro->id;
$journal->save();
$journal->refresh();
$account = $this->getRandomAsset();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput('All accounts are OK.')
->assertExitCode(0);
// nothing changed, dont check output.
}
/**
* Perfect run with opening balance with different currencies
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleDifferent(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'USD';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journal = $this->getRandomWithdrawal();
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$journal->transaction_currency_id = $euro->id;
$journal->save();
// delete meta data of account just in case:
AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('0');
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn($journal);
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput(sprintf('Account #%d ("%s") now has a currency setting (#%d).', $account->id, $account->name, $euro->id))
->assertExitCode(0);
// verify account meta data change.
$this->assertCount(1,
AccountMeta::where('account_id', $account->id)
->where('name', 'currency_id')
->where('data', $euro->id)->get());
}
/**
* No known currency preferences.
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleZeroPreference(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$account = $this->getRandomAsset();
$euro = $this->getEuro();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('0');
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput(sprintf('Account #%d ("%s") now has a currency setting (%s).',
$account->id, $account->name, $euro->code
))
->expectsOutput('Corrected 1 account(s).')
->assertExitCode(0);
$this->assertCount(1, AccountMeta::where('account_id', $account->id)
->where('name', 'currency_id')
->where('data', $euro->id)->get());
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleNoPreference(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = false;
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$account = $this->getRandomAsset();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
$accountRepos->shouldReceive('getOpeningBalance')->atLeast()->once()->andReturn(null);
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput('All accounts are OK.')
->assertExitCode(0);
// nothing changed, so nothing to verify.
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleInvalidPreference(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'ABC';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$account = $this->getRandomAsset();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));
$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput('User has a preference for "ABC", but this currency does not exist.')
->assertExitCode(0);
// nothing changed, so nothing to verify.
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleAlreadyExecuted(): void
{
$true = new Configuration;
$true->data = true;
$pref = new Preference;
$pref->data = 'EUR';
$this->mock(AccountRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($true);
FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);
// check preferences:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);
$this->artisan('firefly-iii:account-currencies')
->expectsOutput('This command has already been executed.')
->assertExitCode(0);
// nothing changed, so nothing to verify.
}
}

View File

@@ -1,253 +0,0 @@
<?php
/**
* BackToJournalsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use Log;
use Tests\TestCase;
/**
* Class BackToJournalsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BackToJournalsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Perfect run. Will report on nothing.
*
* @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
*/
public function testHandle(): void
{
// verify preference:
$false = new Configuration;
$false->data = false;
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
// set new preference after running:
FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
$this->artisan('firefly-iii:back-to-journals')
->expectsOutput('Check 0 transaction journal(s) for budget info.')
->expectsOutput('Check 0 transaction journal(s) for category info.')
->assertExitCode(0);
}
/**
* Transaction has a budget, journal doesn't.
*
* @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
*/
public function testHandleBudget(): void
{
$journal = $this->getRandomWithdrawal();
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
/** @var Budget $budget */
$budget = $this->user()->budgets()->first();
$transaction->budgets()->sync([$budget->id]);
$journal->budgets()->sync([]);
$journal->save();
$transaction->save();
// verify preference:
$false = new Configuration;
$false->data = false;
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
// set new preference after running:
FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
$this->artisan('firefly-iii:back-to-journals')
->expectsOutput('Check 1 transaction journal(s) for budget info.')
->expectsOutput('Check 0 transaction journal(s) for category info.')
->assertExitCode(0);
// transaction should have no budget:
$this->assertEquals(0, $transaction->budgets()->count());
// journal should have one.
$this->assertEquals(1, $journal->budgets()->count());
// should be $budget:
$this->assertEquals($budget->id, $journal->budgets()->first()->id);
}
/**
* Transaction has a category, journal doesn't.
*
* @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
*/
public function testHandleCategory(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
$journal = $this->getRandomWithdrawal();
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
/** @var Category $category */
$category = $this->user()->categories()->first();
$transaction->categories()->sync([$category->id]);
$journal->categories()->sync([]);
$journal->save();
$transaction->save();
// verify preference:
$false = new Configuration;
$false->data = false;
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
// set new preference after running:
FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
$this->artisan('firefly-iii:back-to-journals')
->expectsOutput('Check 0 transaction journal(s) for budget info.')
->expectsOutput('Check 1 transaction journal(s) for category info.')
->assertExitCode(0);
// transaction should have no category:
$this->assertEquals(0, $transaction->categories()->count());
// journal should have one.
$this->assertEquals(1, $journal->categories()->count());
// should be $category:
$this->assertEquals($category->id, $journal->categories()->first()->id);
}
/**
* Transaction has a budget, journal has another
*
* @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
*/
public function testHandleDifferentBudget(): void
{
$journal = $this->getRandomWithdrawal();
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
/** @var Budget $budget */
$budget = $this->user()->budgets()->first();
$otherBudget = $this->user()->budgets()->where('id', '!=', $budget->id)->first();
$transaction->budgets()->sync([$budget->id]);
$journal->budgets()->sync([$otherBudget->id]);
$journal->save();
$transaction->save();
// verify preference:
$false = new Configuration;
$false->data = false;
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
// set new preference after running:
FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
$this->artisan('firefly-iii:back-to-journals')
->expectsOutput('Check 1 transaction journal(s) for budget info.')
->expectsOutput('Check 0 transaction journal(s) for category info.')
->assertExitCode(0);
// transaction should have no budget:
$this->assertEquals(0, $transaction->budgets()->count());
// journal should have one.
$this->assertEquals(1, $journal->budgets()->count());
// should be $budget:
$this->assertEquals($budget->id, $journal->budgets()->first()->id);
}
/**
* Transaction has a category, journal has another
*
* @covers \FireflyIII\Console\Commands\Upgrade\BackToJournals
*/
public function testHandleDifferentCategory(): void
{
$journal = $this->getRandomWithdrawal();
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
/** @var Category $category */
$category = $this->user()->categories()->first();
$otherCategory = $this->user()->categories()->where('id', '!=', $category->id)->first();
$transaction->categories()->sync([$category->id]);
$journal->categories()->sync([$otherCategory->id]);
$journal->save();
$transaction->save();
// verify preference:
$false = new Configuration;
$false->data = false;
$true = new Configuration;
$true->data = true;
FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);
// set new preference after running:
FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);
$this->artisan('firefly-iii:back-to-journals')
->expectsOutput('Check 0 transaction journal(s) for budget info.')
->expectsOutput('Check 1 transaction journal(s) for category info.')
->assertExitCode(0);
// transaction should have no category:
$this->assertEquals(0, $transaction->categories()->count());
// journal should have one.
$this->assertEquals(1, $journal->categories()->count());
// should be $category:
$this->assertEquals($category->id, $journal->categories()->first()->id);
}
}

View File

@@ -1,105 +0,0 @@
<?php
/**
* BudgetLimitCurrencyTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use Amount;
use FireflyConfig;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Configuration;
use Log;
use Tests\TestCase;
/**
* Class BudgetLimitCurrencyTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class BudgetLimitCurrencyTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\BudgetLimitCurrency
*/
public function testHandle(): void
{
BudgetLimit::whereNull('transaction_currency_id')->forceDelete();
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);
$this->artisan('firefly-iii:bl-currency')
->expectsOutput('All budget limits are correct.')
->assertExitCode(0);
}
/**
* Create a bad budget limit.
* @covers \FireflyIII\Console\Commands\Upgrade\BudgetLimitCurrency
*/
public function testHandleBadLimit(): void
{
$false = new Configuration;
$false->data = false;
$budget = $this->user()->budgets()->first();
$limit = BudgetLimit::create(
[
'budget_id' => $budget->id,
'amount' => '10',
'start_date' => '2019-01-01',
'end_date' => '2019-01-31',
]);
FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);
$currency = $this->getEuro();
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
$this->artisan('firefly-iii:bl-currency')
->expectsOutput(
sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).',
$limit->id, $budget->name, 'Euro'
)
)
->assertExitCode(0);
// assume currency is filled in.
$this->assertCount(1, BudgetLimit::where('id', $limit->id)->where('transaction_currency_id', 1)->get());
}
}

View File

@@ -1,137 +0,0 @@
<?php
/**
* CCLiabilitiesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Configuration;
use Log;
use Tests\TestCase;
/**
* Class CCLiabilitiesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CCLiabilitiesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
$this->artisan('firefly-iii:cc-liabilities')
->expectsOutput('No incorrectly stored credit card liabilities.')
->assertExitCode(0);
// nothing changed, so nothing to verify.
}
/**
* Add type to make the script run.
*
* @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
*/
public function testHandleEmpty(): void
{
$type = AccountType::create(
[
'type' => AccountType::CREDITCARD,
]
);
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
$this->artisan('firefly-iii:cc-liabilities')
->expectsOutput('No incorrectly stored credit card liabilities.')
->assertExitCode(0);
$type->forceDelete();
// nothing changed, so nothing to verify.
}
/**
* Add some things to make it trigger.
*
* @covers \FireflyIII\Console\Commands\Upgrade\CCLiabilities
*/
public function testHandleCase(): void
{
$type = AccountType::create(
[
'type' => AccountType::CREDITCARD,
]
);
$account = Account::create(
[
'name' => 'CC',
'user_id' => 1,
'account_type_id' => $type->id,
]
);
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);
$this->artisan('firefly-iii:cc-liabilities')
->expectsOutput(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id))
->expectsOutput('Credit card liability types are no longer supported and have been converted to generic debts. See: http://bit.ly/FF3-credit-cards')
->assertExitCode(0);
// verify new type.
$this->assertCount(0, Account::where('id', $account->id)->where('account_type_id', $type->id)->get());
$account->forceDelete();
$type->forceDelete();
}
}

View File

@@ -1,104 +0,0 @@
<?php
/**
* MigrateAttachmentsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class MigrateAttachmentsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class MigrateAttachmentsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
// assume all is well.
$this->artisan('firefly-iii:migrate-attachments')
->expectsOutput('All attachments are OK.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
*/
public function testHandleMigrate(): void
{
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
$attachment = Attachment::create(
[
'user_id' => 1,
'attachable_id' => 1,
'attachable_type' => TransactionJournal::class,
'description' => 'Hello',
'md5' => md5('hello'),
'filename' => 'test.pdf',
'mime' => 'text/plain',
'size' => 1,
]);
// assume all is well.
$this->artisan('firefly-iii:migrate-attachments')
->expectsOutput('Updated 1 attachment(s).')
->assertExitCode(0);
$this->assertCount(0, Attachment::where('id', $attachment->id)->where('description', '!=', '')->get());
$this->assertCount(1, Attachment::where('id', $attachment->id)->where('description', '=', '')->get());
$this->assertCount(1, Note::where('noteable_id', $attachment->id)->where('noteable_type', Attachment::class)->get());
$attachment->forceDelete();
}
}

View File

@@ -1,106 +0,0 @@
<?php
/**
* MigrateJournalNotesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\TransactionJournalMeta;
use Log;
use Tests\TestCase;
/**
* Class MigrateJournalNotesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class MigrateJournalNotesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
// assume all is well.
$this->artisan('firefly-iii:migrate-notes')
->expectsOutput('No notes to migrate.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
*/
public function testHandleNote(): void
{
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
$journal = $this->getRandomWithdrawal();
// delete any notes the journal may have already:
$journal->notes()->forceDelete();
$meta = TransactionJournalMeta::create(
[
'transaction_journal_id' => $journal->id,
'name' => 'notes',
'data' => json_encode('Some note.'),
'hash' => 'Some hash',
]
);
// assume one is fixed.
$this->artisan('firefly-iii:migrate-notes')
->expectsOutput('Migrated 1 note(s).')
->assertExitCode(0);
$this->assertCount(0, TransactionJournalMeta
::where('name', 'notes')
->where('id', $meta->id)
->whereNull('deleted_at')
->get());
}
}

View File

@@ -1,264 +0,0 @@
<?php
/**
* MigrateToGroupsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class MigrateToGroupsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class MigrateToGroupsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
*/
public function testHandle(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$service = $this->mock(JournalDestroyService::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// mock calls:
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection);
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([]);
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
// assume all is well.
$this->artisan('firefly-iii:migrate-to-groups')
->expectsOutput('No journals to migrate to groups.')
->assertExitCode(0);
}
/**
* Return a journal without a group.
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
*/
public function testHandleNoGroup(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$service = $this->mock(JournalDestroyService::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$asset = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 1,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '10',
'identifier' => 1,
]
);
$array = $journal->toArray();
// mock calls:
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection);
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([$array]);
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
// assume all is well.
$this->artisan('firefly-iii:migrate-to-groups')
->expectsOutput('Migrated 1 transaction journal(s).')
->assertExitCode(0);
// no longer without a group.
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('transaction_group_id')->get());
$journal->transactionGroup()->forceDelete();
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Create split withdrawal and see what the system will do.
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToGroups
*/
public function testHandleSplitJournal(): void
{
$asset = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$group = $this->getRandomWithdrawalGroup();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 1,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '10',
'identifier' => 1,
]
);
$three = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-12',
'identifier' => 2,
]
);
$four = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '12',
'identifier' => 2,
]
);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$service = $this->mock(JournalDestroyService::class);
$factory = $this->mock(TransactionGroupFactory::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// mock calls:
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
// mock journal things:
$cliRepos->shouldReceive('getJournalBudgetId')->atLeast()->once()->andReturn(0);
$cliRepos->shouldReceive('getJournalCategoryId')->atLeast()->once()->andReturn(0);
$cliRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Some note.');
$cliRepos->shouldReceive('getTags')->atLeast()->once()->andReturn(['A', 'B']);
$cliRepos->shouldReceive('getMetaField')->atLeast()
->withArgs([Mockery::any(), Mockery::any()])
->once()->andReturn(null);
$cliRepos->shouldReceive('getMetaDate')->atLeast()
->withArgs([Mockery::any(), Mockery::any()])
->once()->andReturn(null);
// create a group
$factory->shouldReceive('create')->atLeast()->once()->andReturn($group);
$service->shouldReceive('destroy')->atLeast()->once();
$factory->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection([$journal]));
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([]);
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);
$this->artisan('firefly-iii:migrate-to-groups')
->expectsOutput('Migrated 1 transaction journal(s).')
->assertExitCode(0);
// delete the created stuff:
$one->forceDelete();
$two->forceDelete();
$three->forceDelete();
$four->forceDelete();
$journal->forceDelete();
// the calls above let me know it's OK.
}
}

View File

@@ -1,330 +0,0 @@
<?php
/**
* MigrateToRulesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class MigrateToRulesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class MigrateToRulesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
*/
public function testHandle(): void
{
// mock repositories:
$userRepository = $this->mock(UserRepositoryInterface::class);
$ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
$billRepository = $this->mock(BillRepositoryInterface::class);
$ruleRepository = $this->mock(RuleRepositoryInterface::class);
$group = $this->user()->ruleGroups()->inRandomOrder()->first();
$bill = $this->user()->bills()->inRandomOrder()->first();
// mock all calls.
$userRepository->shouldReceive('all')->atLeast()->once()
->andReturn(new Collection([$this->user()]));
$ruleRepository->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepository->shouldReceive('findByTitle')
->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
// rule group repos should try to store a rule group in response to the result above.
$ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
// bill repos should return one rule.
$billRepository->shouldReceive('setUser')->atLeast()->once();
$billRepository->shouldReceive('getBills')->atLeast()->once()
->andReturn(new Collection([$bill]));
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
// preferences
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
// assume all is well.
$this->artisan('firefly-iii:bills-to-rules')
->expectsOutput('All bills are OK.')
->assertExitCode(0);
}
/**
* Basic test. Give command an unmigrated bill. This bill has the same amount_min
* as amount_max
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
*/
public function testHandleEvenBill(): void
{
$billName = 'I am a bill #' . $this->randomInt();
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'transaction_currency_id' => null,
'name' => $billName,
'match' => 'some,kind,of,match',
'amount_min' => '30',
'amount_max' => '30',
'date' => '2019-01-01',
'repeat_freq' => 'monthly',
]
);
// mock repositories:
$userRepository = $this->mock(UserRepositoryInterface::class);
$ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
$billRepository = $this->mock(BillRepositoryInterface::class);
$ruleRepository = $this->mock(RuleRepositoryInterface::class);
$group = $this->user()->ruleGroups()->inRandomOrder()->first();
// mock all calls.
$userRepository->shouldReceive('all')->atLeast()->once()
->andReturn(new Collection([$this->user()]));
$ruleRepository->shouldReceive('setUser')->atLeast()->once();
// this is what rule repos should receive:
$argumentRule = [
'rule_group_id' => $group->id,
'active' => true,
'strict' => false,
'stop_processing' => false, // field is no longer used.
'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
'trigger' => 'store-journal',
'triggers' => [
[
'type' => 'description_contains',
'value' => 'some kind of match',
],
[
'type' => 'amount_exactly',
'value' => $bill->amount_min,
],
],
'actions' => [
[
'type' => 'link_to_bill',
'value' => $bill->name,
],
],
];
// this is what the bill repos should receive:
$argumentBill = [
'currency_id' => $bill->transaction_currency_id,
'name' => $bill->name,
'match' => 'MIGRATED_TO_RULES',
'amount_min' => $bill->amount_min,
'amount_max' => $bill->amount_max,
'date' => $bill->date,
'repeat_freq' => $bill->repeat_freq,
'skip' => $bill->skip,
'active' => $bill->active,
];
$ruleRepository->shouldReceive('store')->atLeast()->once()->withArgs([$argumentRule]);
// rule group repos should try to store a rule group in response to the result above.
$ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepository->shouldReceive('findByTitle')
->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
$ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
// bill repos should return one rule.
$billRepository->shouldReceive('setUser')->atLeast()->once();
$billRepository->shouldReceive('getBills')->atLeast()->once()
->andReturn(new Collection([$bill]));
$billRepository->shouldReceive('update')->atLeast()->once()
->withArgs([Mockery::any(), $argumentBill]);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
// preferences
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
// assume all is well.
$this->artisan('firefly-iii:bills-to-rules')
->expectsOutput('Verified and fixed 1 bill(s).')
->assertExitCode(0);
}
/**
* Basic test. Give command an unmigrated bill. This bill has a different amount_min
* from the amount_max
*
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateToRules
*/
public function testHandleUnevenBill(): void
{
$billName = 'I am a bill #' . $this->randomInt();
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'transaction_currency_id' => null,
'name' => $billName,
'match' => 'some,kind,of,match',
'amount_min' => '30',
'amount_max' => '40',
'date' => '2019-01-01',
'repeat_freq' => 'monthly',
]
);
// mock repositories:
$userRepository = $this->mock(UserRepositoryInterface::class);
$ruleGroupRepository = $this->mock(RuleGroupRepositoryInterface::class);
$billRepository = $this->mock(BillRepositoryInterface::class);
$ruleRepository = $this->mock(RuleRepositoryInterface::class);
$group = $this->user()->ruleGroups()->inRandomOrder()->first();
// mock all calls.
$userRepository->shouldReceive('all')->atLeast()->once()
->andReturn(new Collection([$this->user()]));
$ruleRepository->shouldReceive('setUser')->atLeast()->once();
// this is what rule repos should receive:
$argumentRule = [
'rule_group_id' => $group->id,
'active' => true,
'strict' => false,
'stop_processing' => false, // field is no longer used.
'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
'trigger' => 'store-journal',
'triggers' => [
[
'type' => 'description_contains',
'value' => 'some kind of match',
],
[
'type' => 'amount_less',
'value' => $bill->amount_max,
],
[
'type' => 'amount_more',
'value' => $bill->amount_min,
],
],
'actions' => [
[
'type' => 'link_to_bill',
'value' => $bill->name,
],
],
];
// this is what the bill repos should receive:
$argumentBill = [
'currency_id' => $bill->transaction_currency_id,
'name' => $bill->name,
'match' => 'MIGRATED_TO_RULES',
'amount_min' => $bill->amount_min,
'amount_max' => $bill->amount_max,
'date' => $bill->date,
'repeat_freq' => $bill->repeat_freq,
'skip' => $bill->skip,
'active' => $bill->active,
];
$ruleRepository->shouldReceive('store')->atLeast()->once()->withArgs([$argumentRule]);
// rule group repos should try to store a rule group in response to the result above.
$ruleGroupRepository->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepository->shouldReceive('findByTitle')
->withArgs(['Rule group for bills'])->atLeast()->once()->andReturnNull();
$ruleGroupRepository->shouldReceive('store')->atLeast()->once()->andReturn($group);
// bill repos should return one rule.
$billRepository->shouldReceive('setUser')->atLeast()->once();
$billRepository->shouldReceive('getBills')->atLeast()->once()
->andReturn(new Collection([$bill]));
$billRepository->shouldReceive('update')->atLeast()->once()
->withArgs([Mockery::any(), $argumentBill]);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);
// preferences
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language);
// assume all is well.
$this->artisan('firefly-iii:bills-to-rules')
->expectsOutput('Verified and fixed 1 bill(s).')
->assertExitCode(0);
}
}

View File

@@ -1,277 +0,0 @@
<?php
/**
* OtherCurrenciesCorrectionsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class OtherCurrenciesCorrectionsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class OtherCurrenciesCorrectionsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong. Submit a withdrawal and a deposit.
*
* @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
*/
public function testHandle(): void
{
// mock classes:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal();
$deposit = $this->getRandomDeposit();
$euro = $this->getEuro();
// collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$withdrawal, $deposit]));
// account repos
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
#$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()
# ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
// collect currency
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
#$currencyRepos->shouldReceive('findNull')->atLeast()->once()
# ->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
// assume all is well.
$this->artisan('firefly-iii:other-currencies')
->expectsOutput('Verified 2 transaction(s) and journal(s).')
->assertExitCode(0);
}
/**
* Basic test. Assume nothing is wrong. Submit an opening balance.
* Also fixes transaction currency ID.
*
* @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
*/
public function testHandleOB(): void
{
$type = TransactionType::where('type', TransactionType::OPENING_BALANCE)->first();
$asset = $this->getRandomAsset();
$initial = $this->getRandomInitialBalance();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 1,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $initial->id,
'amount' => '10',
'identifier' => 1,
]
);
// mock classes:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$euro = $this->getEuro();
// collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal]));
// account repos
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// collect currency
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
#$currencyRepos->shouldReceive('findNull')->atLeast()->once()
# ->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
$this->artisan('firefly-iii:other-currencies')
->expectsOutput('Verified 1 transaction(s) and journal(s).')
->assertExitCode(0);
// assume currency has been fixed for both transactions:
$this->assertCount(1, Transaction::where('id', $one->id)->where('transaction_currency_id', $euro->id)->get());
$this->assertCount(1, Transaction::where('id', $two->id)->where('transaction_currency_id', $euro->id)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Basic test. Assume nothing is wrong. Submit an opening balance.
* Also fixes bad transaction currency ID.
*
* @covers \FireflyIII\Console\Commands\Upgrade\OtherCurrenciesCorrections
*/
public function testHandleReconciliation(): void
{
$type = TransactionType::where('type', TransactionType::RECONCILIATION)->first();
$asset = $this->getRandomAsset();
$reconciliation = $this->getRandomReconciliation();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 1,
'transaction_currency_id' => 2,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $reconciliation->id,
'amount' => '10',
'identifier' => 1,
'transaction_currency_id' => 2,
]
);
// mock classes:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$euro = $this->getEuro();
// collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal]));
// account repos
$accountRepos->shouldReceive('setUser')->atLeast()->once();
#$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()
# ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// collect currency
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
#$currencyRepos->shouldReceive('findNull')->atLeast()->once()
# ->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);
$this->artisan('firefly-iii:other-currencies')
->expectsOutput('Verified 1 transaction(s) and journal(s).')
->assertExitCode(0);
// assume currency has been fixed for both transactions:
$this->assertCount(1, Transaction::where('id', $one->id)->where('transaction_currency_id', $euro->id)->get());
$this->assertCount(1, Transaction::where('id', $two->id)->where('transaction_currency_id', $euro->id)->get());
$this->assertCount(1, Transaction::where('id', $one->id)->where('foreign_currency_id', 2)->get());
$this->assertCount(1, Transaction::where('id', $two->id)->where('foreign_currency_id', 2)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
}

View File

@@ -1,108 +0,0 @@
<?php
/**
* RenameAccountMetaTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Configuration;
use Log;
use Tests\TestCase;
/**
* Class RenameAccountMetaTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class RenameAccountMetaTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\RenameAccountMeta
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);
// assume all is well.
$this->artisan('firefly-iii:rename-account-meta')
->expectsOutput('All account meta is OK.')
->assertExitCode(0);
}
/**
* Create bad entry, then check if its renamed.
*
* @covers \FireflyIII\Console\Commands\Upgrade\RenameAccountMeta
*/
public function testHandleRename(): void
{
$false = new Configuration;
$false->data = false;
// check config
FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);
$expense = $this->getRandomExpense();
$meta = AccountMeta::create(
[
'name' => 'accountRole',
'data' => 'defaultAsset',
'account_id' => $expense->id,
]
);
// assume all is well.
$this->artisan('firefly-iii:rename-account-meta')
->expectsOutput('Renamed 1 account meta entries (entry).')
->assertExitCode(0);
$this->assertCount(0, AccountMeta::where('id', $meta->id)->where('name', 'accountRole')->get());
$this->assertCount(1, AccountMeta::where('id', $meta->id)->where('name', 'account_role')->get());
$meta->forceDelete();
}
}

View File

@@ -1,161 +0,0 @@
<?php
/**
* TransactionIdentifierTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class TransactionIdentifierTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TransactionIdentifierTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
*/
public function testHandle(): void
{
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// commands:
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
->atLeast()->once();
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
// assume all is well.
$this->artisan('firefly-iii:transaction-identifiers')
->expectsOutput('All split journal transaction identifiers are correct.')
->assertExitCode(0);
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
*/
public function testHandleSplit(): void
{
// create a split journal:
$asset = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 0,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '10',
'identifier' => 0,
]
);
$three = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-12',
'identifier' => 0,
]
);
$four = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '12',
'identifier' => 0,
]
);
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// commands:
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
->atLeast()->once();
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
// assume all is well.
$this->artisan('firefly-iii:transaction-identifiers')
->expectsOutput('Fixed 2 split journal transaction identifier(s).')
->assertExitCode(0);
// see results:
$this->assertCount(1, Transaction::where('id', $one->id)->where('identifier', 0)->get());
$this->assertCount(1, Transaction::where('id', $three->id)->where('identifier', 1)->get());
}
}

View File

@@ -1,562 +0,0 @@
<?php
/**
* TransferCurrenciesCorrectionsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* 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\Feature\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class TransferCurrenciesCorrectionsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TransferCurrenciesCorrectionsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandle(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
// assume all is well.
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('All transfers have correct currency information.')
->assertExitCode(0);
}
/**
* Basic test. Assume the transfer is OK.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleCorrectTransfer(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
#$accountRepos->shouldReceive('getMetaValue')
# ->atLeast()->once()
# ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// currency repos
#$currencyRepos->shouldReceive('findNull')
# ->atLeast()->once()
# ->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
// assume all is well.
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('All transfers have correct currency information.')
->assertExitCode(0);
}
/**
* Journal has bad currency info.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleInvalidJournalCurrency(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$dollar = $this->getDollar();
$transfer->transaction_currency_id = $dollar->id;
$transfer->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
#$accountRepos->shouldReceive('getMetaValue')
# ->atLeast()->once()
# ->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// currency repos
#$currencyRepos->shouldReceive('findNull')
# ->atLeast()->once()
# ->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
$this->assertCount(1, TransactionJournal::where('id', $transfer->id)->where('transaction_currency_id', 1)->get());
}
/**
* Missing source foreign amount information.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleMissingSourceForeignAmount(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$dollar = $this->getDollar();
/** @var Transaction $destination */
$destination = $transfer->transactions()->where('amount', '>', 0)->first();
$destination->foreign_amount = '100';
$destination->save();
/** @var Transaction $destination */
$source = $transfer->transactions()->where('amount', '<', 0)->first();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([$dollar->id])->andReturn($dollar);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 2 transfer(s).')
->assertExitCode(0);
$this->assertCount(1, Transaction::where('id', $source->id)
->where('foreign_amount', '-100')->get()
);
}
/**
* Missing source foreign amount information.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleMissingDestForeignAmount(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$dollar = $this->getDollar();
/** @var Transaction $destination */
$destination = $transfer->transactions()->where('amount', '>', 0)->first();
$destination->foreign_amount = null;
$destination->save();
/** @var Transaction $destination */
$source = $transfer->transactions()->where('amount', '<', 0)->first();
$source->foreign_amount = '-100';
$source->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1', $dollar->id);
// currency repos
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([1])->andReturn($euro);
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([$dollar->id])->andReturn($dollar);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 3 transfer(s).')
->assertExitCode(0);
$this->assertCount(1, Transaction::where('id', $destination->id)
->where('foreign_amount', '100')->get()
);
}
/**
* Basic test. The foreign currency is broken and should be corrected.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleMismatchedForeignCurrency(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$dollar = $this->getDollar();
// make sure that source and destination have the right currencies beforehand
$source = $transfer->transactions()->where('amount', '<', 0)->first();
$source->transaction_currency_id = $euro->id;
$source->save();
$dest = $transfer->transactions()->where('amount', '>', 0)->first();
$dest->transaction_currency_id = $dollar->id;
$dest->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1', $dollar->id);
// currency repos
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([1])->andReturn($euro);
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([$dollar->id])->andReturn($dollar);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
// source and destination transaction should be corrected:
$this->assertCount(1, Transaction::where('id', $source->id)
->where('transaction_currency_id', $euro->id)
->where('foreign_currency_id', $dollar->id)
->get());
}
/**
* Basic test. Source transaction has no currency.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleTransferNoSourceCurrency(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// get source transaction and remove currency:
/** @var Transaction $source */
$source = $transfer->transactions()->where('amount', '<', 0)->first();
$source->transaction_currency_id = null;
$source->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
// currency repos
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
// assume problem is fixed:
$this->assertCount(1, Transaction::where('id', $source->id)->where('transaction_currency_id', 1)->get());
}
/**
* Basic test. Destination transaction has no currency.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleTransferNoDestCurrency(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
// get source transaction and remove currency:
/** @var Transaction $destination */
$destination = $transfer->transactions()->where('amount', '>', 0)->first();
$destination->transaction_currency_id = null;
$destination->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
// currency repos
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
// assume problem is fixed:
$this->assertCount(1, Transaction::where('id', $destination->id)->where('transaction_currency_id', 1)->get());
}
/**
* Basic test. Source transaction has bad currency.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleTransferBadSourceCurrency(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
// get source transaction and remove currency:
/** @var Transaction $source */
$source = $transfer->transactions()->where('amount', '<', 0)->first();
$source->transaction_currency_id = 2;
$source->foreign_amount = null;
$source->save();
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
// currency repos
$currencyRepos->shouldReceive('findNull')
->atLeast()->once()
->withArgs([1])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
// assume problem is fixed:
$this->assertCount(1, Transaction::where('id', $source->id)->where('transaction_currency_id', 1)->get());
}
/**
* Basic test. Source transaction has bad currency, and this must be fixed.
*
* TODO something in this test is too random, and it fails. Not sure why.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransferCurrenciesCorrections
*/
public function testHandleTransferBadDestCurrency(): void
{
Log::warning(sprintf('Now in test %s.', __METHOD__));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$euro = $this->getEuro();
$dollar = $this->getDollar();
// get destination transaction and remove currency:
$transfer->transaction_currency_id = $euro->id;
$transfer->save();
Log::debug(sprintf('Gave transfer #%d currency EUR', $transfer->id));
/** @var Transaction $destination */
$destination = $transfer->transactions()->where('amount', '>', 0)->first();
$destination->transaction_currency_id = $dollar->id;
$destination->save();
Log::debug(sprintf('Gave transaction #%d currency USD', $destination->id));
// mock calls:
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
// account repos
$accountRepos->shouldReceive('getMetaValue')
->atLeast()->once()
->withArgs([Mockery::any(), 'currency_id'])->andReturn((string)$euro->id);
// currency repos
$currencyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$euro->id])->andReturn($euro);
// configuration
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);
$this->artisan('firefly-iii:transfer-currencies')
->expectsOutput('Verified currency information of 1 transfer(s).')
->assertExitCode(0);
// assume problem is fixed:
$this->assertCount(1, Transaction::where('id', $destination->id)->where('transaction_currency_id', $euro->id)->get());
}
}