From cf121fea50be70180d3d40ebdd0dbe0d9d3aab45 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 3 Aug 2019 14:45:37 +0200 Subject: [PATCH] Improve test coverage. --- routes/breadcrumbs.php | 9 +- .../Controllers/PreferencesControllerTest.php | 75 +- .../Api/V1/Controllers/RuleControllerTest.php | 9 +- .../Controllers/RuleGroupControllerTest.php | 21 + .../Controllers/TransactionControllerTest.php | 4 + tests/TestCase.php | 9 +- .../Console/Commands/Tools/ApplyRulesTest.php | 38 + .../Upgrade/BudgetLimitCurrencyTest.php | 9 + .../Upgrade/RenameAccountMetaTest.php | 6 + tests/Unit/Factory/AccountFactoryTest.php | 86 +- .../Factory/TransactionJournalFactoryTest.php | 968 +----------------- .../Actions/ClearNotesTest.php | 2 + .../Actions/ConvertToDepositTest.php | 4 + .../Actions/ConvertToTransferTest.php | 15 +- .../Actions/ConvertToWithdrawalTest.php | 4 + .../RecurrenceTransformerTest.php | 8 +- 16 files changed, 296 insertions(+), 971 deletions(-) diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 0f10d4c14b..55e0dd4b5d 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -304,10 +304,13 @@ try { $object = $attachment->attachable; if ($object instanceof TransactionJournal) { $breadcrumbs->parent('transactions.show', $object->transactionGroup); - $breadcrumbs->push( - trans('firefly.delete_attachment', ['name' => limitStringLength($attachment->filename)]), route('attachments.edit', [$attachment]) - ); } + if ($object instanceof Bill) { + $breadcrumbs->parent('bills.show', $object); + } + $breadcrumbs->push( + trans('firefly.delete_attachment', ['name' => limitStringLength($attachment->filename)]), route('attachments.edit', [$attachment]) + ); } ); diff --git a/tests/Api/V1/Controllers/PreferencesControllerTest.php b/tests/Api/V1/Controllers/PreferencesControllerTest.php index 07a709be5c..de92ec84a1 100644 --- a/tests/Api/V1/Controllers/PreferencesControllerTest.php +++ b/tests/Api/V1/Controllers/PreferencesControllerTest.php @@ -28,6 +28,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Transformers\PreferenceTransformer; use Laravel\Passport\Passport; use Log; +use Mockery; use Preferences; use Tests\TestCase; @@ -59,6 +60,13 @@ class PreferencesControllerTest extends TestCase $transformer = $this->mock(PreferenceTransformer::class); $accountRepos = $this->mock(AccountRepositoryInterface::class); + // mock calls to preferences facade. + $pref = new Preference; + $pref->data = [1, 2, 3]; + + Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($pref); + Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', ['4', '5', '6']])->atLeast()->once()->andReturn($pref); + // mock calls to transformer: $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf(); @@ -67,10 +75,10 @@ class PreferencesControllerTest extends TestCase $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $accountRepos->shouldReceive('setUser')->atLeast()->once(); - /** @var Preference $preference */ - $preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]); - $data = ['data' => '4,5,6']; - $response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']); + ///** @var Preference $preference */ + //$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]); + $data = ['data' => '4,5,6']; + $response = $this->put(route('api.v1.preferences.update', ['frontPageAccounts']), $data, ['Accept' => 'application/json']); $response->assertStatus(200); } @@ -83,6 +91,21 @@ class PreferencesControllerTest extends TestCase $transformer = $this->mock(PreferenceTransformer::class); $accountRepos = $this->mock(AccountRepositoryInterface::class); + // mock calls to preferences facade. + $pref = new Preference; + $pref->data = false; + $countable = new Preference; + $countable->data = [1]; + + $saved = new Preference; + $saved->user_id = $this->user()->id; + $saved->name = 'twoFactorAuthEnabled'; + $saved->data = false; + $saved->save(); + + Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable); + Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['twoFactorAuthEnabled', '1'])->atLeast()->once()->andReturn($pref); + // mock calls to transformer: $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf(); @@ -92,12 +115,12 @@ class PreferencesControllerTest extends TestCase $accountRepos->shouldReceive('setUser')->atLeast()->once(); /** @var Preference $preference */ - $preference = Preferences::setForUser($this->user(), 'twoFactorAuthEnabled', false); - $data = ['data' => '1']; - $response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']); + $data = ['data' => '1']; + $response = $this->put(route('api.v1.preferences.update', ['twoFactorAuthEnabled']), $data, ['Accept' => 'application/json']); $response->assertStatus(200); + } /** @@ -116,10 +139,23 @@ class PreferencesControllerTest extends TestCase $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $accountRepos->shouldReceive('setUser')->atLeast()->once(); - /** @var Preference $preference */ - $preference = Preferences::setForUser($this->user(), 'currencyPreference', false); + // mock calls to preferences facade. + $pref = new Preference; + $pref->data = 'EUR'; + $countable = new Preference; + $countable->data = [1]; + + $saved = new Preference; + $saved->user_id = $this->user()->id; + $saved->name = 'twoFactorEnabled'; + $saved->data = false; + $saved->save(); + + Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable); + Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref); + $data = ['data' => 'EUR']; - $response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']); + $response = $this->put(route('api.v1.preferences.update', ['currencyPreference']), $data, ['Accept' => 'application/json']); $response->assertStatus(200); } @@ -140,10 +176,23 @@ class PreferencesControllerTest extends TestCase $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $accountRepos->shouldReceive('setUser')->atLeast()->once(); - /** @var Preference $preference */ - $preference = Preferences::setForUser($this->user(), 'listPageSize', 13); + // mock calls to preferences facade. + $pref = new Preference; + $pref->data = 'EUR'; + $countable = new Preference; + $countable->data = [1]; + + $saved = new Preference; + $saved->user_id = $this->user()->id; + $saved->name = 'listPageSize'; + $saved->data = 200; + $saved->save(); + + Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable); + Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['listPageSize', '434'])->atLeast()->once()->andReturn($pref); + $data = ['data' => '434']; - $response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']); + $response = $this->put(route('api.v1.preferences.update', ['listPageSize']), $data, ['Accept' => 'application/json']); $response->assertStatus(200); } diff --git a/tests/Api/V1/Controllers/RuleControllerTest.php b/tests/Api/V1/Controllers/RuleControllerTest.php index b7c4a19504..53471e2f5d 100644 --- a/tests/Api/V1/Controllers/RuleControllerTest.php +++ b/tests/Api/V1/Controllers/RuleControllerTest.php @@ -25,7 +25,7 @@ namespace Tests\Api\V1\Controllers; use FireflyIII\Helpers\Collector\GroupCollectorInterface; -use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions; +use FireflyIII\Models\Preference; use FireflyIII\Models\Rule; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; @@ -37,6 +37,7 @@ use Laravel\Passport\Passport; use Log; use Preferences; use Tests\TestCase; +use Mockery; /** * @@ -238,6 +239,12 @@ class RuleControllerTest extends TestCase $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 50; + + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref); + $response = $this->get(route('api.v1.rules.test', [$rule->id]) . '?accounts=1,2,3'); $response->assertStatus(200); diff --git a/tests/Api/V1/Controllers/RuleGroupControllerTest.php b/tests/Api/V1/Controllers/RuleGroupControllerTest.php index 550320959a..165350993c 100644 --- a/tests/Api/V1/Controllers/RuleGroupControllerTest.php +++ b/tests/Api/V1/Controllers/RuleGroupControllerTest.php @@ -27,6 +27,7 @@ namespace Tests\Api\V1\Controllers; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions; use FireflyIII\Jobs\Job; +use FireflyIII\Models\Preference; use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; @@ -38,6 +39,8 @@ use FireflyIII\Transformers\TransactionGroupTransformer; use Illuminate\Support\Collection; use Laravel\Passport\Passport; use Log; +use Mockery; +use Preferences; use Queue; use Tests\TestCase; @@ -89,6 +92,8 @@ class RuleGroupControllerTest extends TestCase $ruleGroupRepos->shouldReceive('store')->once()->andReturn($ruleGroup); + + // test API $response = $this->post(route('api.v1.rule_groups.store'), $data, ['Accept' => 'application/json']); $response->assertStatus(200); @@ -133,6 +138,13 @@ class RuleGroupControllerTest extends TestCase $matcher->shouldReceive('setAccounts')->once(); $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]); + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 50; + + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref); + + // call API $response = $this->get(route('api.v1.rule_groups.test', [$group->id]) . '?accounts=1,2,3'); $response->assertStatus(200); @@ -151,6 +163,13 @@ class RuleGroupControllerTest extends TestCase $ruleGroupRepos->shouldReceive('setUser')->once(); $ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection); + + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 50; + + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref); + // call API $group = $this->user()->ruleGroups()->first(); $response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']); @@ -198,6 +217,8 @@ class RuleGroupControllerTest extends TestCase $repository->shouldReceive('isAsset')->withArgs([1])->andReturn(true); $repository->shouldReceive('isAsset')->withArgs([2])->andReturn(false); + + $response = $this->post(route('api.v1.rule_groups.trigger', [$group->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02'); $response->assertStatus(204); diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php index f94f40f5d5..1082ba252e 100644 --- a/tests/Api/V1/Controllers/TransactionControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionControllerTest.php @@ -639,6 +639,8 @@ class TransactionControllerTest extends TestCase try { $this->expectsEvents(StoredTransactionGroup::class); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } @@ -856,6 +858,8 @@ class TransactionControllerTest extends TestCase try { $this->expectsEvents(UpdatedTransactionGroup::class); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 5d838e62b8..aa222715f6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -243,7 +243,8 @@ abstract class TestCase extends BaseTestCase try { $date = new Carbon; } catch (Exception $e) { - $e->getMessage(); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); } return [ @@ -286,7 +287,8 @@ abstract class TestCase extends BaseTestCase try { $date = new Carbon; } catch (Exception $e) { - $e->getMessage(); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); } return [ @@ -327,7 +329,8 @@ abstract class TestCase extends BaseTestCase try { $date = new Carbon; } catch (Exception $e) { - $e->getMessage(); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); } return [ diff --git a/tests/Unit/Console/Commands/Tools/ApplyRulesTest.php b/tests/Unit/Console/Commands/Tools/ApplyRulesTest.php index fe7b45d151..1f12494957 100644 --- a/tests/Unit/Console/Commands/Tools/ApplyRulesTest.php +++ b/tests/Unit/Console/Commands/Tools/ApplyRulesTest.php @@ -23,6 +23,7 @@ namespace Tests\Unit\Console\Commands\Tools; use FireflyIII\Helpers\Collector\GroupCollectorInterface; +use FireflyIII\Models\Preference; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; @@ -31,6 +32,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\TransactionRules\Engine\RuleEngine; use Illuminate\Support\Collection; use Log; +use Mockery; +use Preferences; use Tests\TestCase; /** @@ -100,6 +103,11 @@ class ApplyRulesTest extends TestCase '--all_rules', ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).') ->expectsOutput('Done!') @@ -159,6 +167,11 @@ class ApplyRulesTest extends TestCase '--all_rules', ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('No rules or rule groups have been included.') ->expectsOutput('Done!') @@ -218,6 +231,11 @@ class ApplyRulesTest extends TestCase '--end_date=2019-01-01', ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).') ->expectsOutput('Done!') @@ -281,6 +299,11 @@ class ApplyRulesTest extends TestCase sprintf('--rules=%d,%d', $activeRule->id, $inactiveRule->id), ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).') ->expectsOutput('Done!') @@ -343,6 +366,11 @@ class ApplyRulesTest extends TestCase sprintf('--rule_groups=%d,%d', $activeGroup->id, $inactiveGroup->id), ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput(sprintf('Will ignore inactive rule group #%d ("%s")', $inactiveGroup->id, $inactiveGroup->title)) // one rule out of 2 groups: @@ -379,6 +407,11 @@ class ApplyRulesTest extends TestCase '--all_rules', ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('Please use the --accounts option to indicate the accounts to apply rules to.') ->assertExitCode(1); @@ -417,6 +450,11 @@ class ApplyRulesTest extends TestCase '--all_rules', ]; + // mock Preferences Facade: + $pref = new Preference; + $pref->data = 'token'; + Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref); + $this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters)) ->expectsOutput('Please make sure all accounts in --accounts are asset accounts or liabilities.') ->assertExitCode(1); diff --git a/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php b/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php index 4f3d4ed410..bd10d590db 100644 --- a/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php +++ b/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php @@ -22,6 +22,7 @@ namespace Tests\Unit\Console\Commands\Upgrade; +use Amount; use FireflyConfig; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\Configuration; @@ -49,6 +50,11 @@ class BudgetLimitCurrencyTest extends TestCase { BudgetLimit::whereNull('transaction_currency_id')->forceDelete(); + $false = new Configuration; + $false->data = false; + FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false); + FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]); + $this->artisan('firefly-iii:bl-currency') ->expectsOutput('All budget limits are correct.') ->assertExitCode(0); @@ -74,6 +80,9 @@ class BudgetLimitCurrencyTest extends TestCase FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false); FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]); + $currency = $this->getEuro(); + Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency); + $this->artisan('firefly-iii:bl-currency') ->expectsOutput( sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).', diff --git a/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php b/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php index b6b6aa77ef..a534da8d53 100644 --- a/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php +++ b/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php @@ -49,6 +49,12 @@ class RenameAccountMetaTest extends TestCase */ public function testHandle(): void { + $false = new Configuration; + $false->data = false; + // check config + FireflyConfig::shouldReceive('get')->withArgs(['4780_rename_account_meta', false])->andReturn($false); + FireflyConfig::shouldReceive('set')->withArgs(['4780_rename_account_meta', true]); + // assume all is well. $this->artisan('firefly-iii:rename-account-meta') ->expectsOutput('All account meta is OK.') diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php index 80f26c088d..e034d9061b 100644 --- a/tests/Unit/Factory/AccountFactoryTest.php +++ b/tests/Unit/Factory/AccountFactoryTest.php @@ -24,10 +24,12 @@ declare(strict_types=1); namespace Tests\Unit\Factory; +use Amount; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountMetaFactory; +use FireflyIII\Factory\TransactionCurrencyFactory; use FireflyIII\Factory\TransactionGroupFactory; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; @@ -60,9 +62,11 @@ class AccountFactoryTest extends TestCase */ public function testCreate(): void { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $metaFactory = $this->mock(AccountMetaFactory::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); + $euro = $this->getEuro(); $data = [ 'account_type_id' => null, 'account_type' => 'asset', @@ -80,6 +84,8 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); + Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($euro); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -87,6 +93,8 @@ class AccountFactoryTest extends TestCase try { $account = $factory->create($data); } catch (FireflyException $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); return; @@ -110,9 +118,12 @@ class AccountFactoryTest extends TestCase */ public function testCreateCC(): void { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $metaFactory = $this->mock(AccountMetaFactory::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); + + $data = [ 'account_type_id' => null, 'account_type' => 'asset', @@ -133,6 +144,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'cc_monthly_payment_date', '2018-01-01'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'cc_type', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -140,6 +152,8 @@ class AccountFactoryTest extends TestCase try { $account = $factory->create($data); } catch (FireflyException $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); return; @@ -163,8 +177,10 @@ class AccountFactoryTest extends TestCase */ public function testCreateEmptyVb(): void { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $metaFactory = $this->mock(AccountMetaFactory::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $this->mock(TransactionGroupFactory::class); $data = [ 'account_type_id' => null, @@ -183,6 +199,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -190,6 +207,8 @@ class AccountFactoryTest extends TestCase try { $account = $factory->create($data); } catch (FireflyException $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); return; @@ -216,6 +235,8 @@ class AccountFactoryTest extends TestCase { $this->mock(AccountRepositoryInterface::class); $this->mock(TransactionGroupFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $metaFactory = $this->mock(AccountMetaFactory::class); $data = [ 'account_type_id' => null, @@ -233,6 +254,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -240,6 +262,8 @@ class AccountFactoryTest extends TestCase try { $account = $factory->create($data); } catch (FireflyException $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); return; @@ -270,8 +294,9 @@ class AccountFactoryTest extends TestCase { $this->mock(AccountRepositoryInterface::class); $this->mock(TransactionGroupFactory::class); - $metaFactory = $this->mock(AccountMetaFactory::class); - $data = [ + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $data = [ 'account_type_id' => null, 'account_type' => 'Expense account', 'iban' => null, @@ -291,10 +316,13 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); try { $account = $factory->create($data); } catch (FireflyException $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); return; @@ -322,10 +350,12 @@ class AccountFactoryTest extends TestCase */ public function testCreateOB(): void { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $groupFactory = $this->mock(TransactionGroupFactory::class); - $metaFactory = $this->mock(AccountMetaFactory::class); - $data = [ + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $groupFactory = $this->mock(TransactionGroupFactory::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $euro = $this->getEuro(); + $data = [ 'account_type_id' => null, 'account_type' => 'asset', 'iban' => null, @@ -348,6 +378,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -378,10 +409,12 @@ class AccountFactoryTest extends TestCase public function testCreateOBZero(): void { // mock repositories: - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $groupFactory = $this->mock(TransactionGroupFactory::class); - $metaFactory = $this->mock(AccountMetaFactory::class); - $data = [ + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $groupFactory = $this->mock(TransactionGroupFactory::class); + $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $euro = $this->getEuro(); + $data = [ 'account_type_id' => null, 'account_type' => 'asset', 'iban' => null, @@ -404,6 +437,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -438,6 +472,7 @@ class AccountFactoryTest extends TestCase { $accountRepos = $this->mock(AccountRepositoryInterface::class); $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); $data = [ 'account_type_id' => null, @@ -457,6 +492,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -490,6 +526,7 @@ class AccountFactoryTest extends TestCase { $accountRepos = $this->mock(AccountRepositoryInterface::class); $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); $data = [ 'account_type_id' => null, @@ -509,7 +546,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); - + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -543,6 +580,8 @@ class AccountFactoryTest extends TestCase $accountRepos = $this->mock(AccountRepositoryInterface::class); $groupFactory = $this->mock(TransactionGroupFactory::class); $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $euro = $this->getEuro(); $data = [ 'account_type_id' => null, 'account_type' => 'asset', @@ -566,6 +605,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro); /** @var AccountFactory $factory */ @@ -600,6 +640,7 @@ class AccountFactoryTest extends TestCase { $accountRepos = $this->mock(AccountRepositoryInterface::class); $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); $data = [ 'account_type_id' => null, @@ -624,7 +665,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); - + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); try { $account = $factory->create($data); @@ -656,6 +697,8 @@ class AccountFactoryTest extends TestCase $accountRepos = $this->mock(AccountRepositoryInterface::class); $metaFactory = $this->mock(AccountMetaFactory::class); $this->mock(TransactionGroupFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); + $currency = $this->getDollar(); $data = [ 'account_type_id' => null, @@ -676,7 +719,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', $currency->id])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); - + $currencyFactory->shouldReceive('find')->withArgs([0, 'USD'])->atLeast()->once()->andReturn($currency); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -710,6 +753,7 @@ class AccountFactoryTest extends TestCase { $accountRepos = $this->mock(AccountRepositoryInterface::class); $metaFactory = $this->mock(AccountMetaFactory::class); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $this->mock(TransactionGroupFactory::class); $currency = $this->getDollar(); $data = [ @@ -731,7 +775,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', $currency->id])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); - + $currencyFactory->shouldReceive('find')->withArgs([7, ''])->atLeast()->once()->andReturn($currency); /** @var AccountFactory $factory */ $factory = app(AccountFactory::class); @@ -858,6 +902,7 @@ class AccountFactoryTest extends TestCase $metaFactory = $this->mock(AccountMetaFactory::class); /** @var Account $account */ $account = $this->getRandomRevenue(); + $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull(); @@ -865,6 +910,7 @@ class AccountFactoryTest extends TestCase $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull(); $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull(); + $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull(); $name = sprintf('New %s', $account->name); diff --git a/tests/Unit/Factory/TransactionJournalFactoryTest.php b/tests/Unit/Factory/TransactionJournalFactoryTest.php index 77c66be79a..8601b69552 100644 --- a/tests/Unit/Factory/TransactionJournalFactoryTest.php +++ b/tests/Unit/Factory/TransactionJournalFactoryTest.php @@ -44,6 +44,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface; +use FireflyIII\Validation\AccountValidator; use Log; use Tests\TestCase; @@ -82,6 +83,7 @@ class TransactionJournalFactoryTest extends TestCase $accountFactory = $this->mock(AccountFactory::class); $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); + $validator = $this->mock(AccountValidator::class); $submission = []; // mock calls to all repositories @@ -129,6 +131,14 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + + + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); + // data @@ -218,13 +228,16 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data - $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first(); $deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first(); $asset = $this->getRandomAsset(); - $expense = $this->getRandomExpense(); $revenue = $this->getRandomRevenue(); $euro = $this->getEuro(); $submission = [ @@ -309,7 +322,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first(); @@ -401,7 +419,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first(); @@ -494,7 +517,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first(); @@ -588,7 +616,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first(); @@ -681,7 +714,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first(); @@ -777,7 +815,12 @@ class TransactionJournalFactoryTest extends TestCase $currencyFactory = $this->mock(TransactionCurrencyFactory::class); $metaFactory = $this->mock(TransactionJournalMetaFactory::class); $transactionFactory = $this->mock(TransactionFactory::class); + $validator = $this->mock(AccountValidator::class); + $validator->shouldReceive('setUser')->atLeast()->once(); + $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']); + $validator->shouldReceive('validateSource')->atLeast()->once()->andReturnTrue(); + $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturnTrue(); // data $transfer = TransactionType::where('type', TransactionType::TRANSFER)->first(); @@ -850,925 +893,4 @@ class TransactionJournalFactoryTest extends TestCase $this->assertEquals($first->description, $submission['transactions'][0]['description']); $first->forceDelete(); } - - - -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testBudget(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $usd = TransactionCurrency::whereCode('USD')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// $budget = Budget::first(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// 'foreign_currency_code' => 'USD', -// 'foreign_amount' => '2', -// 'notes' => 'I am some notes', -// 'budget_id' => $budget->id, -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, 'USD'])->once()->andReturn($usd); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, $budget->id, null])->once()->andReturn($budget); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(1, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// $this->assertEquals('I am some notes', $journal->notes->first()->text); -// $this->assertEquals('EUR', $journal->transactions->first()->transactionCurrency->code); -// $this->assertEquals('USD', $journal->transactions->first()->foreignCurrency->code); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCategory(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $usd = TransactionCurrency::whereCode('USD')->first(); -// $asset = $this->getRandomAsset(); -// $category = Category::first(); -// $expense = $this->getRandomExpense(); -// $budget = Budget::first(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// 'foreign_currency_code' => 'USD', -// 'foreign_amount' => '2', -// 'notes' => 'I am some notes', -// 'budget_id' => $budget->id, -// 'category_name' => $category->name, -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, 'USD'])->once()->andReturn($usd); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, $budget->id, null])->once()->andReturn($budget); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, $category->name])->once()->andReturn($category); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(1, $journal->budgets); -// $this->assertCount(1, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// $this->assertEquals('I am some notes', $journal->notes->first()->text); -// $this->assertEquals('EUR', $journal->transactions->first()->transactionCurrency->code); -// $this->assertEquals('USD', $journal->transactions->first()->foreignCurrency->code); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCreateAlmostEmpty(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCreateAlmostEmptyTransfer(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::TRANSFER)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $source = $this->getRandomAsset(); -// $destination = $this->getAnotherRandomAsset($source->id); -// -// // data to submit. -// $data = [ -// 'type' => 'transfer', -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $source->id, -// 'destination_id' => $destination->id, -// 'amount' => '1', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the piggy bank repository: -// $piggyRepos->shouldReceive('findPiggyBank')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$source->id])->once()->andReturn($source); -// $accountRepos->shouldReceive('findNull')->withArgs([$destination->id])->once()->andReturn($destination); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCreateBasicGroup(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// ], -// // second transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->times(2); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->times(2)->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->times(2)->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->times(2)->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->times(2)->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->times(2)->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->times(2)->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// -// // collection should have two journals. -// $this->assertCount(2, $collection); -// -// // journal should have some props. -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// -// // group of journal should also have some props. -// /** @var TransactionGroup $group */ -// $group = $journal->transactionGroups()->first(); -// $this->assertCount(2, $group->transactionJournals); -// $this->assertEquals($journal->description, $group->title); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCreateEmpty(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $transactionFactory = $this->mock(TransactionFactory::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// -// // data to submit. -// $data = []; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $transactionFactory->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// $this->assertCount(0, $collection); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testCreatePiggyEvent(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::TRANSFER)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $piggyBank = PiggyBank::first(); -// $source = $this->getRandomAsset(); -// $destination = $this->getAnotherRandomAsset($source->id); -// -// // data to submit. -// $data = [ -// 'type' => 'transfer', -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $source->id, -// 'destination_id' => $destination->id, -// 'amount' => '1', -// 'piggy_bank_id' => '1', -// 'piggy_bank_name' => 'Some name', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, 'transfer'])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the piggy bank repository: -// $piggyRepos->shouldReceive('findPiggyBank')->withArgs([null, 1, 'Some name'])->once()->andReturn($piggyBank); -// -// // calls to the piggy factory -// $eventFactory->shouldReceive('create')->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$source->id])->once()->andReturn($source); -// $accountRepos->shouldReceive('findNull')->withArgs([$destination->id])->once()->andReturn($destination); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testForeignCurrency(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $usd = TransactionCurrency::whereCode('USD')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// 'foreign_currency_code' => 'USD', -// 'foreign_amount' => '2', -// 'notes' => 'I am some notes', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, 'USD'])->once()->andReturn($usd); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// $this->assertEquals('I am some notes', $journal->notes->first()->text); -// $this->assertEquals('EUR', $journal->transactions->first()->transactionCurrency->code); -// $this->assertEquals('USD', $journal->transactions->first()->foreignCurrency->code); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testNotes(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// 'notes' => 'I am some notes', -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// $this->assertEquals('I am some notes', $journal->notes->first()->text); -// } -// -// /** -// * @covers \FireflyIII\Factory\TransactionJournalFactory -// */ -// public function testTags(): void -// { -// $this->markTestIncomplete('Needs to be rewritten for v4.8.0'); -// -// return; -// // mock used repositories. -// $billRepos = $this->mock(BillRepositoryInterface::class); -// $budgetRepos = $this->mock(BudgetRepositoryInterface::class); -// $catRepos = $this->mock(CategoryRepositoryInterface::class); -// $curRepos = $this->mock(CurrencyRepositoryInterface::class); -// $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); -// $typeRepos = $this->mock(TransactionTypeRepositoryInterface::class); -// $eventFactory = $this->mock(PiggyBankEventFactory::class); -// $tagFactory = $this->mock(TagFactory::class); -// $accountFactory = $this->mock(AccountFactory::class); -// $currencyFactory = $this->mock(TransactionCurrencyFactory::class); -// $metaFactory = $this->mock(TransactionJournalMetaFactory::class); -// $accountRepos = $this->mock(AccountRepositoryInterface::class); -// -// // data to return from various calls: -// $type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); -// $euro = TransactionCurrency::whereCode('EUR')->first(); -// $asset = $this->getRandomAsset(); -// $expense = $this->getRandomExpense(); -// $tag = Tag::first(); -// -// // data to submit. -// $data = [ -// 'transactions' => [ -// // first transaction: -// [ -// 'source_id' => $asset->id, -// 'amount' => '1', -// 'tags' => ['tagA', 'B', '', 'C'], -// ], -// ], -// ]; -// -// // calls to setUser: -// $curRepos->shouldReceive('setUser')->once(); -// $billRepos->shouldReceive('setUser')->once(); -// $budgetRepos->shouldReceive('setUser')->once(); -// $catRepos->shouldReceive('setUser')->once(); -// $piggyRepos->shouldReceive('setUser')->once(); -// $accountRepos->shouldReceive('setUser')->once(); -// $tagFactory->shouldReceive('setUser')->once(); -// -// // calls to transaction type repository. -// $typeRepos->shouldReceive('findTransactionType')->withArgs([null, null])->once()->andReturn($type); -// -// // calls to the currency repository: -// $curRepos->shouldReceive('findCurrency')->withArgs([null, null, null])->once()->andReturn($euro); -// -// // calls to the bill repository: -// $billRepos->shouldReceive('findBill')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the budget repository -// $budgetRepos->shouldReceive('findBudget')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the category repository -// $catRepos->shouldReceive('findCategory')->withArgs([null, null, null])->once()->andReturnNull(); -// -// // calls to the account repository -// $accountRepos->shouldReceive('findNull')->withArgs([$asset->id])->once()->andReturn($asset); -// $accountRepos->shouldReceive('getCashAccount')->once()->andReturn($expense); -// -// // calls to tag factory -// $tagFactory->shouldReceive('findOrCreate')->once()->withArgs(['tagA'])->andReturn($tag); -// $tagFactory->shouldReceive('findOrCreate')->once()->withArgs(['B'])->andReturn($tag); -// $tagFactory->shouldReceive('findOrCreate')->once()->withArgs(['C'])->andReturnNull(); -// -// // calls to the meta factory: -// $metaFactory->shouldReceive('updateOrCreate')->atLeast()->once()->andReturnNull(); -// -// /** @var TransactionJournalFactory $factory */ -// $factory = app(TransactionJournalFactory::class); -// $factory->setUser($this->user()); -// $collection = $factory->create($data); -// -// /** @var TransactionJournal $journal */ -// $journal = $collection->first(); -// // collection should have one journal. -// $this->assertCount(1, $collection); -// $this->assertInstanceOf(TransactionJournal::class, $journal); -// $this->assertEquals('(empty description)', $journal->description); -// $this->assertCount(0, $journal->budgets); -// $this->assertCount(0, $journal->categories); -// $this->assertCount(2, $journal->transactions); -// $this->assertCount(1, $journal->tags); // we return the same tag every time. -// } -// -// /** -// * @param int $id -// * -// * @return Account -// */ -// private function getAnotherRandomAsset(int $id): Account -// { -// -// $query = Account:: -// leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') -// ->whereNull('accounts.deleted_at') -// ->where('accounts.user_id', $this->user()->id) -// ->where('account_types.type', AccountType::ASSET) -// ->where('accounts.id', '!=', $id) -// ->inRandomOrder()->take(1); -// -// return $query->first(['accounts.*']); -// } - } diff --git a/tests/Unit/TransactionRules/Actions/ClearNotesTest.php b/tests/Unit/TransactionRules/Actions/ClearNotesTest.php index 7312c451ba..3379ef87b2 100644 --- a/tests/Unit/TransactionRules/Actions/ClearNotesTest.php +++ b/tests/Unit/TransactionRules/Actions/ClearNotesTest.php @@ -68,6 +68,8 @@ class ClearNotesTest extends TestCase try { $result = $action->act($journal); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); diff --git a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php b/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php index 1aa250a2b9..79190b0d90 100644 --- a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php +++ b/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php @@ -75,6 +75,8 @@ class ConvertToDepositTest extends TestCase try { $result = $action->act($journal); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); @@ -111,6 +113,8 @@ class ConvertToDepositTest extends TestCase try { $result = $action->act($journal); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); diff --git a/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php b/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php index 2f7f03f6de..a369fb30f7 100644 --- a/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php +++ b/tests/Unit/TransactionRules/Actions/ConvertToTransferTest.php @@ -64,7 +64,10 @@ class ConvertToTransferTest extends TestCase // mock used stuff: $accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos->shouldReceive('setUser')->once(); - $accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($asset); + $accountRepos->shouldReceive('findByName')->withArgs( + [$asset->name, + [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]] + )->andReturn($asset); // fire the action: $rule = new Rule; @@ -77,6 +80,8 @@ class ConvertToTransferTest extends TestCase try { $result = $action->act($deposit); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); @@ -94,8 +99,10 @@ class ConvertToTransferTest extends TestCase public function testActWithdrawal(): void { $withdrawal = $this->getRandomWithdrawal(); - /** @var Account $asset */ - $asset = $this->getRandomAsset(); + + // make sure that $asset is not the source account of $withdrawal: + $forbiddenId = (int)$withdrawal->transactions()->where('amount', '<', 0)->first()->account_id; + $asset = $this->getRandomAsset($forbiddenId); // mock used stuff: $accountRepos = $this->mock(AccountRepositoryInterface::class); @@ -113,6 +120,8 @@ class ConvertToTransferTest extends TestCase try { $result = $action->act($withdrawal); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); diff --git a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php b/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php index 5260327622..d65c447d6c 100644 --- a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php +++ b/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php @@ -75,6 +75,8 @@ class ConvertToWithdrawalTest extends TestCase try { $result = $action->act($deposit); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); @@ -108,6 +110,8 @@ class ConvertToWithdrawalTest extends TestCase try { $result = $action->act($transfer); } catch (Exception $e) { + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); $this->assertTrue(false, $e->getMessage()); } $this->assertTrue($result); diff --git a/tests/Unit/Transformers/RecurrenceTransformerTest.php b/tests/Unit/Transformers/RecurrenceTransformerTest.php index 5628ab695a..c0331d5656 100644 --- a/tests/Unit/Transformers/RecurrenceTransformerTest.php +++ b/tests/Unit/Transformers/RecurrenceTransformerTest.php @@ -25,8 +25,6 @@ namespace Tests\Unit\Transformers; use Carbon\Carbon; use FireflyIII\Factory\CategoryFactory; -use FireflyIII\Models\RecurrenceTransaction; -use FireflyIII\Models\RecurrenceTransactionMeta; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; @@ -81,9 +79,9 @@ class RecurrenceTransformerTest extends TestCase $recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr'); $recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once(); $factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null,Mockery::any()])->andReturn($category); - $budgetRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([2])->andReturn($budget); - $piggyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($piggy); - $billRepos->shouldReceive('find')->atLeast()->once()->withArgs([1])->andReturn($bill); + $budgetRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($budget); + $piggyRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($piggy); + $billRepos->shouldReceive('find')->andReturn($bill); // basic transformation: