Refactor journal repositories.

This commit is contained in:
James Cole
2019-08-10 14:41:08 +02:00
parent 93f1854be0
commit 0097c66522
11 changed files with 454 additions and 353 deletions

View File

@@ -28,6 +28,7 @@ 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;
@@ -59,12 +60,13 @@ class MigrateToGroupsTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$service = $this->mock(JournalDestroyService::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// mock calls:
$journalRepos->shouldReceive('getSplitJournals')
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalsWithoutGroup')
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([]);
@@ -89,6 +91,7 @@ class MigrateToGroupsTest extends TestCase
$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();
@@ -121,10 +124,10 @@ class MigrateToGroupsTest extends TestCase
$array = $journal->toArray();
// mock calls:
$journalRepos->shouldReceive('getSplitJournals')
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalsWithoutGroup')
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([$array]);
@@ -203,19 +206,21 @@ class MigrateToGroupsTest extends TestCase
$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:
$journalRepos->shouldReceive('getJournalBudgetId')->atLeast()->once()->andReturn(0);
$journalRepos->shouldReceive('getJournalCategoryId')->atLeast()->once()->andReturn(0);
$journalRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Some note.');
$journalRepos->shouldReceive('getTags')->atLeast()->once()->andReturn(['A', 'B']);
$journalRepos->shouldReceive('getMetaField')->atLeast()
$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);
$journalRepos->shouldReceive('getMetaDate')->atLeast()
$cliRepos->shouldReceive('getMetaDate')->atLeast()
->withArgs([Mockery::any(), Mockery::any()])
->once()->andReturn(null);
@@ -225,10 +230,10 @@ class MigrateToGroupsTest extends TestCase
$factory->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('getSplitJournals')
$cliRepos->shouldReceive('getSplitJournals')
->atLeast()->once()
->andReturn(new Collection([$journal]));
$journalRepos->shouldReceive('getJournalsWithoutGroup')
$cliRepos->shouldReceive('getJournalsWithoutGroup')
->atLeast()->once()
->andReturn([]);

View File

@@ -107,11 +107,12 @@ class MigrateToRulesTest extends TestCase
*/
public function testHandleEvenBill(): void
{
$bill = Bill::create(
$billName = 'I am a bill #' . $this->randomInt();
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'transaction_currency_id' => null,
'name' => 'I am a bill',
'name' => $billName,
'match' => 'some,kind,of,match',
'amount_min' => '30',
'amount_max' => '30',
@@ -137,8 +138,8 @@ class MigrateToRulesTest extends TestCase
'active' => true,
'strict' => false,
'stop_processing' => false, // field is no longer used.
'title' => 'Auto-generated rule for bill "I am a bill"',
'description' => 'This rule is auto-generated to try to match bill "I am a bill".',
'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' => [
[
@@ -214,11 +215,12 @@ class MigrateToRulesTest extends TestCase
*/
public function testHandleUnevenBill(): void
{
$bill = Bill::create(
$billName = 'I am a bill #' . $this->randomInt();
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'transaction_currency_id' => null,
'name' => 'I am a bill',
'name' => $billName,
'match' => 'some,kind,of,match',
'amount_min' => '30',
'amount_max' => '40',
@@ -244,8 +246,8 @@ class MigrateToRulesTest extends TestCase
'active' => true,
'strict' => false,
'stop_processing' => false, // field is no longer used.
'title' => 'Auto-generated rule for bill "I am a bill"',
'description' => 'This rule is auto-generated to try to match bill "I am a bill".',
'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' => [
[

View File

@@ -26,6 +26,7 @@ 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;
@@ -54,9 +55,9 @@ class TransactionIdentifierTest extends TestCase
{
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// commands:
$journalRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
->atLeast()->once();
// configuration
@@ -127,9 +128,9 @@ class TransactionIdentifierTest extends TestCase
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
// commands:
$journalRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
->atLeast()->once();
// configuration