mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Refactor journal repository and fix tests.
This commit is contained in:
@@ -28,6 +28,7 @@ use Exception;
|
||||
use FireflyIII\Events\StoredTransactionGroup;
|
||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
@@ -69,11 +70,13 @@ class TransactionControllerTest extends TestCase
|
||||
// mock repository
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -120,10 +123,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -173,10 +178,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -224,10 +231,13 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -275,10 +285,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -327,10 +339,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -381,11 +395,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$data = [
|
||||
'transactions' => [
|
||||
],
|
||||
@@ -420,10 +435,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -480,10 +497,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -542,10 +561,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['transfer'])->atLeast()->once();
|
||||
@@ -609,11 +630,13 @@ class TransactionControllerTest extends TestCase
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// validator:
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
@@ -689,10 +712,12 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
@@ -750,6 +775,7 @@ class TransactionControllerTest extends TestCase
|
||||
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
|
||||
@@ -759,6 +785,7 @@ class TransactionControllerTest extends TestCase
|
||||
// some mock calls:
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'group_title' => 'Empty',
|
||||
@@ -815,6 +842,7 @@ class TransactionControllerTest extends TestCase
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
$validator = $this->mock(AccountValidator::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
|
||||
|
||||
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
|
||||
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
|
||||
@@ -824,6 +852,7 @@ class TransactionControllerTest extends TestCase
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$apiRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// call stuff:
|
||||
$repository->shouldReceive('update')->atLeast()->once()->andReturn($group);
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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';
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user