Fix tests

This commit is contained in:
James Cole 2019-08-11 07:25:59 +02:00
parent c4964cf603
commit 8545d73119
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 38 additions and 15 deletions

View File

@ -31,6 +31,7 @@ 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\Console\Command;
@ -61,6 +62,8 @@ class OtherCurrenciesCorrections extends Command
private $currencyRepos;
/** @var JournalRepositoryInterface */
private $journalRepos;
/** @var JournalCLIRepositoryInterface */
private $cliRepos;
/** @var int */
private $count;
@ -105,6 +108,7 @@ class OtherCurrenciesCorrections extends Command
$this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->journalRepos = app(JournalRepositoryInterface::class);
$this->cliRepos = app(JournalCLIRepositoryInterface::class);
}
/**
@ -166,6 +170,7 @@ class OtherCurrenciesCorrections extends Command
$this->accountRepos->setUser($journal->user);
$this->journalRepos->setUser($journal->user);
$this->currencyRepos->setUser($journal->user);
$this->cliRepos->setUser($journal->user);
$leadTransaction = $this->getLeadTransaction($journal);
@ -223,7 +228,7 @@ class OtherCurrenciesCorrections extends Command
private function updateOtherJournalsCurrencies(): void
{
$set =
$this->journalRepos->getAllJournals(
$this->cliRepos->getAllJournals(
[
TransactionType::WITHDRAWAL,
TransactionType::DEPOSIT,

View File

@ -242,7 +242,7 @@ class TransferCurrenciesCorrections extends Command
*/
private function startUpdateRoutine(): void
{
$set = $this->journalRepos->getAllJournals([TransactionType::TRANSFER]);
$set = $this->cliRepos->getAllJournals([TransactionType::TRANSFER]);
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
$this->updateTransferCurrency($journal);

View File

@ -29,6 +29,7 @@ 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;
@ -59,6 +60,7 @@ class OtherCurrenciesCorrectionsTest extends TestCase
// 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();
@ -66,7 +68,8 @@ class OtherCurrenciesCorrectionsTest extends TestCase
// collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('getAllJournals')
$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]));
@ -136,11 +139,13 @@ class OtherCurrenciesCorrectionsTest extends TestCase
$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();
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal]));
@ -219,11 +224,13 @@ class OtherCurrenciesCorrectionsTest extends TestCase
$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();
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal]));

View File

@ -29,6 +29,7 @@ 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;
@ -60,9 +61,10 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection);
@ -89,11 +91,12 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -130,6 +133,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -137,7 +141,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$transfer->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -175,6 +179,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -188,7 +193,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$source = $transfer->transactions()->where('amount', '<', 0)->first();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -233,6 +238,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -248,7 +254,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$source->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -293,6 +299,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -307,7 +314,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$dest->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -356,6 +363,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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 */
@ -364,7 +372,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$source->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -403,6 +411,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -413,7 +422,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$destination->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -451,6 +460,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -462,7 +472,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$source->save();
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));
@ -503,6 +513,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
$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();
@ -521,7 +532,7 @@ class TransferCurrenciesCorrectionsTest extends TestCase
Log::debug(sprintf('Gave transaction #%d currency USD', $destination->id));
// mock calls:
$journalRepos->shouldReceive('getAllJournals')
$cliRepos->shouldReceive('getAllJournals')
->withArgs([[TransactionType::TRANSFER]])
->atLeast()->once()->andReturn(new Collection([$transfer]));