Fix tests

This commit is contained in:
James Cole
2019-08-11 07:25:59 +02:00
parent c4964cf603
commit 8545d73119
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\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -61,6 +62,8 @@ class OtherCurrenciesCorrections extends Command
private $currencyRepos; private $currencyRepos;
/** @var JournalRepositoryInterface */ /** @var JournalRepositoryInterface */
private $journalRepos; private $journalRepos;
/** @var JournalCLIRepositoryInterface */
private $cliRepos;
/** @var int */ /** @var int */
private $count; private $count;
@@ -105,6 +108,7 @@ class OtherCurrenciesCorrections extends Command
$this->accountRepos = app(AccountRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->journalRepos = app(JournalRepositoryInterface::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->accountRepos->setUser($journal->user);
$this->journalRepos->setUser($journal->user); $this->journalRepos->setUser($journal->user);
$this->currencyRepos->setUser($journal->user); $this->currencyRepos->setUser($journal->user);
$this->cliRepos->setUser($journal->user);
$leadTransaction = $this->getLeadTransaction($journal); $leadTransaction = $this->getLeadTransaction($journal);
@@ -223,7 +228,7 @@ class OtherCurrenciesCorrections extends Command
private function updateOtherJournalsCurrencies(): void private function updateOtherJournalsCurrencies(): void
{ {
$set = $set =
$this->journalRepos->getAllJournals( $this->cliRepos->getAllJournals(
[ [
TransactionType::WITHDRAWAL, TransactionType::WITHDRAWAL,
TransactionType::DEPOSIT, TransactionType::DEPOSIT,

View File

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

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@@ -59,6 +60,7 @@ class OtherCurrenciesCorrectionsTest extends TestCase
// mock classes: // mock classes:
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
@@ -66,7 +68,8 @@ class OtherCurrenciesCorrectionsTest extends TestCase
// collect all journals: // collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once(); $journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('getAllJournals') $cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once() ->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]]) ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$withdrawal, $deposit])); ->andReturn(new Collection([$withdrawal, $deposit]));
@@ -136,11 +139,13 @@ class OtherCurrenciesCorrectionsTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$euro = $this->getEuro(); $euro = $this->getEuro();
// collect all journals: // collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once(); $journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('getAllJournals') $cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once() ->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]]) ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal])); ->andReturn(new Collection([$journal]));
@@ -219,11 +224,13 @@ class OtherCurrenciesCorrectionsTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
$euro = $this->getEuro(); $euro = $this->getEuro();
// collect all journals: // collect all journals:
$journalRepos->shouldReceive('setUser')->atLeast()->once(); $journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('getAllJournals') $cliRepos->shouldReceive('setUser')->atLeast()->once();
$cliRepos->shouldReceive('getAllJournals')
->atLeast()->once() ->atLeast()->once()
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]]) ->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]])
->andReturn(new Collection([$journal])); ->andReturn(new Collection([$journal]));

View File

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