Refactor journal repository and fix tests.

This commit is contained in:
James Cole
2019-08-10 13:42:33 +02:00
parent b7f3c53688
commit 93f1854be0
14 changed files with 286 additions and 130 deletions

View File

@@ -410,7 +410,7 @@ class AccountFactoryTest extends TestCase
{
// mock repositories:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
@@ -429,8 +429,6 @@ class AccountFactoryTest extends TestCase
// mock calls to the repository:
$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);
$groupFactory->shouldReceive('setUser')->atLeast()->once();
$groupFactory->shouldReceive('create')->atLeast()->once();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();

View File

@@ -82,7 +82,8 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -156,7 +157,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -250,7 +251,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -358,7 +359,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -469,7 +470,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -582,7 +583,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -700,7 +701,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -788,7 +789,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -867,7 +868,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
$meta = new TransactionJournalMeta;
$meta->transaction_journal_id = 1;
@@ -954,7 +955,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@@ -1047,7 +1048,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job

View File

@@ -28,6 +28,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Rules\IsValidAttachmentModel;
use Log;
@@ -88,11 +89,11 @@ class IsValidAttachmentModelTest extends TestCase
*/
public function testTransaction(): void
{
$transaction = $this->getRandomWithdrawal()->transactions()->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$transaction = $this->getRandomWithdrawal()->transactions()->first();
$apiJournalRepos = $this->mock(JournalAPIRepositoryInterface::class);
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
$apiJournalRepos->shouldReceive('setUser')->atLeast()->once();
$apiJournalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
$value = $transaction->id;
$attribute = 'not-important';

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetBudget;
use Illuminate\Support\Collection;
@@ -42,9 +41,6 @@ class SetBudgetTest extends TestCase
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
@@ -65,17 +61,13 @@ class SetBudgetTest extends TestCase
{
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $budget->name;
$ruleAction->action_value = 'non-existing budget #' . $this->randomInt();
$action = new SetBudget($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
@@ -91,9 +83,6 @@ class SetBudgetTest extends TestCase
// get journal, remove all budgets
$journal = $this->getRandomDeposit();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());