Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Improve test coverage.
James Cole19feefda2de0
diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.phpindex 50443d0af0..57cb6b73c5 100644--- a/app/Api/V1/Requests/RecurrenceStoreRequest.php+++ b/app/Api/V1/Requests/RecurrenceStoreRequest.php@@ -210,7 +210,7 @@ class RecurrenceStoreRequest extends Request// new and updated fields:'piggy_bank_id' => isset($transaction['piggy_bank_id']) ? (int)$transaction['piggy_bank_id'] : null,'piggy_bank_name' => $transaction['piggy_bank_name'] ?? null,- 'tags' => $transaction['tags'],+ 'tags' => $transaction['tags'] ?? [],'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null,'budget_name' => $transaction['budget_name'] ?? null,'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null,diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.phpindex 09a84b3113..728e78b4de 100644--- a/app/Console/Commands/Upgrade/BackToJournals.php+++ b/app/Console/Commands/Upgrade/BackToJournals.php@@ -29,6 +29,7 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use Illuminate\Console\Command;use Illuminate\Support\Collection;+use Log;/*** Class BackToJournals@@ -109,9 +110,11 @@ class BackToJournals extends Command$chunks = array_chunk($transactions, 500);foreach ($chunks as $chunk) {- $set = DB::table('transactions')- ->whereIn('transactions.id', $transactions)- ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();+ $set = DB::table('transactions')+ ->whereIn('transactions.id', $chunk)+ ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();+ /** @noinspection SlowArrayOperationsInLoopInspection */+ $array = array_merge($array, $set);}return $array;@@ -156,6 +159,7 @@ class BackToJournals extends Command*/private function migrateAll(): void{+ Log::debug('Now in migrateAll()');$this->migrateBudgets();$this->migrateCategories();@@ -224,11 +228,16 @@ class BackToJournals extends Command*/private function migrateCategories(): void{+ Log::debug('Now in migrateCategories()');$journals = new Collection;$allIds = $this->getIdsForCategories();- $chunks = array_chunk($allIds, 500);- foreach ($chunks as $journalIds) {- $collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'categories', 'transactions.categories'])->get();++ Log::debug(sprintf('Total: %d', count($allIds)));++ $chunks = array_chunk($allIds, 500);+ foreach ($chunks as $chunk) {+ Log::debug('Now doing a chunk.');+ $collected = TransactionJournal::whereIn('id', $chunk)->with(['transactions', 'categories', 'transactions.categories'])->get();$journals = $journals->merge($collected);}$this->line(sprintf('Check %d transaction journal(s) for category info.', count($journals)));diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.phpindex fc047ee06e..0e484418f5 100644--- a/app/Exceptions/GracefulNotFoundHandler.php+++ b/app/Exceptions/GracefulNotFoundHandler.php@@ -60,7 +60,7 @@ class GracefulNotFoundHandler extends ExceptionHandlerswitch ($name) {default:- Log::error(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name));+ Log::debug(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name));return parent::render($request, $exception);case 'accounts.show':diff --git a/app/Factory/RecurrenceFactory.php b/app/Factory/RecurrenceFactory.phpindex f7cfb2f9d5..33a4f60431 100644--- a/app/Factory/RecurrenceFactory.php+++ b/app/Factory/RecurrenceFactory.php@@ -96,7 +96,6 @@ class RecurrenceFactory);$recurrence->save();- //$this->updateMetaData($recurrence, $data);$this->createRepetitions($recurrence, $data['repetitions'] ?? []);try {$this->createTransactions($recurrence, $data['transactions'] ?? []);diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.phpindex acbc5a7a64..ee14c94334 100644--- a/app/Http/Controllers/Recurring/EditController.php+++ b/app/Http/Controllers/Recurring/EditController.php@@ -129,7 +129,7 @@ class EditController extends Controller'withdrawal_destination_id' => $array['transactions'][0]['destination_id'],];- $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags']);+ $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags'] ?? []);return view('recurring.edit',diff --git a/app/Import/Storage/ImportArrayStorage.php b/app/Import/Storage/ImportArrayStorage.phpindex 211b075e2b..0c42ebf815 100644--- a/app/Import/Storage/ImportArrayStorage.php+++ b/app/Import/Storage/ImportArrayStorage.php@@ -583,7 +583,6 @@ class ImportArrayStorageDB::table('tag_transaction_journal')->insert(['transaction_journal_id' => $journalId, 'tag_id' => $tagId]);} catch (QueryException $e) {Log::error(sprintf('Could not link journal #%d to tag #%d because: %s', $journalId, $tagId, $e->getMessage()));- Log::error($e->getTraceAsString());}// @codeCoverageIgnoreEnd}diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex caf385c9f2..1fe38bf43f 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -518,7 +518,9 @@ class AccountRepository implements AccountRepositoryInterface*/public function searchAccount(string $query, array $types): Collection{- $dbQuery = $this->user->accounts()->with(['accountType']);+ $dbQuery = $this->user->accounts()+ ->where('active', 1)+ ->with(['accountType']);if ('' !== $query) {$search = sprintf('%%%s%%', $query);$dbQuery->where('name', 'LIKE', $search);diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.phpindex e29a44b658..d1475c815b 100644--- a/app/Services/Internal/Support/RecurringTransactionTrait.php+++ b/app/Services/Internal/Support/RecurringTransactionTrait.php@@ -266,7 +266,6 @@ trait RecurringTransactionTrait*/protected function updatePiggyBank(RecurrenceTransaction $transaction, int $piggyId, string $piggyName): void{-/** @var PiggyBankFactory $factory */$factory = app(PiggyBankFactory::class);$factory->setUser($transaction->recurrence->user);diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex 0ca74e82f1..487bdab988 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -90,7 +90,7 @@ class AccountUpdateService$account->save();// find currency, or use default currency instead.- if (null !== $data['currency_id'] || null !== $data['currency_code']) {+ if (isset($data['currency_id']) && (null !== $data['currency_id'] || null !== $data['currency_code'])) {$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));unset($data['currency_code']);$data['currency_id'] = $currency->id;diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.phpindex 11a51616d5..94a7c058ff 100644--- a/app/Support/FireflyConfig.php+++ b/app/Support/FireflyConfig.php@@ -40,7 +40,7 @@ class FireflyConfigpublic function delete(string $name): void{if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name));}$fullName = 'ff-config-' . $name;if (Cache::has($fullName)) {@@ -63,7 +63,7 @@ class FireflyConfigpublic function get(string $name, $default = null): ?Configuration{if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name));}$fullName = 'ff-config-' . $name;if (Cache::has($fullName)) {diff --git a/app/Support/Http/Controllers/BasicDataSupport.php b/app/Support/Http/Controllers/BasicDataSupport.phpindex ea627dde8c..3e62be2e4e 100644--- a/app/Support/Http/Controllers/BasicDataSupport.php+++ b/app/Support/Http/Controllers/BasicDataSupport.php@@ -45,7 +45,8 @@ trait BasicDataSupport*/foreach ($data as $entryId => $set) {$sum = '0';- foreach ($set['entries'] as $amount) {+ $entries = $set['entries'] ?? [];+ foreach ($entries as $amount) {$sum = bcadd($amount, $sum);}$data[$entryId]['sum'] = $sum;diff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex 72bd3a2f03..999f515d43 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -99,7 +99,7 @@ class Preferencespublic function get(string $name, $default = null): ?Preference{if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name));}/** @var User $user */$user = auth()->user();@@ -149,7 +149,7 @@ class Preferencespublic function getForUser(User $user, string $name, $default = null): ?Preference{if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name));}$fullName = sprintf('preference%s%s', $user->id, $name);if (Cache::has($fullName)) {diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.phpindex bbab73358f..69415cd78c 100644--- a/app/Support/Twig/General.php+++ b/app/Support/Twig/General.php@@ -208,10 +208,6 @@ class General extends Twig_Extensionreturn new Twig_SimpleFunction('accountGetMetaField',static function (Account $account, string $field): string {- if ('testing' === config('app.env')) {- Log::warning('Twig General::getMetaField should NOT be called in the TEST environment!');- }-/** @var AccountRepositoryInterface $repository */$repository = app(AccountRepositoryInterface::class);$result = $repository->getMetaValue($account, $field);diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.phpindex 4d1c91238e..de46620276 100644--- a/app/Support/Twig/TransactionGroupTwig.php+++ b/app/Support/Twig/TransactionGroupTwig.php@@ -148,9 +148,6 @@ class TransactionGroupTwig extends Twig_Extensionreturn new Twig_SimpleFunction('journalHasMeta',static function (int $journalId, string $metaField) {- if ('testing' === config('app.env')) {- Log::warning('Twig TransactionGroup::journalHasMeta should NOT be called in the TEST environment!');- }$count = DB::table('journal_meta')->where('name', $metaField)->where('transaction_journal_id', $journalId)diff --git a/app/Transformers/CategoryTransformer.php b/app/Transformers/CategoryTransformer.phpindex cfe3173fd2..bc22a2f793 100644--- a/app/Transformers/CategoryTransformer.php+++ b/app/Transformers/CategoryTransformer.php@@ -25,7 +25,6 @@ namespace FireflyIII\Transformers;use FireflyIII\Models\Category;-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;use FireflyIII\Repositories\Category\OperationsRepositoryInterface;use Illuminate\Support\Collection;use Log;@@ -37,8 +36,6 @@ class CategoryTransformer extends AbstractTransformer{/** @var OperationsRepositoryInterface */private $opsRepository;- /** @var CategoryRepositoryInterface */- private $repository;/*** CategoryTransformer constructor.@@ -47,7 +44,6 @@ class CategoryTransformer extends AbstractTransformer*/public function __construct(){- $this->repository = app(CategoryRepositoryInterface::class);$this->opsRepository = app(OperationsRepositoryInterface::class);if ('testing' === config('app.env')) {Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));@@ -63,7 +59,6 @@ class CategoryTransformer extends AbstractTransformer*/public function transform(Category $category): array{- $this->repository->setUser($category->user);$this->opsRepository->setUser($category->user);$spent = [];@@ -101,7 +96,7 @@ class CategoryTransformer extends AbstractTransformer{$return = [];foreach ($array as $data) {- $data['sum'] = round($data['sum'], $data['currency_decimal_places']);+ $data['sum'] = round($data['sum'], (int)$data['currency_decimal_places']);$return[] = $data;}diff --git a/app/Transformers/RuleTransformer.php b/app/Transformers/RuleTransformer.phpindex 0ca8a0f2a0..fb66aac7eb 100644--- a/app/Transformers/RuleTransformer.php+++ b/app/Transformers/RuleTransformer.php@@ -75,7 +75,7 @@ class RuleTransformer extends AbstractTransformer'active' => $rule->active,'strict' => $rule->strict,'stop_processing' => $rule->stop_processing,- 'trigger' => $this->getRuleTrigger($rule),+ 'trigger' => $this->getRuleTrigger($rule),'triggers' => $this->triggers($rule),'actions' => $this->actions($rule),'links' => [diff --git a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php b/tests/Api/V1/Controllers/BudgetLimitControllerTest.phpindex c5ccefda5c..984c02dec6 100644--- a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php+++ b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php@@ -120,6 +120,7 @@ class BudgetLimitControllerTest extends TestCase$repository->shouldReceive('setUser')->once();// call API+ Log::warning('The following error is part of a test.');$response = $this->post(route('api.v1.budget_limits.store'), $data);$response->assertStatus(500);$response->assertSee('Unknown budget.');diff --git a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php b/tests/Api/V1/Controllers/Chart/CategoryControllerTest.phpindex 07418b3bb0..65d9944bc8 100644--- a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php+++ b/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php@@ -24,8 +24,11 @@ namespace Tests\Api\V1\Controllers\Chart;use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;+use FireflyIII\Repositories\Category\OperationsRepositoryInterface;use Laravel\Passport\Passport;use Log;+use Tests\Support\TestDataTrait;use Tests\TestCase;/**@@ -36,6 +39,8 @@ use Tests\TestCase;*/class CategoryControllerTest extends TestCase{+ use TestDataTrait;+/****/@@ -52,65 +57,21 @@ class CategoryControllerTest extends TestCasepublic function testOverview(): void{$repository = $this->mock(CategoryRepositoryInterface::class);+ $noCatRepos =$this->mock(NoCategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);- $spent = [- 2 => [- 'name' => 'Some other category',- 'spent' => [- // earned in this currency.- 1 => [- 'currency_decimal_places' => 2,- 'currency_symbol' => 'x',- 'currency_code' => 'EUR',- 'currency_id' => 1,- 'spent' => '-522',- ],- ],- ],- ];-- $earned = [- 1 => [- 'name' => 'Some category',- 'earned' => [- // earned in this currency.- 2 => [- 'currency_decimal_places' => 2,- 'currency_id' => 1,- 'currency_symbol' => 'x',- 'currency_code' => 'EUR',- 'earned' => '123',- ],- ],- ],- ];-- $earnedNoCategory = [- 1 => [- 'currency_decimal_places' => 2,- 'currency_id' => 3,- 'currency_symbol' => 'x',- 'currency_code' => 'EUR',- 'earned' => '123',- ],- ];- $spentNoCategory = [- 5 => [- 'currency_decimal_places' => 2,- 'currency_symbol' => 'x',- 'currency_code' => 'EUR',- 'currency_id' => 4,- 'spent' => '-345',- ],- ];// mock calls:$repository->shouldReceive('setUser')->atLeast()->once();- $repository->shouldReceive('spentInPeriodPerCurrency')->atLeast()->once()->andReturn($spent);- $repository->shouldReceive('earnedInPeriodPerCurrency')->atLeast()->once()->andReturn($earned);+ $noCatRepos->shouldReceive('setUser')->atLeast()->once();+ $opsRepos->shouldReceive('setUser')->atLeast()->once();++ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());+ $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());++ $noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());+ $noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());- $repository->shouldReceive('earnedInPeriodPcWoCategory')->atLeast()->once()->andReturn($earnedNoCategory);- $repository->shouldReceive('spentInPeriodPcWoCategory')->atLeast()->once()->andReturn($spentNoCategory);$parameters = ['start' => '2019-01-01',diff --git a/tests/Api/V1/Controllers/LinkTypeControllerTest.php b/tests/Api/V1/Controllers/LinkTypeControllerTest.phpindex 53816a9645..51d94abba4 100644--- a/tests/Api/V1/Controllers/LinkTypeControllerTest.php+++ b/tests/Api/V1/Controllers/LinkTypeControllerTest.php@@ -118,6 +118,7 @@ class LinkTypeControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->post(route('api.v1.link_types.store'), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('You need the \"owner\"-role to do this.');@@ -207,6 +208,7 @@ class LinkTypeControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('You cannot edit this link type ');@@ -248,6 +250,7 @@ class LinkTypeControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('You need the \"owner\"-role to do this.');diff --git a/tests/Api/V1/Controllers/PiggyBankControllerTest.php b/tests/Api/V1/Controllers/PiggyBankControllerTest.phpindex 6b20a2ee59..ce53a0a56d 100644--- a/tests/Api/V1/Controllers/PiggyBankControllerTest.php+++ b/tests/Api/V1/Controllers/PiggyBankControllerTest.php@@ -112,6 +112,7 @@ class PiggyBankControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertHeader('Content-Type', 'application/json');diff --git a/tests/Api/V1/Controllers/RecurrenceControllerTest.php b/tests/Api/V1/Controllers/RecurrenceControllerTest.phpindex 8ad80b3fa2..b820ce14c4 100644--- a/tests/Api/V1/Controllers/RecurrenceControllerTest.php+++ b/tests/Api/V1/Controllers/RecurrenceControllerTest.php@@ -1256,7 +1256,7 @@ class RecurrenceControllerTest extends TestCase['message' => 'The given data was invalid.','errors' => [- 'description' => [+ 'repetitions' => ['Need at least one repetition.',],],@@ -1309,7 +1309,7 @@ class RecurrenceControllerTest extends TestCase['message' => 'The given data was invalid.','errors' => [- 'description' => [+ 'transactions' => ['Need at least one transaction.',],],diff --git a/tests/Api/V1/Controllers/RuleGroupControllerTest.php b/tests/Api/V1/Controllers/RuleGroupControllerTest.phpindex 165350993c..4e58999767 100644--- a/tests/Api/V1/Controllers/RuleGroupControllerTest.php+++ b/tests/Api/V1/Controllers/RuleGroupControllerTest.php@@ -172,6 +172,7 @@ class RuleGroupControllerTest extends TestCase// call API$group = $this->user()->ruleGroups()->first();+ Log::warning('The following error is part of a test.');$response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('{"message":"No rules in this rule group.","exception":"FireflyIII\\\\Exceptions\\\\FireflyException"');diff --git a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php b/tests/Api/V1/Controllers/TransactionLinkControllerTest.phpindex ed57e7d286..cfc21cad23 100644--- a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php+++ b/tests/Api/V1/Controllers/TransactionLinkControllerTest.php@@ -257,6 +257,7 @@ class TransactionLinkControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('Source or destination is NULL.'); // the creation moment.@@ -380,6 +381,7 @@ class TransactionLinkControllerTest extends TestCase];// test API+ Log::warning('The following error is part of a test.');$response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);$response->assertStatus(500);$response->assertSee('Source or destination is NULL.'); // the creation moment.diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.phpindex 9e762d2dab..79561de704 100644--- a/tests/Feature/Controllers/AttachmentControllerTest.php+++ b/tests/Feature/Controllers/AttachmentControllerTest.php@@ -126,6 +126,7 @@ class AttachmentControllerTest extends TestCase$repository->shouldReceive('exists')->once()->andReturn(false);+ Log::warning('The following error is part of a test.');$this->be($this->user());$response = $this->get(route('attachments.download', [$attachment->id]));$response->assertStatus(500);diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.phpindex 956128ca36..5b3336f269 100644--- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php+++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php@@ -22,12 +22,13 @@ declare(strict_types=1);namespace Tests\Feature\Controllers\Auth;+use FireflyIII\Models\Configuration;use FireflyIII\Models\Preference;use Google2FA;use Log;use Preferences;use Tests\TestCase;-+use FireflyConfig;/*** Class TwoFactorControllerTest* @SuppressWarnings(PHPMD.CouplingBetweenObjects)@@ -54,6 +55,11 @@ class TwoFactorControllerTest extends TestCase$langPreference = new Preference;$langPreference->data = 'en_US';+ $falseConfig = new Configuration;+ $falseConfig->data = false;++ FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig);+Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);$response = $this->get(route('two-factor.lost'));diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.phpindex f3c0d41a90..a350194100 100644--- a/tests/Feature/Controllers/BillControllerTest.php+++ b/tests/Feature/Controllers/BillControllerTest.php@@ -166,14 +166,17 @@ class BillControllerTest extends TestCase$userRepos = $this->mock(UserRepositoryInterface::class);$transformer = $this->mock(BillTransformer::class);$euro = $this->getEuro();- $pref = new Preference;- $pref->data = 50;- Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);+ //$pref = new Preference;+ //$pref->data = 50;+ //Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);Amount::shouldReceive('formatAnything')->andReturn('-100');$transformer->shouldReceive('setParameters')->atLeast()->once();$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(- ['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',+ ['id' => 5, 'active' => true,+ 'name' => 'x', 'next_expected_match' => '2018-01-01',+ 'amount_min' => '10',+ 'amount_max' => '10','currency' => $this->getEuro(),'currency_id' => $euro->id,'currency_code' => $euro->code,@@ -185,7 +188,7 @@ class BillControllerTest extends TestCase$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();$collection = new Collection([$bill]);- $repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();+ $repository->shouldReceive('getBills')->andReturn($collection)->once();$repository->shouldReceive('setUser');$repository->shouldReceive('getNoteText')->andReturn('Hi there');$repository->shouldReceive('getRulesForBills')->andReturn([]);diff --git a/tests/Feature/Controllers/Chart/BudgetControllerTest.php b/tests/Feature/Controllers/Chart/BudgetControllerTest.phpindex 3125ba94bc..99dff45af0 100644--- a/tests/Feature/Controllers/Chart/BudgetControllerTest.php+++ b/tests/Feature/Controllers/Chart/BudgetControllerTest.php@@ -121,6 +121,7 @@ class BudgetControllerTest extends TestCase// mock default session$this->mockDefaultSession();+ Log::warning('The following error is part of a test.');$this->be($this->user());$response = $this->get(route('chart.budget.budget-limit', [$budget->id, $limit->id]));$response->assertStatus(500);diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.phpindex 354353a0a9..f034fd41dc 100644--- a/tests/Feature/Controllers/CurrencyControllerTest.php+++ b/tests/Feature/Controllers/CurrencyControllerTest.php@@ -295,6 +295,7 @@ class CurrencyControllerTest extends TestCase$repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);Preferences::shouldReceive('mark')->atLeast()->once();+ Log::warning('The following error is part of a test.');$this->be($this->user());$response = $this->get(route('currencies.disable', [$euro->id]));$response->assertStatus(500);diff --git a/tests/Feature/Controllers/Import/JobStatusControllerTest.php b/tests/Feature/Controllers/Import/JobStatusControllerTest.phpindex 01544a6c85..2c92cfd2d7 100644--- a/tests/Feature/Controllers/Import/JobStatusControllerTest.php+++ b/tests/Feature/Controllers/Import/JobStatusControllerTest.php@@ -275,6 +275,7 @@ class JobStatusControllerTest extends TestCase$routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));// call thing.+ Log::warning('The following error is part of a test.');$this->be($this->user());$response = $this->post(route('import.job.start', [$job->key]));$response->assertStatus(200);@@ -308,6 +309,7 @@ class JobStatusControllerTest extends TestCase$routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));// call thing.+ Log::warning('The following error is part of a test.');$this->be($this->user());$response = $this->post(route('import.job.start', [$job->key]));$response->assertStatus(200);diff --git a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.phpindex 376201714a..95ab78633a 100644--- a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php+++ b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Json;use FireflyIII\Models\AccountType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;use Illuminate\Support\Collection;use Log;use Tests\TestCase;@@ -115,6 +116,7 @@ class AutoCompleteControllerTest extends TestCase*/public function testAllJournals(): void{+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);$journalRepos = $this->mockDefaultSession();$journal = $this->getRandomWithdrawalAsArray();@@ -134,6 +136,7 @@ class AutoCompleteControllerTest extends TestCase*/public function testAllJournalsWithId(): void{+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);$journalRepos = $this->mockDefaultSession();$journal = $this->getRandomWithdrawalAsArray();@@ -155,12 +158,13 @@ class AutoCompleteControllerTest extends TestCase*/public function testAllJournalsWithIdNumeric(): void{+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);$journalRepos = $this->mockDefaultSession();$journal = $this->getRandomWithdrawalAsArray();- $journalObject = $this->getRandomWithdrawal();+ $journalObject = $this->getRandomWithdrawalGroup();$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));- $journalRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($journalObject);+ $groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject);$this->be($this->user());diff --git a/tests/Feature/Controllers/Json/FrontpageControllerTest.php b/tests/Feature/Controllers/Json/FrontpageControllerTest.phpindex a19d33ebff..c3ecdfefa8 100644--- a/tests/Feature/Controllers/Json/FrontpageControllerTest.php+++ b/tests/Feature/Controllers/Json/FrontpageControllerTest.php@@ -26,6 +26,7 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;use Illuminate\Support\Collection;use Log;use Tests\TestCase;+use Amount;/*** Class FrontpageControllerTest@@ -57,6 +58,8 @@ class FrontpageControllerTest extends TestCase$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy]));$repository->shouldReceive('getCurrentAmount')->andReturn('10');+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');+$this->be($this->user());$response = $this->get(route('json.fp.piggy-banks'));$response->assertStatus(200);diff --git a/tests/Feature/Controllers/Json/ReconcileControllerTest.php b/tests/Feature/Controllers/Json/ReconcileControllerTest.phpindex 9491f23019..24f9b297bd 100644--- a/tests/Feature/Controllers/Json/ReconcileControllerTest.php+++ b/tests/Feature/Controllers/Json/ReconcileControllerTest.php@@ -35,6 +35,7 @@ use Log;use Mockery;use Preferences;use Tests\TestCase;+use Steam;/***@@ -117,9 +118,11 @@ class ReconcileControllerTest extends TestCase$euro = $this->getEuro();$withdrawal = $this->getRandomWithdrawalAsArray();+ Steam::shouldReceive('balance')->atLeast()->once()->andReturn('20');+$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+ //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');Amount::shouldReceive('formatAnything')->andReturn('-100');$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.phpindex 02c6fa8167..d281161a44 100644--- a/tests/Feature/Controllers/ProfileControllerTest.php+++ b/tests/Feature/Controllers/ProfileControllerTest.php@@ -116,7 +116,8 @@ class ProfileControllerTest extends TestCase$this->mock(UserRepositoryInterface::class);Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection());- // email_change_confirm_token++ Log::warning('The following error is part of a test.');$response = $this->get(route('profile.confirm-email-change', ['some-fake-token']));$response->assertStatus(500);}@@ -583,6 +584,7 @@ class ProfileControllerTest extends TestCasePreferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference]));+ Log::warning('The following error is part of a test.');$response = $this->get(route('profile.undo-email-change', ['token', $hash]));$response->assertStatus(500);}diff --git a/tests/Feature/Controllers/Recurring/IndexControllerTest.php b/tests/Feature/Controllers/Recurring/IndexControllerTest.phpindex d09f3fe23e..cab0b2a1a2 100644--- a/tests/Feature/Controllers/Recurring/IndexControllerTest.php+++ b/tests/Feature/Controllers/Recurring/IndexControllerTest.php@@ -162,47 +162,5 @@ class IndexControllerTest extends TestCase}- /**- * @covers \FireflyIII\Http\Controllers\Recurring\IndexController- */- public function testShow(): void- {- $repository = $this->mock(RecurringRepositoryInterface::class);- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);- $userRepos = $this->mock(UserRepositoryInterface::class);- $categoryFactory = $this->mock(CategoryFactory::class);- $transformer = $this->mock(RecurrenceTransformer::class);-- $this->mockDefaultSession();-- $transformer->shouldReceive('setParameters')->atLeast()->once();- $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(- [- 'id' => 5,- 'first_date' => '2018-01-01',- 'repeat_until' => null,- 'latest_date' => null,- 'recurrence_repetitions' => [- [- 'occurrences' => [- '2019-01-01',- ],- ],- ],- ]- );-- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);-- $recurrence = $this->user()->recurrences()->first();- $repository->shouldReceive('setUser');- $repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();-- $this->be($this->user());- $response = $this->get(route('recurring.show', [$recurrence->id]));- $response->assertStatus(200);- $response->assertSee('<ol class="breadcrumb">');- }-}diff --git a/tests/Feature/Controllers/Recurring/ShowControllerTest.php b/tests/Feature/Controllers/Recurring/ShowControllerTest.phpnew file mode 100644index 0000000000..4dc7c0b467--- /dev/null+++ b/tests/Feature/Controllers/Recurring/ShowControllerTest.php@@ -0,0 +1,96 @@+<?php+/**+ * ShowControllerTest.php+ * Copyright (c) 2019 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace Tests\Feature\Controllers\Recurring;+++use FireflyIII\Factory\CategoryFactory;+use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;+use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;+use FireflyIII\Transformers\RecurrenceTransformer;+use Illuminate\Support\Collection;+use Tests\TestCase;+use Log;+use Mockery;++/**+ *+ * Class ShowControllerTest+ */+class ShowControllerTest extends TestCase+{++ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::info(sprintf('Now in %s.', get_class($this)));+ }+++ /**+ * @covers \FireflyIII\Http\Controllers\Recurring\IndexController+ */+ public function testShow(): void+ {+ $repository = $this->mock(RecurringRepositoryInterface::class);+ $budgetRepos = $this->mock(BudgetRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $categoryFactory = $this->mock(CategoryFactory::class);+ $transformer = $this->mock(RecurrenceTransformer::class);++ $this->mockDefaultSession();++ $transformer->shouldReceive('setParameters')->atLeast()->once();+ $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(+ [+ 'id' => 5,+ 'first_date' => '2018-01-01',+ 'repeat_until' => null,+ 'latest_date' => null,+ 'repetitions' => [+ [+ 'occurrences' => [+ '2019-01-01',+ ],+ ],+ ],+ ]+ );++ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);++ $recurrence = $this->user()->recurrences()->first();+ $repository->shouldReceive('setUser');+ $repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();++ $this->be($this->user());+ $response = $this->get(route('recurring.show', [$recurrence->id]));+ $response->assertStatus(200);+ $response->assertSee('<ol class="breadcrumb">');+ }++}\ No newline at end of filediff --git a/tests/Feature/Controllers/Report/BudgetControllerTest.php b/tests/Feature/Controllers/Report/BudgetControllerTest.phpindex f14dbe469f..2370022471 100644--- a/tests/Feature/Controllers/Report/BudgetControllerTest.php+++ b/tests/Feature/Controllers/Report/BudgetControllerTest.php@@ -86,7 +86,7 @@ class BudgetControllerTest extends TestCase$date = new Carbon;Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');- Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');+ //Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('getBudgets')->andReturn(new Collection);diff --git a/tests/Feature/Controllers/Report/CategoryControllerTest.php b/tests/Feature/Controllers/Report/CategoryControllerTest.phpindex 8e88b87cea..1d90472bde 100644--- a/tests/Feature/Controllers/Report/CategoryControllerTest.php+++ b/tests/Feature/Controllers/Report/CategoryControllerTest.php@@ -26,9 +26,12 @@ use Amount;use Carbon\Carbon;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;+use FireflyIII\Repositories\Category\OperationsRepositoryInterface;use Illuminate\Support\Collection;use Log;use Preferences;+use Tests\Support\TestDataTrait;use Tests\TestCase;/**@@ -40,6 +43,7 @@ use Tests\TestCase;*/class CategoryControllerTest extends TestCase{+ use TestDataTrait;/****/@@ -56,11 +60,16 @@ class CategoryControllerTest extends TestCasepublic function testExpenses(): void{$this->mockDefaultSession();- $first = [1 => ['entries' => ['1', '1']]];- $second = ['entries' => ['1', '1']];- $repository = $this->mock(CategoryRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $first = [1 => ['entries' => ['1', '1']]];+ $second = ['entries' => ['1', '1']];+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;++ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());+ $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');@@ -81,15 +90,22 @@ class CategoryControllerTest extends TestCasepublic function testIncome(): void{$this->mockDefaultSession();- $first = [+ $first = [1 => ['entries' => ['1', '1']],2 => ['entries' => ['0']],];- $second = ['entries' => ['1', '1']];- $repository = $this->mock(CategoryRepositoryInterface::class);- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $second = ['entries' => ['1', '1']];+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;++ $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());+ $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());+Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('getCategories')->andReturn(new Collection);@@ -107,12 +123,21 @@ class CategoryControllerTest extends TestCasepublic function testOperations(): void{$this->mockDefaultSession();- $repository = $this->mock(CategoryRepositoryInterface::class);- $category = $this->getRandomCategory();- $fiscalHelper = $this->mock(FiscalHelperInterface::class);- $date = new Carbon;+ $repository = $this->mock(CategoryRepositoryInterface::class);+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepository = $this->mock(NoCategoryRepositoryInterface::class);+ $category = $this->getRandomCategory();+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);+ $date = new Carbon;++ $opsRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());+ $noCatRepository->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());++ $opsRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());+ $noCatRepository->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());+Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');- //Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));diff --git a/tests/Feature/Controllers/Report/ExpenseControllerTest.php b/tests/Feature/Controllers/Report/ExpenseControllerTest.phpindex 94b7c04660..e06c57c995 100644--- a/tests/Feature/Controllers/Report/ExpenseControllerTest.php+++ b/tests/Feature/Controllers/Report/ExpenseControllerTest.php@@ -178,6 +178,8 @@ class ExpenseControllerTest extends TestCase$this->mockDefaultSession();Preferences::shouldReceive('lastActivity')->atLeast()->once();+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');+$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);@@ -222,6 +224,7 @@ class ExpenseControllerTest extends TestCase$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();$collector->shouldReceive('getExtractedJournals')->andReturn($transactions)->atLeast()->once();+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('100');$this->be($this->user());$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));diff --git a/tests/Feature/Controllers/Rule/EditControllerTest.php b/tests/Feature/Controllers/Rule/EditControllerTest.phpindex 95e5bc2992..c55523c867 100644--- a/tests/Feature/Controllers/Rule/EditControllerTest.php+++ b/tests/Feature/Controllers/Rule/EditControllerTest.php@@ -114,7 +114,7 @@ class EditControllerTest extends TestCase// mock stuff$repository = $this->mock(RuleRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);-+ $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);$this->mockDefaultSession();Preferences::shouldReceive('mark')->atLeast()->once();diff --git a/tests/Feature/Controllers/Rule/SelectControllerTest.php b/tests/Feature/Controllers/Rule/SelectControllerTest.phpindex c802b9dc5e..ea879a0172 100644--- a/tests/Feature/Controllers/Rule/SelectControllerTest.php+++ b/tests/Feature/Controllers/Rule/SelectControllerTest.php@@ -59,11 +59,11 @@ class SelectControllerTest extends TestCase*/public function testExecute(): void{+ $this->mockDefaultSession();$account = $this->user()->accounts()->find(1);$accountRepos = $this->mock(AccountRepositoryInterface::class);$repository = $this->mock(RuleRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);- $this->mockDefaultSession();$collector = $this->mock(GroupCollectorInterface::class);$ruleEngine = $this->mock(RuleEngine::class);@@ -100,9 +100,9 @@ class SelectControllerTest extends TestCase*/public function testSelectTransactions(): void{+ $this->mockDefaultSession();$accountRepos = $this->mock(AccountRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);- $this->mockDefaultSession();$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);@@ -187,6 +187,7 @@ class SelectControllerTest extends TestCase*/public function testTestTriggersMax(): void{+ $this->mockDefaultSession();$data = ['triggers' => ['name' => 'description',diff --git a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.phpindex 87932454b1..5a071512cf 100644--- a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php+++ b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php@@ -27,6 +27,7 @@ use Carbon\Carbon;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\TransactionRules\Engine\RuleEngine;use Illuminate\Support\Collection;@@ -59,12 +60,12 @@ class ExecutionControllerTest extends TestCase{$this->mockDefaultSession();$accountRepos = $this->mock(AccountRepositoryInterface::class);-+ $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);$collector = $this->mock(GroupCollectorInterface::class);$ruleEngine = $this->mock(RuleEngine::class);$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);-+ $groupRepos->shouldReceive('getActiveRules')->atLeast()->once()->andReturn(new Collection);// new mocks for ruleEngine$ruleEngine->shouldReceive('setUser')->atLeast()->once();$ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();@@ -96,6 +97,7 @@ class ExecutionControllerTest extends TestCase$this->mockDefaultSession();$accountRepos = $this->mock(AccountRepositoryInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);+ $groupRepos = $this->mock(RuleGroupRepositoryInterface::class);$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.phpindex ad867e2da2..b41a289056 100644--- a/tests/Feature/Controllers/TagControllerTest.php+++ b/tests/Feature/Controllers/TagControllerTest.php@@ -172,6 +172,10 @@ class TagControllerTest extends TestCase$collector = $this->mock(GroupCollectorInterface::class);$userRepos = $this->mock(UserRepositoryInterface::class);$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);+ $repository->shouldReceive('setUser')->atLeast()->once();+ //$repository->shouldReceive('setUser')->atLeast()->once();+ $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());+//Preferences::shouldReceive('mark')->atLeast()->once();Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');@@ -228,6 +232,9 @@ class TagControllerTest extends TestCase$userRepos = $this->mock(UserRepositoryInterface::class);$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);+ $repository->shouldReceive('setUser')->atLeast()->once();+ $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());+$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();@@ -279,6 +286,10 @@ class TagControllerTest extends TestCase$userRepos = $this->mock(UserRepositoryInterface::class);$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);+ $repository->shouldReceive('setUser')->atLeast()->once();+ $repository->shouldReceive('findByTag')->atLeast()->once()->andReturn($this->getRandomTag());++//Preferences::shouldReceive('mark')->atLeast()->once();Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');diff --git a/tests/Feature/Controllers/Transaction/ConvertControllerTest.php b/tests/Feature/Controllers/Transaction/ConvertControllerTest.phpindex 03aadb530f..7679c924a0 100644--- a/tests/Feature/Controllers/Transaction/ConvertControllerTest.php+++ b/tests/Feature/Controllers/Transaction/ConvertControllerTest.php@@ -23,8 +23,18 @@ declare(strict_types=1);namespace Tests\Feature\Controllers\Transaction;use Amount;+use FireflyIII\Factory\TagFactory;+use FireflyIII\Factory\TransactionFactory;+use FireflyIII\Factory\TransactionTypeFactory;use FireflyIII\Models\AccountType;+use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Bill\BillRepositoryInterface;+use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;+use FireflyIII\Repositories\Category\OperationsRepositoryInterface;+use FireflyIII\Repositories\Currency\CurrencyRepository;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;@@ -63,12 +73,18 @@ class ConvertControllerTest extends TestCasepublic function testIndexDepositTransfer(): void{// mock stuff:- $journalRepos = $this->mockDefaultSession();- $userRepos = $this->mock(UserRepositoryInterface::class);- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $transformer = $this->mock(TransactionGroupTransformer::class);+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $journalRepos = $this->mockDefaultSession();+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+ $billRepos = $this->mock(BillRepositoryInterface::class);+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);+ $transactionFactory = $this->mock(TransactionFactory::class);$revenue = $this->getRandomRevenue();$deposit = $this->getRandomDepositGroup();@@ -123,10 +139,16 @@ class ConvertControllerTest extends TestCasepublic function testIndexSameType(): void{// mock stuff:+ Log::info(sprintf('Now in test %s.', __METHOD__));$this->mockDefaultSession();$this->mock(UserRepositoryInterface::class);$this->mock(CurrencyRepositoryInterface::class);$this->mock(TransactionGroupRepositoryInterface::class);+ $billRepos = $this->mock(BillRepositoryInterface::class);+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);+ $transactionFactory = $this->mock(TransactionFactory::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(TransactionGroupTransformer::class);@@ -174,28 +196,38 @@ class ConvertControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\Transaction\ConvertController*/- public function testPostIndexDepositTransfer(): void+ public function testPostIndexBadDestination(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));$this->mockDefaultSession();$this->mock(UserRepositoryInterface::class);$this->mock(AccountRepositoryInterface::class);$this->mock(RuleGroupRepositoryInterface::class);+ $billRepos = $this->mock(BillRepositoryInterface::class);+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);+ $transactionFactory = $this->mock(TransactionFactory::class);++$validator = $this->mock(AccountValidator::class);$deposit = $this->getRandomDepositGroup();- Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();+ // first journal:+ $journal = $deposit->transactionJournals()->first();$validator->shouldReceive('setUser')->atLeast()->once();$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);+ $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);$data = ['source_account_id' => 1];$this->be($this->user());$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);$response->assertStatus(302);- $response->assertRedirect(route('transactions.show', [$deposit->id]));+ $response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));+ $response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));}/**@@ -203,10 +235,18 @@ class ConvertControllerTest extends TestCase*/public function testPostIndexBadSource(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));$this->mockDefaultSession();$this->mock(UserRepositoryInterface::class);$this->mock(AccountRepositoryInterface::class);$this->mock(RuleGroupRepositoryInterface::class);+ $billRepos = $this->mock(BillRepositoryInterface::class);+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);+ $transactionFactory = $this->mock(TransactionFactory::class);++$validator = $this->mock(AccountValidator::class);$deposit = $this->getRandomDepositGroup();@@ -230,29 +270,46 @@ class ConvertControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\Transaction\ConvertController*/- public function testPostIndexBadDestination(): void+ public function testPostIndexDepositTransfer(): void{- $this->mockDefaultSession();+ Log::info(sprintf('Now in test %s.', __METHOD__));$this->mock(UserRepositoryInterface::class);$this->mock(AccountRepositoryInterface::class);- $this->mock(RuleGroupRepositoryInterface::class);- $validator = $this->mock(AccountValidator::class);- $deposit = $this->getRandomDepositGroup();- // first journal:- $journal = $deposit->transactionJournals()->first();++ $billRepos = $this->mock(BillRepositoryInterface::class);+ $categoryRepos = $this->mock(CategoryRepositoryInterface::class);+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);+ $noCatRepos = $this->mock(NoCategoryRepositoryInterface::class);+ $budgetRepos = $this->mock(BudgetRepositoryInterface::class);+ $tagFactory = $this->mock(TagFactory::class);+ $currencyRepos = $this->mock(CurrencyRepository::class);+ $validator = $this->mock(AccountValidator::class);+ $transactionFactory = $this->mock(TransactionFactory::class);+ $typeFactory = $this->mock(TransactionTypeFactory::class);+ $ruleGroup = $this->mock(RuleGroupRepositoryInterface::class);++ $type = TransactionType::first();+ $typeFactory->shouldReceive('find')->atLeast()->once()->andReturn($type);++ $this->mockDefaultSession();+++ $deposit = $this->getRandomDepositGroup();++ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();$validator->shouldReceive('setUser')->atLeast()->once();+ $currencyRepos->shouldReceive('setUser')->atLeast()->once();$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);+ $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);$data = ['source_account_id' => 1];$this->be($this->user());$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);$response->assertStatus(302);- $response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));- $response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));+ $response->assertRedirect(route('transactions.show', [$deposit->id]));}}diff --git a/tests/Feature/Controllers/Transaction/CreateControllerTest.php b/tests/Feature/Controllers/Transaction/CreateControllerTest.phpindex 07d514fb6a..e187f5832b 100644--- a/tests/Feature/Controllers/Transaction/CreateControllerTest.php+++ b/tests/Feature/Controllers/Transaction/CreateControllerTest.php@@ -64,6 +64,7 @@ class CreateControllerTest extends TestCase$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);+ Preferences::shouldReceive('mark')->atLeast()->once();Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($empty);diff --git a/tests/Feature/Controllers/Transaction/EditControllerTest.php b/tests/Feature/Controllers/Transaction/EditControllerTest.phpindex ba9f55ee36..80a87aee09 100644--- a/tests/Feature/Controllers/Transaction/EditControllerTest.php+++ b/tests/Feature/Controllers/Transaction/EditControllerTest.php@@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Transaction;use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;use Log;use Tests\TestCase;@@ -49,8 +50,10 @@ class EditControllerTest extends TestCase$group = $this->getRandomWithdrawalGroup();$account = $this->getRandomAsset();$accountRepos = $this->mock(AccountRepositoryInterface::class);- $this->mockDefaultSession();+ $userRepos = $this->mock(UserRepositoryInterface::class);+ $this->mockDefaultSession();+ $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturn(true);$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($account);diff --git a/tests/Support/TestDataTrait.php b/tests/Support/TestDataTrait.phpindex 0fe38bb4e6..9cbb706b83 100644--- a/tests/Support/TestDataTrait.php+++ b/tests/Support/TestDataTrait.php@@ -171,6 +171,41 @@ trait TestDataTraitreturn $data;}+ /**+ * Method that returns default data for when the category OperationsController+ * "sumIncome" method is called.+ *+ * Also applies to NoCategoryRepos::sumIncome.+ *+ * @return array+ */+ protected function categorySumIncome(): array+ {+ $eur = TransactionCurrency::where('code', 'EUR')->first();+ $usd = TransactionCurrency::where('code', 'USD')->first();+ $data = [];+ $amount = 400;+ try {+ $amount = random_int(100, 2500);+ } catch (Exception $e) {+ $e->getMessage();+ }+ $amount = (string)round($amount / 100, 2);++ foreach ([$eur, $usd] as $currency) {+ $data[$currency->id] = [+ 'currency_id' => $currency->id,+ 'currency_name' => $currency->name,+ 'currency_symbol' => $currency->symbol,+ 'currency_code' => $currency->code,+ 'currency_decimal_places' => $currency->decimal_places,+ 'sum' => $amount,+ ];+ }++ return $data;+ }+/*** Method that returns default data for when the category NoCategoryRepos* "listExpenses" method is called.diff --git a/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php b/tests/Unit/Console/Commands/Import/CreateCSVImportTest.phpindex bbd3e66ae2..3894b080c3 100644--- a/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php+++ b/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php@@ -316,7 +316,7 @@ class CreateCSVImportTest extends TestCase'--user=1','--token=token',];-+ Log::warning('The following error is part of a test.');$this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))->expectsOutput(sprintf('Import file : %s', $file))->expectsOutput(sprintf('Configuration file : %s', $config))@@ -373,7 +373,7 @@ class CreateCSVImportTest extends TestCase'--user=1','--token=token',];-+ Log::warning('The following error is part of a test.');$this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))->expectsOutput(sprintf('Import file : %s', $file))->expectsOutput(sprintf('Configuration file : %s', $config))@@ -424,6 +424,7 @@ class CreateCSVImportTest extends TestCase'--user=1','--token=token',];+ Log::warning('The following error is part of a test.');$this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))->expectsOutput(sprintf('Import file : %s', $file))->expectsOutput(sprintf('Configuration file : %s', $config))diff --git a/tests/Unit/Console/Commands/Upgrade/AccountCurrenciesTest.php b/tests/Unit/Console/Commands/Upgrade/AccountCurrenciesTest.phpindex 45d50ad47d..e1318d92a6 100644--- a/tests/Unit/Console/Commands/Upgrade/AccountCurrenciesTest.php+++ b/tests/Unit/Console/Commands/Upgrade/AccountCurrenciesTest.php@@ -77,8 +77,8 @@ class AccountCurrenciesTest extends TestCase$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -117,8 +117,8 @@ class AccountCurrenciesTest extends TestCase$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -163,8 +163,8 @@ class AccountCurrenciesTest extends TestCase$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -205,8 +205,8 @@ class AccountCurrenciesTest extends TestCase$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -245,8 +245,8 @@ class AccountCurrenciesTest extends TestCase$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -283,8 +283,8 @@ class AccountCurrenciesTest extends TestCase$accountRepos->shouldReceive('getAccountsByType')->atLeast()->once()->andReturn(new Collection([$account]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -314,8 +314,8 @@ class AccountCurrenciesTest extends TestCase$userRepos->shouldReceive('all')->atLeast()->once()->andReturn(new Collection([$this->user()]));// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);@@ -340,8 +340,8 @@ class AccountCurrenciesTest extends TestCase$this->mock(UserRepositoryInterface::class);// check config- FireflyConfig::shouldReceive('get')->withArgs(['4780_account_currencies', false])->andReturn($true);- FireflyConfig::shouldReceive('set')->withArgs(['4780_account_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_account_currencies', false])->andReturn($true);+ FireflyConfig::shouldReceive('set')->withArgs(['480_account_currencies', true]);// check preferences:Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->andReturn($pref);diff --git a/tests/Unit/Console/Commands/Upgrade/BackToJournalsTest.php b/tests/Unit/Console/Commands/Upgrade/BackToJournalsTest.phpindex 4d15782ed3..57b72e2aea 100644--- a/tests/Unit/Console/Commands/Upgrade/BackToJournalsTest.php+++ b/tests/Unit/Console/Commands/Upgrade/BackToJournalsTest.php@@ -60,11 +60,11 @@ class BackToJournalsTest extends TestCase$false->data = false;$true = new Configuration;$true->data = true;- FireflyConfig::shouldReceive('get')->withArgs(['4780_back_to_journals', false])->andReturn($false);- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($true);+ FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);// set new preference after running:- FireflyConfig::shouldReceive('set')->withArgs(['4780_back_to_journals', true]);+ FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);$this->artisan('firefly-iii:back-to-journals')->expectsOutput('Check 0 transaction journal(s) for budget info.')@@ -96,11 +96,11 @@ class BackToJournalsTest extends TestCase$false->data = false;$true = new Configuration;$true->data = true;- FireflyConfig::shouldReceive('get')->withArgs(['4780_back_to_journals', false])->andReturn($false);- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($true);+ FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);// set new preference after running:- FireflyConfig::shouldReceive('set')->withArgs(['4780_back_to_journals', true]);+ FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);$this->artisan('firefly-iii:back-to-journals')->expectsOutput('Check 1 transaction journal(s) for budget info.')@@ -122,6 +122,7 @@ class BackToJournalsTest extends TestCase*/public function testHandleCategory(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));$journal = $this->getRandomWithdrawal();/** @var Transaction $transaction */$transaction = $journal->transactions()->first();@@ -138,11 +139,11 @@ class BackToJournalsTest extends TestCase$true = new Configuration;$true->data = true;- FireflyConfig::shouldReceive('get')->withArgs(['4780_back_to_journals', false])->andReturn($false);- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($true);+ FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);// set new preference after running:- FireflyConfig::shouldReceive('set')->withArgs(['4780_back_to_journals', true]);+ FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);$this->artisan('firefly-iii:back-to-journals')->expectsOutput('Check 0 transaction journal(s) for budget info.')@@ -181,11 +182,11 @@ class BackToJournalsTest extends TestCase$false->data = false;$true = new Configuration;$true->data = true;- FireflyConfig::shouldReceive('get')->withArgs(['4780_back_to_journals', false])->andReturn($false);- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($true);+ FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);// set new preference after running:- FireflyConfig::shouldReceive('set')->withArgs(['4780_back_to_journals', true]);+ FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);$this->artisan('firefly-iii:back-to-journals')->expectsOutput('Check 1 transaction journal(s) for budget info.')@@ -225,11 +226,11 @@ class BackToJournalsTest extends TestCase$false->data = false;$true = new Configuration;$true->data = true;- FireflyConfig::shouldReceive('get')->withArgs(['4780_back_to_journals', false])->andReturn($false);- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($true);+ FireflyConfig::shouldReceive('get')->withArgs(['480_back_to_journals', false])->andReturn($false);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($true);// set new preference after running:- FireflyConfig::shouldReceive('set')->withArgs(['4780_back_to_journals', true]);+ FireflyConfig::shouldReceive('set')->withArgs(['480_back_to_journals', true]);$this->artisan('firefly-iii:back-to-journals')->expectsOutput('Check 0 transaction journal(s) for budget info.')diff --git a/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php b/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.phpindex b4ed731906..8a58b39d18 100644--- a/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php+++ b/tests/Unit/Console/Commands/Upgrade/BudgetLimitCurrencyTest.php@@ -56,8 +56,8 @@ class BudgetLimitCurrencyTest extends TestCase$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);$this->artisan('firefly-iii:bl-currency')->expectsOutput('All budget limits are correct.')@@ -81,8 +81,8 @@ class BudgetLimitCurrencyTest extends TestCase'end_date' => '2019-01-31',]);- FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_bl_currency', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_bl_currency', true]);$currency = $this->getEuro();Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);diff --git a/tests/Unit/Console/Commands/Upgrade/CCLiabilitiesTest.php b/tests/Unit/Console/Commands/Upgrade/CCLiabilitiesTest.phpindex e7a78ca7bb..43a3613a25 100644--- a/tests/Unit/Console/Commands/Upgrade/CCLiabilitiesTest.php+++ b/tests/Unit/Console/Commands/Upgrade/CCLiabilitiesTest.php@@ -54,8 +54,8 @@ class CCLiabilitiesTest extends TestCase{$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_cc_liabilities', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_cc_liabilities', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);$this->artisan('firefly-iii:cc-liabilities')@@ -79,8 +79,8 @@ class CCLiabilitiesTest extends TestCase);$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_cc_liabilities', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_cc_liabilities', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);$this->artisan('firefly-iii:cc-liabilities')@@ -114,8 +114,8 @@ class CCLiabilitiesTest extends TestCase$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_cc_liabilities', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_cc_liabilities', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_cc_liabilities', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_cc_liabilities', true]);$this->artisan('firefly-iii:cc-liabilities')diff --git a/tests/Unit/Console/Commands/Upgrade/MigrateAttachmentsTest.php b/tests/Unit/Console/Commands/Upgrade/MigrateAttachmentsTest.phpindex 9d91bdf732..3a9d053f24 100644--- a/tests/Unit/Console/Commands/Upgrade/MigrateAttachmentsTest.php+++ b/tests/Unit/Console/Commands/Upgrade/MigrateAttachmentsTest.php@@ -55,8 +55,8 @@ class MigrateAttachmentsTest extends TestCase{$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrate_attachments', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_attachments', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);// assume all is well.$this->artisan('firefly-iii:migrate-attachments')->expectsOutput('All attachments are OK.')@@ -70,8 +70,8 @@ class MigrateAttachmentsTest extends TestCase{$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrate_attachments', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_attachments', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);$attachment = Attachment::create([diff --git a/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php b/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.phpindex 8638b86077..e0608ada4a 100644--- a/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php+++ b/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php@@ -53,8 +53,8 @@ class MigrateJournalNotesTest extends TestCase{$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrate_notes', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_notes', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);// assume all is well.$this->artisan('firefly-iii:migrate-notes')@@ -69,8 +69,8 @@ class MigrateJournalNotesTest extends TestCase{$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrate_notes', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_notes', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);$journal = $this->getRandomWithdrawal();diff --git a/tests/Unit/Console/Commands/Upgrade/MigrateToGroupsTest.php b/tests/Unit/Console/Commands/Upgrade/MigrateToGroupsTest.phpindex 8f9db22756..fbd3eeff79 100644--- a/tests/Unit/Console/Commands/Upgrade/MigrateToGroupsTest.php+++ b/tests/Unit/Console/Commands/Upgrade/MigrateToGroupsTest.php@@ -75,8 +75,8 @@ class MigrateToGroupsTest extends TestCase$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrated_to_groups', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);// assume all is well.$this->artisan('firefly-iii:migrate-to-groups')@@ -136,8 +136,8 @@ class MigrateToGroupsTest extends TestCase$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrated_to_groups', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);// assume all is well.$this->artisan('firefly-iii:migrate-to-groups')@@ -242,8 +242,8 @@ class MigrateToGroupsTest extends TestCase$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_migrated_to_groups', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_migrated_to_groups', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_migrated_to_groups', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_migrated_to_groups', true]);$this->artisan('firefly-iii:migrate-to-groups')->expectsOutput('Migrated 1 transaction journal(s).')diff --git a/tests/Unit/Console/Commands/Upgrade/MigrateToRulesTest.php b/tests/Unit/Console/Commands/Upgrade/MigrateToRulesTest.phpindex 145525c01f..ceabf87d39 100644--- a/tests/Unit/Console/Commands/Upgrade/MigrateToRulesTest.php+++ b/tests/Unit/Console/Commands/Upgrade/MigrateToRulesTest.php@@ -88,8 +88,8 @@ class MigrateToRulesTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_bills_to_rules', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_bills_to_rules', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);// preferences$language = new Preference;@@ -196,8 +196,8 @@ class MigrateToRulesTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_bills_to_rules', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_bills_to_rules', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);// preferences$language = new Preference;@@ -308,8 +308,8 @@ class MigrateToRulesTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_bills_to_rules', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_bills_to_rules', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_bills_to_rules', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_bills_to_rules', true]);// preferences$language = new Preference;diff --git a/tests/Unit/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php b/tests/Unit/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.phpindex d26fd087a3..82c176a045 100644--- a/tests/Unit/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php+++ b/tests/Unit/Console/Commands/Upgrade/OtherCurrenciesCorrectionsTest.php@@ -91,8 +91,8 @@ class OtherCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_other_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_other_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);// assume all is well.$this->artisan('firefly-iii:other-currencies')@@ -167,8 +167,8 @@ class OtherCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_other_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_other_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);$this->artisan('firefly-iii:other-currencies')->expectsOutput('Verified 1 transaction(s) and journal(s).')@@ -252,8 +252,8 @@ class OtherCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_other_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_other_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_other_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_other_currencies', true]);$this->artisan('firefly-iii:other-currencies')->expectsOutput('Verified 1 transaction(s) and journal(s).')diff --git a/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php b/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.phpindex 957eabfc12..a9fe45874e 100644--- a/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php+++ b/tests/Unit/Console/Commands/Upgrade/RenameAccountMetaTest.php@@ -56,8 +56,8 @@ class RenameAccountMetaTest extends TestCase$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]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);// assume all is well.$this->artisan('firefly-iii:rename-account-meta')@@ -76,8 +76,8 @@ class RenameAccountMetaTest extends TestCase$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]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_rename_account_meta', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_rename_account_meta', true]);$expense = $this->getRandomExpense();diff --git a/tests/Unit/Console/Commands/Upgrade/TransactionIdentifierTest.php b/tests/Unit/Console/Commands/Upgrade/TransactionIdentifierTest.phpindex 8fee32f112..c32727eeb9 100644--- a/tests/Unit/Console/Commands/Upgrade/TransactionIdentifierTest.php+++ b/tests/Unit/Console/Commands/Upgrade/TransactionIdentifierTest.php@@ -67,8 +67,8 @@ class TransactionIdentifierTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transaction_identifier', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transaction_identifier', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);// assume all is well.$this->artisan('firefly-iii:transaction-identifiers')@@ -140,8 +140,8 @@ class TransactionIdentifierTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transaction_identifier', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transaction_identifier', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);// assume all is well.$this->artisan('firefly-iii:transaction-identifiers')diff --git a/tests/Unit/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php b/tests/Unit/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.phpindex 29a6a96fd8..9e1fe1cc66 100644--- a/tests/Unit/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php+++ b/tests/Unit/Console/Commands/Upgrade/TransferCurrenciesCorrectionsTest.php@@ -75,8 +75,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);// assume all is well.$this->artisan('firefly-iii:transfer-currencies')@@ -117,8 +117,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);// assume all is well.$this->artisan('firefly-iii:transfer-currencies')@@ -162,8 +162,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')@@ -218,8 +218,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 2 transfer(s).')@@ -279,8 +279,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 3 transfer(s).')@@ -339,8 +339,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')@@ -393,8 +393,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')@@ -443,8 +443,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')@@ -493,8 +493,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')@@ -551,8 +551,8 @@ class TransferCurrenciesCorrectionsTest extends TestCase// configuration$false = new Configuration;$false->data = false;- FireflyConfig::shouldReceive('get')->withArgs(['4780_transfer_currencies', false])->andReturn($false);- FireflyConfig::shouldReceive('set')->withArgs(['4780_transfer_currencies', true]);+ FireflyConfig::shouldReceive('get')->withArgs(['480_transfer_currencies', false])->andReturn($false);+ FireflyConfig::shouldReceive('set')->withArgs(['480_transfer_currencies', true]);$this->artisan('firefly-iii:transfer-currencies')->expectsOutput('Verified currency information of 1 transfer(s).')diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.phpindex 8f7bdd8069..6bb1ac8a71 100644--- a/tests/Unit/Factory/AccountFactoryTest.php+++ b/tests/Unit/Factory/AccountFactoryTest.php@@ -34,9 +34,11 @@ use FireflyIII\Factory\TransactionGroupFactory;use FireflyIII\Models\Account;use FireflyIII\Models\AccountMeta;use FireflyIII\Models\AccountType;+use FireflyIII\Models\Preference;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Log;use Mockery;+use Preferences;use Tests\TestCase;/**@@ -82,10 +84,10 @@ class AccountFactoryTest extends TestCase// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ ////$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();+ //$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);@@ -140,14 +142,15 @@ class AccountFactoryTest extends TestCase// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'ccAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ ////$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();+ ////$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();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'cc_type', ''])->atLeast()->once()->andReturnNull();$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();-+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());@@ -172,45 +175,109 @@ class AccountFactoryTest extends TestCase}/**- * Leave virtual balance empty.+ * Test minimal set of data to make factory work (asset account).** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateEmptyVb(): void+ public function testCreateCurrencyCode(): void+ {+ $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,+ 'account_type' => 'asset',+ 'iban' => null,+ 'currency_code' => $currency->code,+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => null,+ 'active' => true,+ 'account_role' => 'defaultAsset',+ ];++ // mock calls to the repository:+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);++ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ $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);++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);++ /** @var AccountFactory $factory */+ $factory = app(AccountFactory::class);+ $factory->setUser($this->user());++ try {+ $account = $factory->create($data);+ } catch (FireflyException $e) {+ $this->assertTrue(false, $e->getMessage());++ return;+ }++ // assert stuff about account:+ $this->assertEquals($account->name, $data['name']);+ $this->assertEquals(AccountType::ASSET, $account->accountType->type);+ $this->assertEquals('', $account->iban);+ $this->assertTrue($account->active);+ $this->assertEquals('0', $account->virtual_balance);+++ }++ /**+ * Test minimal set of data to make factory work (asset account).+ *+ * @covers \FireflyIII\Factory\AccountFactory+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait+ */+ public function testCreateCurrencyId(): void{$accountRepos = $this->mock(AccountRepositoryInterface::class);$metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);-$this->mock(TransactionGroupFactory::class);- $data = [+ $currency = $this->getDollar();+ $data = ['account_type_id' => null,'account_type' => 'asset','iban' => null,+ 'currency_id' => $currency->id,'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => '',+ 'virtual_balance' => null,'active' => true,'account_role' => 'defaultAsset',];// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);+$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();- $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();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ $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);++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());+try {$account = $factory->create($data);} catch (FireflyException $e) {- Log::error($e->getMessage());- Log::error($e->getTraceAsString());$this->assertTrue(false, $e->getMessage());return;@@ -223,41 +290,43 @@ class AccountFactoryTest extends TestCase$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);- $account->forceDelete();}/**- * Create an expense account. This overrules the virtual balance.- * Role should not be set.+ * Leave virtual balance empty.** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateExpense(): void+ public function testCreateEmptyVb(): void{- $this->mock(AccountRepositoryInterface::class);- $this->mock(TransactionGroupFactory::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);- $metaFactory = $this->mock(AccountMetaFactory::class);- $data = [+ $this->mock(TransactionGroupFactory::class);+ $data = ['account_type_id' => null,- 'account_type' => 'expense',+ 'account_type' => 'asset','iban' => null,- 'name' => sprintf('Basic expense account #%d', $this->randomInt()),- 'virtual_balance' => '1243',+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => '','active' => true,'account_role' => 'defaultAsset',];- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ // mock calls to the repository:+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();+ ////$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->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();+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());@@ -273,122 +342,98 @@ class AccountFactoryTest extends TestCase// assert stuff about account:$this->assertEquals($account->name, $data['name']);- $this->assertEquals(AccountType::EXPENSE, $account->accountType->type);+ $this->assertEquals(AccountType::ASSET, $account->accountType->type);$this->assertEquals('', $account->iban);$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);- // get the role:- /** @var AccountMeta $meta */- $meta = $account->accountMeta()->where('name', 'accountRole')->first();- $this->assertNull($meta);$account->forceDelete();}/**- * Create an expense account. This overrules the virtual balance.- * Role should not be set. This time set type name, not ID.+ * Should return existing account.** @covers \FireflyIII\Factory\AccountFactory- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateExpenseFullType(): void+ public function testCreateExisting(): void{$this->mock(AccountRepositoryInterface::class);$this->mock(TransactionGroupFactory::class);- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);- $metaFactory = $this->mock(AccountMetaFactory::class);- $data = [+ $this->mock(AccountMetaFactory::class);+ $existing = $this->getRandomAsset();+ $data = ['account_type_id' => null,- 'account_type' => 'Expense account',+ 'account_type' => 'asset',+ 'name' => $existing->name,+ 'virtual_balance' => null,'iban' => null,- 'name' => sprintf('Basic expense account #%d', $this->randomInt()),- 'virtual_balance' => '1243','active' => true,'account_role' => 'defaultAsset',];++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();- $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();- $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;}// assert stuff about account:- $this->assertEquals($account->name, $data['name']);- $this->assertEquals(AccountType::EXPENSE, $account->accountType->type);- $this->assertEquals('', $account->iban);- $this->assertTrue($account->active);- $this->assertEquals('0', $account->virtual_balance);-- // get the role:- /** @var AccountMeta $meta */- $meta = $account->accountMeta()->where('name', 'accountRole')->first();- $this->assertNull($meta);- $account->forceDelete();+ $this->assertEquals($account->id, $existing->id);}/**- * Submit valid opening balance data for asset account.+ * Create an expense account. This overrules the virtual balance.+ * Role should not be set.** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateOB(): void+ public function testCreateExpense(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $groupFactory = $this->mock(TransactionGroupFactory::class);- $metaFactory = $this->mock(AccountMetaFactory::class);+ $this->mock(AccountRepositoryInterface::class);+ $this->mock(TransactionGroupFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);- $euro = $this->getEuro();- $data = [- 'account_type_id' => null,- 'account_type' => 'asset',- 'iban' => null,- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => null,- 'active' => true,- 'account_role' => 'defaultAsset',- 'opening_balance' => '100',- 'opening_balance_date' => new Carbon('2018-01-01'),- 'currency_id' => 1,- ];- // mock calls to the repository:- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);- $groupFactory->shouldReceive('setUser')->atLeast()->once();- $groupFactory->shouldReceive('create')->atLeast()->once();+ $metaFactory = $this->mock(AccountMetaFactory::class);+ $data = [+ 'account_type_id' => null,+ 'account_type' => 'expense',+ 'iban' => null,+ 'name' => sprintf('Basic expense account #%d', $this->randomInt()),+ 'virtual_balance' => '1243',+ 'active' => true,+ 'account_role' => 'defaultAsset',+ ];- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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);+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();+ //$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();++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());-try {$account = $factory->create($data);} catch (FireflyException $e) {+ Log::error($e->getMessage());+ Log::error($e->getTraceAsString());$this->assertTrue(false, $e->getMessage());return;@@ -396,69 +441,78 @@ class AccountFactoryTest extends TestCase// assert stuff about account:$this->assertEquals($account->name, $data['name']);- $this->assertEquals(AccountType::ASSET, $account->accountType->type);+ $this->assertEquals(AccountType::EXPENSE, $account->accountType->type);$this->assertEquals('', $account->iban);$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);++ // get the role:+ /** @var AccountMeta $meta */+ $meta = $account->accountMeta()->where('name', 'accountRole')->first();+ $this->assertNull($meta);+ $account->forceDelete();}/**- * Submit empty (amount = 0) IB data for asset account.+ * Create an expense account. This overrules the virtual balance.+ * Role should not be set. This time set type name, not ID.** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateOBZero(): void+ public function testCreateExpenseFullType(): void{- // mock repositories:- $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $this->mock(AccountRepositoryInterface::class);$this->mock(TransactionGroupFactory::class);- $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);- $euro = $this->getEuro();+ $metaFactory = $this->mock(AccountMetaFactory::class);$data = [- 'account_type_id' => null,- 'account_type' => 'asset',- 'iban' => null,- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => null,- 'active' => true,- 'account_role' => 'defaultAsset',- 'opening_balance' => '0.0',- 'opening_balance_date' => new Carbon('2018-01-01'),- 'currency_id' => 1,+ 'account_type_id' => null,+ 'account_type' => 'Expense account',+ 'iban' => null,+ 'name' => sprintf('Basic expense account #%d', $this->randomInt()),+ 'virtual_balance' => '1243',+ 'active' => true,+ 'account_role' => 'defaultAsset',];- // mock calls to the repository:- $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();- $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);+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());+ ////$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ $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();+ ////$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;}-// assert stuff about account:$this->assertEquals($account->name, $data['name']);- $this->assertEquals(AccountType::ASSET, $account->accountType->type);+ $this->assertEquals(AccountType::EXPENSE, $account->accountType->type);$this->assertEquals('', $account->iban);$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);+ // get the role:+ /** @var AccountMeta $meta */+ $meta = $account->accountMeta()->where('name', 'accountRole')->first();+ $this->assertNull($meta);$account->forceDelete();}@@ -470,8 +524,9 @@ class AccountFactoryTest extends TestCase*/public function testCreateIban(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $metaFactory = $this->mock(AccountMetaFactory::class);+ Log::info(sprintf('Now in test %s', __METHOD__));+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);$this->mock(TransactionGroupFactory::class);$data = [@@ -484,14 +539,18 @@ class AccountFactoryTest extends TestCase'account_role' => 'defaultAsset',];++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();+ //$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 */@@ -524,8 +583,9 @@ class AccountFactoryTest extends TestCase*/public function testCreateInvalidIban(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $metaFactory = $this->mock(AccountMetaFactory::class);+ Log::info(sprintf('Now in test %s', __METHOD__));+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);$this->mock(TransactionGroupFactory::class);$data = [@@ -542,12 +602,15 @@ class AccountFactoryTest extends TestCase$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();+ //$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();+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());@@ -577,12 +640,13 @@ class AccountFactoryTest extends TestCase*/public function testCreateNegativeIB(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $groupFactory = $this->mock(TransactionGroupFactory::class);- $metaFactory = $this->mock(AccountMetaFactory::class);+ Log::info(sprintf('Now in test %s', __METHOD__));+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $groupFactory = $this->mock(TransactionGroupFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);- $euro = $this->getEuro();- $data = [+ $euro = $this->getEuro();+ $data = ['account_type_id' => null,'account_type' => 'asset','iban' => null,@@ -595,19 +659,21 @@ class AccountFactoryTest extends TestCase'currency_id' => 1,];+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);++ $langPreference = new Preference;+ $langPreference->data = 'en_US';+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($langPreference);+// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$groupFactory->shouldReceive('setUser')->atLeast()->once();$groupFactory->shouldReceive('create')->atLeast()->once();$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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);$factory->setUser($this->user());@@ -630,6 +696,41 @@ class AccountFactoryTest extends TestCase$account->forceDelete();}+ /**+ * Can't find account type.+ *+ * @covers \FireflyIII\Factory\AccountFactory+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait+ */+ public function testCreateNoType(): void+ {+ Log::info(sprintf('Now in test %s', __METHOD__));+ $this->mock(AccountRepositoryInterface::class);+ $this->mock(TransactionGroupFactory::class);+ $this->mock(AccountMetaFactory::class);+ $data = [+ 'account_type_id' => null,+ 'account_type' => 'bla-bla',+ 'iban' => null,+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => null,+ 'active' => true,+ 'account_role' => 'defaultAsset',+ ];++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);++ /** @var AccountFactory $factory */+ $factory = app(AccountFactory::class);+ $factory->setUser($this->user());+ try {+ $factory->create($data);+ } catch (FireflyException $e) {+ $this->assertStringContainsString('AccountFactory::create() was unable to find account type #0 ("bla-bla").', $e->getMessage());+ }+ }+/*** Add some notes to asset account.*@@ -638,8 +739,9 @@ class AccountFactoryTest extends TestCase*/public function testCreateNotes(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $metaFactory = $this->mock(AccountMetaFactory::class);+ Log::info(sprintf('Now in test %s', __METHOD__));+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);$this->mock(TransactionGroupFactory::class);$data = [@@ -653,6 +755,9 @@ class AccountFactoryTest extends TestCase'notes' => 'Hello!',];+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+/** @var AccountFactory $factory */$factory = app(AccountFactory::class);$factory->setUser($this->user());@@ -661,10 +766,10 @@ class AccountFactoryTest extends TestCase$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();+ //$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 {@@ -687,39 +792,46 @@ class AccountFactoryTest extends TestCase}/**- * Test minimal set of data to make factory work (asset account).+ * Submit valid opening balance data for asset account.** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateCurrencyCode(): void+ public function testCreateOB(): void{- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $metaFactory = $this->mock(AccountMetaFactory::class);- $this->mock(TransactionGroupFactory::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $groupFactory = $this->mock(TransactionGroupFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);$currencyFactory = $this->mock(TransactionCurrencyFactory::class);-- $currency = $this->getDollar();- $data = [- 'account_type_id' => null,- 'account_type' => 'asset',- 'iban' => null,- 'currency_code' => $currency->code,- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => null,- 'active' => true,- 'account_role' => 'defaultAsset',+ $euro = $this->getEuro();+ $data = [+ 'account_type_id' => null,+ 'account_type' => 'asset',+ 'iban' => null,+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => null,+ 'active' => true,+ 'account_role' => 'defaultAsset',+ 'opening_balance' => '100',+ 'opening_balance_date' => new Carbon('2018-01-01'),+ 'currency_id' => 1,];// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);+ $groupFactory->shouldReceive('setUser')->atLeast()->once();+ $groupFactory->shouldReceive('create')->atLeast()->once();$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();- $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);+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();+ $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro);++ $langPreference = new Preference;+ $langPreference->data = 'en_US';+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($langPreference);++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);@@ -739,43 +851,48 @@ class AccountFactoryTest extends TestCase$this->assertEquals('', $account->iban);$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);--}/**- * Test minimal set of data to make factory work (asset account).+ * Submit empty (amount = 0) IB data for asset account.** @covers \FireflyIII\Factory\AccountFactory* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateCurrencyId(): void+ public function testCreateOBZero(): void{+ // mock repositories:$accountRepos = $this->mock(AccountRepositoryInterface::class);- $metaFactory = $this->mock(AccountMetaFactory::class);- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);$this->mock(TransactionGroupFactory::class);- $currency = $this->getDollar();- $data = [- 'account_type_id' => null,- 'account_type' => 'asset',- 'iban' => null,- 'currency_id' => $currency->id,- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => null,- 'active' => true,- 'account_role' => 'defaultAsset',+ $metaFactory = $this->mock(AccountMetaFactory::class);+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);+ $euro = $this->getEuro();+ $data = [+ 'account_type_id' => null,+ 'account_type' => 'asset',+ 'iban' => null,+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => null,+ 'active' => true,+ 'account_role' => 'defaultAsset',+ 'opening_balance' => '0.0',+ 'opening_balance_date' => new Carbon('2018-01-01'),+ 'currency_id' => 1,];// mock calls to the repository:$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();- $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);+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();+ $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro);++ $langPreference = new Preference;+ $langPreference->data = 'en_US';+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($langPreference);++ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);/** @var AccountFactory $factory */$factory = app(AccountFactory::class);@@ -789,6 +906,7 @@ class AccountFactoryTest extends TestCasereturn;}+// assert stuff about account:$this->assertEquals($account->name, $data['name']);$this->assertEquals(AccountType::ASSET, $account->accountType->type);@@ -796,75 +914,68 @@ class AccountFactoryTest extends TestCase$this->assertTrue($account->active);$this->assertEquals('0', $account->virtual_balance);+ $account->forceDelete();}/**- * Should return existing account.+ * Test minimal set of data to make factory work (asset account).+ *+ * Add some details** @covers \FireflyIII\Factory\AccountFactory+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait*/- public function testCreateExisting(): void+ public function testCreateWithNumbers(): void{- $this->mock(AccountRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);$this->mock(TransactionGroupFactory::class);- $this->mock(AccountMetaFactory::class);- $existing = $this->getRandomAsset();- $data = [- 'account_type_id' => null,- 'account_type' => 'asset',- 'name' => $existing->name,- 'virtual_balance' => null,- 'iban' => null,- 'active' => true,- 'account_role' => 'defaultAsset',+ $euro = $this->getEuro();+ $data = [+ 'account_type_id' => null,+ 'account_type' => 'asset',+ 'iban' => null,+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),+ 'virtual_balance' => null,+ 'active' => true,+ 'account_role' => 'defaultAsset',+ 'BIC' => 'BIC',+ 'include_net_worth' => false,+ 'account_number' => '1234',];+ // mock calls to the repository:+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', '1234'])->atLeast()->once()->andReturnNull();+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', 'BIC'])->atLeast()->once()->andReturnNull();+ $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', false])->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);$factory->setUser($this->user());-try {$account = $factory->create($data);} catch (FireflyException $e) {+ Log::error($e->getMessage());+ Log::error($e->getTraceAsString());$this->assertTrue(false, $e->getMessage());return;}// assert stuff about account:- $this->assertEquals($account->id, $existing->id);- }-- /**- * Can't find account type.- *- * @covers \FireflyIII\Factory\AccountFactory- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait- */- public function testCreateNoType(): void- {- $this->mock(AccountRepositoryInterface::class);- $this->mock(TransactionGroupFactory::class);- $this->mock(AccountMetaFactory::class);- $data = [- 'account_type_id' => null,- 'account_type' => 'bla-bla',- 'iban' => null,- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),- 'virtual_balance' => null,- 'active' => true,- 'account_role' => 'defaultAsset',- ];+ $this->assertEquals($account->name, $data['name']);+ $this->assertEquals(AccountType::ASSET, $account->accountType->type);+ $this->assertEquals('', $account->iban);+ $this->assertTrue($account->active);+ $this->assertEquals('0', $account->virtual_balance);- /** @var AccountFactory $factory */- $factory = app(AccountFactory::class);- $factory->setUser($this->user());- try {- $factory->create($data);- } catch (FireflyException $e) {- $this->assertStringContainsString('AccountFactory::create() was unable to find account type #0 ("bla-bla").', $e->getMessage());- }+ $account->forceDelete();}/**@@ -901,17 +1012,20 @@ class AccountFactoryTest extends TestCase$this->mock(TransactionGroupFactory::class);$metaFactory = $this->mock(AccountMetaFactory::class);/** @var Account $account */- $account = $this->getRandomRevenue();+ $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(), 'account_number', ''])->atLeast()->once()->andReturnNull();$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();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull();- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->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();+ //$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();+ $euro = $this->getEuro();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);+$name = sprintf('New %s', $account->name);/** @var AccountFactory $factory */diff --git a/tests/Unit/Factory/PiggyBankEventFactoryTest.php b/tests/Unit/Factory/PiggyBankEventFactoryTest.phpindex c4dace7159..899f81ac27 100644--- a/tests/Unit/Factory/PiggyBankEventFactoryTest.php+++ b/tests/Unit/Factory/PiggyBankEventFactoryTest.php@@ -101,6 +101,7 @@ class PiggyBankEventFactoryTest extends TestCase$repos->shouldReceive('getRepetition')->andReturn(null);$repos->shouldReceive('getExactAmount')->andReturn('0');+ Log::warning('The following error is part of a test.');$this->assertNull($factory->create($transfer, $piggy));}@@ -115,7 +116,7 @@ class PiggyBankEventFactoryTest extends TestCase$piggy = $this->user()->piggyBanks()->first();/** @var PiggyBankEventFactory $factory */$factory = app(PiggyBankEventFactory::class);-+ Log::warning('The following error is part of a test.');$this->assertNull($factory->create($deposit, $piggy));}diff --git a/tests/Unit/Factory/RecurrenceFactoryTest.php b/tests/Unit/Factory/RecurrenceFactoryTest.phpindex a88b2712f6..812fea990f 100644--- a/tests/Unit/Factory/RecurrenceFactoryTest.php+++ b/tests/Unit/Factory/RecurrenceFactoryTest.php@@ -34,7 +34,6 @@ use FireflyIII\Factory\PiggyBankFactory;use FireflyIII\Factory\RecurrenceFactory;use FireflyIII\Factory\TransactionCurrencyFactory;use FireflyIII\Factory\TransactionTypeFactory;-use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Validation\AccountValidator;@@ -124,11 +123,6 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],'repetitions' => [['type' => 'daily',@@ -154,6 +148,9 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],@@ -167,6 +164,38 @@ class RecurrenceFactoryTest extends TestCase$this->assertEquals($result->title, $data['recurrence']['title']);}+ /**+ * @covers \FireflyIII\Factory\RecurrenceFactory+ */+ public function testCreateBadTransactionType(): void+ {+ $accountFactory = $this->mock(AccountFactory::class);+ $validator = $this->mock(AccountValidator::class);+ $typeFactory = $this->mock(TransactionTypeFactory::class);+ $data = [+ 'recurrence' => [+ 'type' => 'bad type',+ ],+ ];+++ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(null);+++ /** @var RecurrenceFactory $factory */+ $factory = app(RecurrenceFactory::class);+ $factory->setUser($this->user());+ $result = null;+ Log::warning('The following error is part of a test.');+ try {+ $result = $factory->create($data);+ } catch (FireflyException $e) {+ $this->assertEquals('Cannot make a recurring transaction of type "bad type"', $e->getMessage());+ $this->assertTrue(true);+ }+ $this->assertNull($result);+ }+/*** With piggy bank. With tags. With budget. With category.* Submit account names, not types. This is a withdrawal.@@ -232,11 +261,6 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],'repetitions' => [['type' => 'daily',@@ -262,6 +286,9 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],@@ -276,21 +303,19 @@ class RecurrenceFactoryTest extends TestCase}/**- * With piggy bank. With tags. With budget. With category.- * Submit account names, not types. Also a withdrawal+ * Deposit. With piggy bank. With tags. With budget. With category.** @covers \FireflyIII\Factory\RecurrenceFactory* @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait*/- public function testCreateNewByName(): void+ public function testCreateDeposit(): void{// objects to return:$piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();- $source = $this->getRandomAsset();- $destination = $this->getRandomExpense();+ $source = $this->getRandomRevenue();+ $destination = $this->getRandomAsset();$budget = $this->user()->budgets()->inRandomOrder()->first();$category = $this->user()->categories()->inRandomOrder()->first();- $euro = $this->getEuro();// mock other factories:$piggyFactory = $this->mock(PiggyBankFactory::class);@@ -303,29 +328,20 @@ class RecurrenceFactoryTest extends TestCase$validator = $this->mock(AccountValidator::class);// mock calls:- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();- $piggyFactory->shouldReceive('setUser')->atLeast()->once();- $budgetFactory->shouldReceive('setUser')->atLeast()->once();- $categoryFactory->shouldReceive('setUser')->once();+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();+ $piggyFactory->shouldReceive('setUser')->once();+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);$accountRepos->shouldReceive('setUser')->twice();- $piggyFactory->shouldReceive('find')->atLeast()->once()->withArgs([1, 'Bla bla'])->andReturn($piggyBank);-- // return NULL for account ID's.- $accountRepos->shouldReceive('findNull')->twice()->andReturn(null, null);- // but find them by name (at least the first one):- $accountRepos->shouldReceive('findByName')->twice()->andReturn($source, null);-- // this activates the "create by name" routine (account factory):- $accountFactory->shouldReceive('setUser')->atLeast()->once();- $accountFactory->shouldReceive('findOrCreate')->atLeast()->once()- ->andReturn($destination);+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);$currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);$currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);-+ $budgetFactory->shouldReceive('setUser')->once();$budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);++ $categoryFactory->shouldReceive('setUser')->once();$categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);// validator:@@ -337,7 +353,7 @@ class RecurrenceFactoryTest extends TestCase// data for basic recurrence.$data = ['recurrence' => [- 'type' => 'withdrawal',+ 'type' => 'deposit','first_date' => Carbon::now()->addDay(),'repetitions' => 0,'title' => 'Test recurrence' . $this->randomInt(),@@ -346,11 +362,6 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],'repetitions' => [['type' => 'daily',@@ -364,7 +375,7 @@ class RecurrenceFactoryTest extends TestCase'source_id' => 1,'source_name' => 'Some name','destination_id' => 2,- 'destination_name' => 'some other name',+ 'destination_name' => 'some otjer name','currency_id' => 1,'currency_code' => 'EUR','foreign_currency_id' => null,@@ -376,11 +387,17 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],];- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));+++ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(2));+/** @var RecurrenceFactory $factory */$factory = app(RecurrenceFactory::class);$factory->setUser($this->user());@@ -389,21 +406,22 @@ class RecurrenceFactoryTest extends TestCase$this->assertEquals($result->title, $data['recurrence']['title']);}-/**- * Deposit. With piggy bank. With tags. With budget. With category.+ * With piggy bank. With tags. With budget. With category.+ * Submit account names, not types. Also a withdrawal** @covers \FireflyIII\Factory\RecurrenceFactory* @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait*/- public function testCreateDeposit(): void+ public function testCreateNewByName(): void{// objects to return:$piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();- $source = $this->getRandomRevenue();- $destination = $this->getRandomAsset();+ $source = $this->getRandomAsset();+ $destination = $this->getRandomExpense();$budget = $this->user()->budgets()->inRandomOrder()->first();$category = $this->user()->categories()->inRandomOrder()->first();+ $euro = $this->getEuro();// mock other factories:$piggyFactory = $this->mock(PiggyBankFactory::class);@@ -416,20 +434,29 @@ class RecurrenceFactoryTest extends TestCase$validator = $this->mock(AccountValidator::class);// mock calls:- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();- $piggyFactory->shouldReceive('setUser')->once();- $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();+ $piggyFactory->shouldReceive('setUser')->atLeast()->once();+ $budgetFactory->shouldReceive('setUser')->atLeast()->once();+ $categoryFactory->shouldReceive('setUser')->once();$accountRepos->shouldReceive('setUser')->twice();- $accountRepos->shouldReceive('findNull')->twice()->andReturn($source, $destination);+ $piggyFactory->shouldReceive('find')->atLeast()->once()->withArgs([1, 'Bla bla'])->andReturn($piggyBank);++ // return NULL for account ID's.+ $accountRepos->shouldReceive('findNull')->twice()->andReturn(null, null);+ // but find them by name (at least the first one):+ $accountRepos->shouldReceive('findByName')->twice()->andReturn($source, null);++ // this activates the "create by name" routine (account factory):+ $accountFactory->shouldReceive('setUser')->atLeast()->once();+ $accountFactory->shouldReceive('findOrCreate')->atLeast()->once()+ ->andReturn($destination);$currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);$currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);- $budgetFactory->shouldReceive('setUser')->once();- $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);- $categoryFactory->shouldReceive('setUser')->once();+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);$categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);// validator:@@ -441,7 +468,7 @@ class RecurrenceFactoryTest extends TestCase// data for basic recurrence.$data = ['recurrence' => [- 'type' => 'deposit',+ 'type' => 'withdrawal','first_date' => Carbon::now()->addDay(),'repetitions' => 0,'title' => 'Test recurrence' . $this->randomInt(),@@ -450,11 +477,6 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],'repetitions' => [['type' => 'daily',@@ -468,7 +490,7 @@ class RecurrenceFactoryTest extends TestCase'source_id' => 1,'source_name' => 'Some name','destination_id' => 2,- 'destination_name' => 'some otjer name',+ 'destination_name' => 'some other name','currency_id' => 1,'currency_code' => 'EUR','foreign_currency_id' => null,@@ -480,14 +502,14 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],];--- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(2));-+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));/** @var RecurrenceFactory $factory */$factory = app(RecurrenceFactory::class);$factory->setUser($this->user());@@ -546,7 +568,7 @@ class RecurrenceFactoryTest extends TestCase// data for basic recurrence.$data = [- 'recurrence' => [+ 'recurrence' => ['type' => 'withdrawal','first_date' => Carbon::now()->addDay(),'repetitions' => 0,@@ -556,11 +578,7 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],+'repetitions' => [['type' => 'daily',@@ -586,6 +604,9 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],@@ -661,11 +682,6 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => [],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],'repetitions' => [['type' => 'daily',@@ -691,6 +707,9 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => [],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],@@ -755,7 +774,7 @@ class RecurrenceFactoryTest extends TestCase// data for basic recurrence.$data = [- 'recurrence' => [+ 'recurrence' => ['type' => 'transfer','first_date' => Carbon::now()->addDay(),'repetitions' => 0,@@ -765,11 +784,7 @@ class RecurrenceFactoryTest extends TestCase'active' => true,'repeat_until' => null,],- 'meta' => [- 'tags' => ['a', 'b', 'c'],- 'piggy_bank_id' => 1,- 'piggy_bank_name' => 'Bla bla',- ],+'repetitions' => [['type' => 'daily',@@ -795,6 +810,9 @@ class RecurrenceFactoryTest extends TestCase'budget_name' => 'Some budget','category_id' => 2,'category_name' => 'Some category',+ 'tags' => ['a', 'b', 'c'],+ 'piggy_bank_id' => 1,+ 'piggy_bank_name' => 'Bla bla',],],@@ -812,35 +830,4 @@ class RecurrenceFactoryTest extends TestCase$this->assertEquals($result->title, $data['recurrence']['title']);}- /**- * @covers \FireflyIII\Factory\RecurrenceFactory- */- public function testCreateBadTransactionType(): void- {- $accountFactory = $this->mock(AccountFactory::class);- $validator = $this->mock(AccountValidator::class);- $typeFactory = $this->mock(TransactionTypeFactory::class);- $data = [- 'recurrence' => [- 'type' => 'bad type',- ],- ];--- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(null);--- /** @var RecurrenceFactory $factory */- $factory = app(RecurrenceFactory::class);- $factory->setUser($this->user());- $result = null;- try {- $result = $factory->create($data);- } catch (FireflyException $e) {- $this->assertEquals('Cannot make a recurring transaction of type "bad type"', $e->getMessage());- $this->assertTrue(true);- }- $this->assertNull($result);- }-}diff --git a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php b/tests/Unit/Factory/TransactionCurrencyFactoryTest.phpindex ce9fb583b3..562220d66c 100644--- a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php+++ b/tests/Unit/Factory/TransactionCurrencyFactoryTest.php@@ -66,6 +66,7 @@ class TransactionCurrencyFactoryTest extends TestCase{/** @var TransactionCurrencyFactory $factory */$factory = app(TransactionCurrencyFactory::class);+ Log::warning('The following error is part of a test.');$result = $factory->create(['name' => null, 'code' => null, 'symbol' => null, 'decimal_places' => null, 'enabled' => true]);$this->assertNull($result);}@@ -100,7 +101,6 @@ class TransactionCurrencyFactoryTest extends TestCase*/public function testFindByCode(): void{- // ;$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();/** @var TransactionCurrencyFactory $factory */$factory = app(TransactionCurrencyFactory::class);diff --git a/tests/Unit/Factory/TransactionFactoryTest.php b/tests/Unit/Factory/TransactionFactoryTest.phpindex bb03800d75..4830bdf952 100644--- a/tests/Unit/Factory/TransactionFactoryTest.php+++ b/tests/Unit/Factory/TransactionFactoryTest.php@@ -72,7 +72,7 @@ class TransactionFactoryTest extends TestCase$transaction = $factory->createNegative($amount, null);$this->assertEquals($transaction->account_id, $account->id);- $this->assertEquals('-10', $transaction->amount);+ $this->assertEquals('-10.000000000000', $transaction->amount);$transaction->forceDelete();}@@ -134,8 +134,8 @@ class TransactionFactoryTest extends TestCase$transaction = $factory->createNegative($amount, $amount);$this->assertEquals($transaction->account_id, $account->id);- $this->assertEquals('-10', $transaction->amount);- $this->assertEquals('-10', $transaction->foreign_amount);+ $this->assertEquals('-10.000000000000', $transaction->amount);+ $this->assertEquals('-10.000000000000', $transaction->foreign_amount);$this->assertEquals($euro->id, $transaction->transaction_currency_id);$this->assertEquals($dollar->id, $transaction->foreign_currency_id);$transaction->forceDelete();diff --git a/tests/Unit/Factory/TransactionJournalFactoryTest.php b/tests/Unit/Factory/TransactionJournalFactoryTest.phpindex 60ccb47a0a..78ceee5842 100644--- a/tests/Unit/Factory/TransactionJournalFactoryTest.php+++ b/tests/Unit/Factory/TransactionJournalFactoryTest.php@@ -68,6 +68,7 @@ class TransactionJournalFactoryTest extends TestCase/*** Submit empty array.+ ** @covers \FireflyIII\Factory\TransactionJournalFactory* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait*/@@ -103,7 +104,7 @@ class TransactionJournalFactoryTest extends TestCase/** @var TransactionJournalFactory $factory */$factory = app(TransactionJournalFactory::class);$factory->setUser($this->user());-+ Log::warning('The following error is part of a test.');try {$collection = $factory->create($submission);} catch (FireflyException $e) {diff --git a/tests/Unit/Handlers/Events/UserEventHandlerTest.php b/tests/Unit/Handlers/Events/UserEventHandlerTest.phpindex 7640184b25..c41c2651af 100644--- a/tests/Unit/Handlers/Events/UserEventHandlerTest.php+++ b/tests/Unit/Handlers/Events/UserEventHandlerTest.php@@ -30,6 +30,7 @@ use FireflyIII\Mail\ConfirmEmailChangeMail;use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;use FireflyIII\Mail\UndoEmailChangeMail;+use FireflyIII\Models\Preference;use FireflyIII\Models\Role;use FireflyIII\Repositories\User\UserRepositoryInterface;use Illuminate\Auth\Events\Login;@@ -109,7 +110,7 @@ class UserEventHandlerTest extends TestCase$repository->shouldReceive('getRole')->once()->andReturn(null);$repository->shouldReceive('attachRole')->once()->withArgs([Mockery::any(), 'owner']);$repository->shouldReceive('createRole')->once()->withArgs(['owner', 'Site Owner', 'User runs this instance of FF3'])->andReturn(new Role);-+ Log::warning('The following error is part of a test.');$listener->checkSingleUserIsAdmin($event);$this->assertTrue(true);}@@ -178,7 +179,13 @@ class UserEventHandlerTest extends TestCase*/public function testSendEmailChangeConfirmMail(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Mail::fake();++ $tokenPref = new Preference;+ $tokenPref->data = 'token';+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_confirm_token', 'invalid'])->andReturn($tokenPref);+$user = $this->emptyUser();$event = new UserChangedEmail($user, 'new@new', 'old@old', '127.0.0.1');$listener = new UserEventHandler;@@ -201,14 +208,18 @@ class UserEventHandlerTest extends TestCase*/public function testSendEmailChangeUndoMail(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Mail::fake();++ $tokenPref = new Preference;+ $tokenPref->data = 'token';+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'email_change_undo_token', 'invalid'])->andReturn($tokenPref);+$user = $this->emptyUser();$event = new UserChangedEmail($user, 'new@new', 'old@old', '127.0.0.1');$listener = new UserEventHandler;$listener->sendEmailChangeUndoMail($event);- // must send user an email:-Mail::assertSent(UndoEmailChangeMail::class, function ($mail) {return $mail->hasTo('old@old') && '127.0.0.1' === $mail->ipAddress;@@ -225,6 +236,7 @@ class UserEventHandlerTest extends TestCase*/public function testSendNewPassword(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Mail::fake();$user = $this->emptyUser();$event = new RequestedNewPassword($user, 'token', '127.0.0.1');@@ -248,6 +260,7 @@ class UserEventHandlerTest extends TestCase*/public function testSendRegistrationMail(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Mail::fake();$user = $this->emptyUser();$event = new RegisteredUser($user, '127.0.0.1');diff --git a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.phpindex ecfc95019a..17a83cbf4d 100644--- a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php+++ b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php@@ -61,6 +61,7 @@ class AttachmentHelperTest extends TestCase$path = resource_path('stubs/binary.bin');$file = new UploadedFile($path, 'binary.bin', 'application/octet-stream', filesize($path), null, true);+ Log::warning('The following error is part of a test.');$helper->saveAttachmentsForModel($journal, [$file]);$errors = $helper->getErrors();$messages = $helper->getMessages();@@ -103,7 +104,6 @@ class AttachmentHelperTest extends TestCasepublic function testSaveAttachmentFromApi(): void{// mock calls:- Crypt::shouldReceive('encrypt')->times(1)->andReturn('Some encrypted content');Storage::fake('upload');$path = public_path('apple-touch-icon.png');@@ -162,6 +162,7 @@ class AttachmentHelperTest extends TestCase);// call helper+ Log::warning('The following error is part of a test.');$result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));$this->assertFalse($result);@@ -195,6 +196,7 @@ class AttachmentHelperTest extends TestCase$path = public_path('apple-touch-icon.png');$file = new UploadedFile($path, 'apple-touch-icon.png', 'image/png', filesize($path), null, true);+ Log::warning('The following error is part of a test.');$helper->saveAttachmentsForModel($journal, [$file]);$errors = $helper->getErrors();$messages = $helper->getMessages();diff --git a/tests/Unit/Helpers/Help/HelpTest.php b/tests/Unit/Helpers/Help/HelpTest.phpindex ed6a4278fb..159dde2959 100644--- a/tests/Unit/Helpers/Help/HelpTest.php+++ b/tests/Unit/Helpers/Help/HelpTest.php@@ -87,7 +87,7 @@ class HelpTest extends TestCase//client instance is bound to the mock here.$this->app->instance(Client::class, $client);-+ Log::warning('The following error is part of a test.');// now let's see what happens:$help = new Help;$result = $help->getFromGitHub('test-route', 'en_US');diff --git a/tests/Unit/Import/Converter/AmountCreditTest.php b/tests/Unit/Import/Converter/AmountCreditTest.phpindex 57ff0877f2..33dc43dd90 100644--- a/tests/Unit/Import/Converter/AmountCreditTest.php+++ b/tests/Unit/Import/Converter/AmountCreditTest.php@@ -155,22 +155,22 @@ class AmountCreditTest extends TestCase'63 5212.4440' => '635212.4440','163 5219.1634567898' => '1635219.1634567898','444 163 5219.1634567898' => '4441635219.1634567898',- '-0.34918323' => '0.34918323',+ '-0.34918323' => '0.349183230000','0.208' => '0.208',- '-0.15' => '0.15',- '-0.03881677' => '0.03881677',+ '-0.15' => '0.150000000000',+ '-0.03881677' => '0.038816770000','0.33' => '0.33',- '-0.1' => '0.1',+ '-0.1' => '0.100000000000','0.01124' => '0.01124',- '-0.01124' => '0.01124',+ '-0.01124' => '0.011240000000','0.115' => '0.115',- '-0.115' => '0.115',+ '-0.115' => '0.115000000000','1.33' => '1.33','$1.23' => '1.23','€1,44' => '1.44',- '(33.52)' => '33.52',- '€(63.12)' => '63.12',- '($182.77)' => '182.77',+ '(33.52)' => '33.520000000000',+ '€(63.12)' => '63.120000000000',+ '($182.77)' => '182.770000000000',// double minus because why the hell not'--0.03881677' => '0.03881677',diff --git a/tests/Unit/Import/Converter/AmountDebitTest.php b/tests/Unit/Import/Converter/AmountDebitTest.phpindex cc62382a3e..64aed537ce 100644--- a/tests/Unit/Import/Converter/AmountDebitTest.php+++ b/tests/Unit/Import/Converter/AmountDebitTest.php@@ -51,133 +51,133 @@ class AmountDebitTest extends TestCase{$values = [- '0' => '0',- '0.0' => '0.0',- '0.1' => '-0.1',- '.2' => '-0.2',- '0.01' => '-0.01',- '1' => '-1',- '1.0' => '-1.0',- '1.1' => '-1.1',- '1.12' => '-1.12',- '1.10' => '-1.10',- '12' => '-12',- '12.3' => '-12.3',- '12.34' => '-12.34',- '123' => '-123',- '123.4' => '-123.4',- '123.45' => '-123.45',- '1234' => '-1234',- '1234.5' => '-1234.5',- '1234.56' => '-1234.56',- '1 234' => '-1234',- '1 234.5' => '-1234.5',- '1 234.56' => '-1234.56',- '1,234' => '-1234',- '1,234.5' => '-1234.5',- '1,234.56' => '-1234.56',- '123,456,789' => '-123456789',- '0,0' => '0.0',- '0,1' => '-0.1',- ',2' => '-0.2',- '0,01' => '-0.01',- '1,0' => '-1.0',- '1,1' => '-1.1',- '1,12' => '-1.12',- '1,10' => '-1.10',- '12,3' => '-12.3',- '12,34' => '-12.34',- '123,4' => '-123.4',- '123,45' => '-123.45',- '1234,5' => '-1234.5',- '1234,56' => '-1234.56',- '1 234,5' => '-1234.5',- '1 234,56' => '-1234.56',- '1.234' => '-1.234', // will no longer match as 1234, but as 1.234- '1.234,5' => '-1234.5',- '1.234,56' => '-1234.56',+ '0' => '0.000000000000',+ '0.0' => '0.000000000000',+ '0.1' => '-0.100000000000',+ '.2' => '-0.200000000000',+ '0.01' => '-0.010000000000',+ '1' => '-1.000000000000',+ '1.0' => '-1.000000000000',+ '1.1' => '-1.100000000000',+ '1.12' => '-1.120000000000',+ '1.10' => '-1.100000000000',+ '12' => '-12.000000000000',+ '12.3' => '-12.300000000000',+ '12.34' => '-12.340000000000',+ '123' => '-123.000000000000',+ '123.4' => '-123.400000000000',+ '123.45' => '-123.450000000000',+ '1234' => '-1234.000000000000',+ '1234.5' => '-1234.500000000000',+ '1234.56' => '-1234.560000000000',+ '1 234' => '-1234.000000000000',+ '1 234.5' => '-1234.500000000000',+ '1 234.56' => '-1234.560000000000',+ '1,234' => '-1234.000000000000',+ '1,234.5' => '-1234.500000000000',+ '1,234.56' => '-1234.560000000000',+ '123,456,789' => '-123456789.000000000000',+ '0,0' => '0.000000000000',+ '0,1' => '-0.100000000000',+ ',2' => '-0.200000000000',+ '0,01' => '-0.010000000000',+ '1,0' => '-1.000000000000',+ '1,1' => '-1.100000000000',+ '1,12' => '-1.120000000000',+ '1,10' => '-1.100000000000',+ '12,3' => '-12.300000000000',+ '12,34' => '-12.340000000000',+ '123,4' => '-123.400000000000',+ '123,45' => '-123.450000000000',+ '1234,5' => '-1234.500000000000',+ '1234,56' => '-1234.560000000000',+ '1 234,5' => '-1234.500000000000',+ '1 234,56' => '-1234.560000000000',+ '1.234' => '-1.234000000000', // will no longer match as 1234, but as 1.234+ '1.234,5' => '-1234.500000000000',+ '1.234,56' => '-1234.560000000000',// many decimals- '2.00' => '-2.00',- '3.000' => '-3.000',- '4.0000' => '-4.0000',- '5.000' => '-5.000',- '6.0000' => '-6.0000',- '7.200' => '-7.200',- '8.2000' => '-8.2000',- '9.330' => '-9.330',- '10.3300' => '-10.3300',- '11.444' => '-11.444',- '12.4440' => '-12.4440',- '13.5555' => '-13.5555',- '14.45678' => '-14.45678',- '15.456789' => '-15.456789',- '16.4567898' => '-16.4567898',- '17.34567898' => '-17.34567898',- '18.134567898' => '-18.134567898',- '19.1634567898' => '-19.1634567898',- '20.16334567898' => '-20.16334567898',- '21.16364567898' => '-21.16364567898',+ '2.00' => '-2.000000000000',+ '3.000' => '-3.000000000000',+ '4.0000' => '-4.000000000000',+ '5.000' => '-5.000000000000',+ '6.0000' => '-6.000000000000',+ '7.200' => '-7.200000000000',+ '8.2000' => '-8.200000000000',+ '9.330' => '-9.330000000000',+ '10.3300' => '-10.330000000000',+ '11.444' => '-11.444000000000',+ '12.4440' => '-12.444000000000',+ '13.5555' => '-13.555500000000',+ '14.45678' => '-14.456780000000',+ '15.456789' => '-15.456789000000',+ '16.4567898' => '-16.456789800000',+ '17.34567898' => '-17.345678980000',+ '18.134567898' => '-18.134567898000',+ '19.1634567898' => '-19.163456789800',+ '20.16334567898' => '-20.163345678980',+ '21.16364567898' => '-21.163645678980','22.163644567898' => '-22.163644567898','22.1636445670069' => '-22.163644567006',// many decimals, mixed, large numbers- '63522.00' => '-63522.00',- '63523.000' => '-63523.000',- '63524.0000' => '-63524.0000',- '63525.000' => '-63525.000',- '63526.0000' => '-63526.0000',- '63527.200' => '-63527.200',- '63528.2000' => '-63528.2000',- '63529.330' => '-63529.330',- '635210.3300' => '-635210.3300',- '635211.444' => '-635211.444',- '635212.4440' => '-635212.4440',- '635213.5555' => '-635213.5555',- '635214.45678' => '-635214.45678',- '635215.456789' => '-635215.456789',- '635216.4567898' => '-635216.4567898',- '635217.34567898' => '-635217.34567898',- '635218.134567898' => '-635218.134567898',- '635219.1634567898' => '-635219.1634567898',- '635220.16334567898' => '-635220.16334567898',- '635221.16364567898' => '-635221.16364567898',+ '63522.00' => '-63522.000000000000',+ '63523.000' => '-63523.000000000000',+ '63524.0000' => '-63524.000000000000',+ '63525.000' => '-63525.000000000000',+ '63526.0000' => '-63526.000000000000',+ '63527.200' => '-63527.200000000000',+ '63528.2000' => '-63528.200000000000',+ '63529.330' => '-63529.330000000000',+ '635210.3300' => '-635210.330000000000',+ '635211.444' => '-635211.444000000000',+ '635212.4440' => '-635212.444000000000',+ '635213.5555' => '-635213.555500000000',+ '635214.45678' => '-635214.456780000000',+ '635215.456789' => '-635215.456789000000',+ '635216.4567898' => '-635216.456789800000',+ '635217.34567898' => '-635217.345678980000',+ '635218.134567898' => '-635218.134567898000',+ '635219.1634567898' => '-635219.163456789800',+ '635220.16334567898' => '-635220.163345678980',+ '635221.16364567898' => '-635221.163645678980','635222.163644567898' => '-635222.163644567898',// many decimals, mixed, also mixed thousands separators- '63 522.00' => '-63522.00',- '63 523.000' => '-63523.000',- '63,524.0000' => '-63524.0000',- '63 525.000' => '-63525.000',- '63,526.0000' => '-63526.0000',- '63 527.200' => '-63527.200',- '63 528.2000' => '-63528.2000',- '63 529.330' => '-63529.330',- '63,5210.3300' => '-635210.3300',- '63,5211.444' => '-635211.444',- '63 5212.4440' => '-635212.4440',- '163 5219.1634567898' => '-1635219.1634567898',- '444 163 5219.1634567898' => '-4441635219.1634567898',- '-0.34918323' => '-0.34918323',- '0.208' => '-0.208',- '-0.15' => '-0.15',- '-0.03881677' => '-0.03881677',- '0.33' => '-0.33',- '-0.1' => '-0.1',- '0.01124' => '-0.01124',- '-0.01124' => '-0.01124',- '0.115' => '-0.115',- '-0.115' => '-0.115',- '1.33' => '-1.33',- '$1.23' => '-1.23',- '€1,44' => '-1.44',- '(33.52)' => '-33.52',- '€(63.12)' => '-63.12',- '($182.77)' => '-182.77',+ '63 522.00' => '-63522.000000000000',+ '63 523.000' => '-63523.000000000000',+ '63,524.0000' => '-63524.000000000000',+ '63 525.000' => '-63525.000000000000',+ '63,526.0000' => '-63526.000000000000',+ '63 527.200' => '-63527.200000000000',+ '63 528.2000' => '-63528.200000000000',+ '63 529.330' => '-63529.330000000000',+ '63,5210.3300' => '-635210.330000000000',+ '63,5211.444' => '-635211.444000000000',+ '63 5212.4440' => '-635212.444000000000',+ '163 5219.1634567898' => '-1635219.163456789800',+ '444 163 5219.1634567898' => '-4441635219.163456789800',+ '-0.34918323' => '-0.349183230000',+ '0.208' => '-0.208000000000',+ '-0.15' => '-0.150000000000',+ '-0.03881677' => '-0.038816770000',+ '0.33' => '-0.330000000000',+ '-0.1' => '-0.100000000000',+ '0.01124' => '-0.011240000000',+ '-0.01124' => '-0.011240000000',+ '0.115' => '-0.115000000000',+ '-0.115' => '-0.115000000000',+ '1.33' => '-1.330000000000',+ '$1.23' => '-1.230000000000',+ '€1,44' => '-1.440000000000',+ '(33.52)' => '-33.520000000000',+ '€(63.12)' => '-63.120000000000',+ '($182.77)' => '-182.770000000000',// double minus because why the hell not- '--0.03881677' => '-0.03881677',- '--0.33' => '-0.33',- '--$1.23' => '-1.23',- '--63 5212.4440' => '-635212.4440',- '--,2' => '-0.2',+ '--0.03881677' => '-0.038816770000',+ '--0.33' => '-0.330000000000',+ '--$1.23' => '-1.230000000000',+ '--63 5212.4440' => '-635212.444000000000',+ '--,2' => '-0.200000000000',];foreach ($values as $value => $expected) {$converter = new AmountDebit;@@ -193,6 +193,6 @@ class AmountDebitTest extends TestCase{$converter = new AmountDebit;$result = $converter->convert(null);- $this->assertEquals('0', $result);+ $this->assertEquals('0.000000000000', $result);}}diff --git a/tests/Unit/Import/Converter/AmountNegatedTest.php b/tests/Unit/Import/Converter/AmountNegatedTest.phpindex 3da2874260..d3fa98d66b 100644--- a/tests/Unit/Import/Converter/AmountNegatedTest.php+++ b/tests/Unit/Import/Converter/AmountNegatedTest.php@@ -40,136 +40,136 @@ class AmountNegatedTest extends TestCase{$values = [- '0' => '0',- '0.0' => '0.0',- '0.1' => '-0.1',- '.2' => '-0.2',- '0.01' => '-0.01',- '1' => '-1',- '1.0' => '-1.0',- '1.1' => '-1.1',- '1.12' => '-1.12',- '1.10' => '-1.10',- '12' => '-12',- '12.3' => '-12.3',- '12.34' => '-12.34',- '123' => '-123',- '123.4' => '-123.4',- '123.45' => '-123.45',- '1234' => '-1234',- '1234.5' => '-1234.5',- '1234.56' => '-1234.56',- '1 234' => '-1234',- '1 234.5' => '-1234.5',- '1 234.56' => '-1234.56',- '1,234' => '-1234',- '1,234.5' => '-1234.5',- '1,234.56' => '-1234.56',- '123,456,789' => '-123456789',- '0,0' => '0.0',- '0,1' => '-0.1',- ',2' => '-0.2',- '0,01' => '-0.01',- '1,0' => '-1.0',- '1,1' => '-1.1',- '1,12' => '-1.12',- '1,10' => '-1.10',- '12,3' => '-12.3',- '12,34' => '-12.34',- '123,4' => '-123.4',- '123,45' => '-123.45',- '1234,5' => '-1234.5',- '1234,56' => '-1234.56',- '1 234,5' => '-1234.5',- '1 234,56' => '-1234.56',- '1.234' => '-1.234', // will no longer match as 1234, but as 1.234- '1.234,5' => '-1234.5',- '1.234,56' => '-1234.56',+ '0' => '0.000000000000',+ '0.0' => '0.000000000000',+ '0.1' => '-0.100000000000',+ '.2' => '-0.200000000000',+ '0.01' => '-0.010000000000',+ '1' => '-1.000000000000',+ '1.0' => '-1.000000000000',+ '1.1' => '-1.100000000000',+ '1.12' => '-1.120000000000',+ '1.10' => '-1.100000000000',+ '12' => '-12.000000000000',+ '12.3' => '-12.300000000000',+ '12.34' => '-12.340000000000',+ '123' => '-123.000000000000',+ '123.4' => '-123.400000000000',+ '123.45' => '-123.450000000000',+ '1234' => '-1234.000000000000',+ '1234.5' => '-1234.500000000000',+ '1234.56' => '-1234.560000000000',+ '1 234' => '-1234.000000000000',+ '1 234.5' => '-1234.500000000000',+ '1 234.56' => '-1234.560000000000',+ '1,234' => '-1234.000000000000',+ '1,234.5' => '-1234.500000000000',+ '1,234.56' => '-1234.560000000000',+ '123,456,789' => '-123456789.000000000000',+ '0,0' => '0.000000000000',+ '0,1' => '-0.100000000000',+ ',2' => '-0.200000000000',+ '0,01' => '-0.010000000000',+ '1,0' => '-1.000000000000',+ '1,1' => '-1.100000000000',+ '1,12' => '-1.120000000000',+ '1,10' => '-1.100000000000',+ '12,3' => '-12.300000000000',+ '12,34' => '-12.340000000000',+ '123,4' => '-123.400000000000',+ '123,45' => '-123.450000000000',+ '1234,5' => '-1234.500000000000',+ '1234,56' => '-1234.560000000000',+ '1 234,5' => '-1234.500000000000',+ '1 234,56' => '-1234.560000000000',+ '1.234' => '-1.234000000000', // will no longer match as 1234, but as 1.234+ '1.234,5' => '-1234.500000000000',+ '1.234,56' => '-1234.560000000000',// many decimals- '2.00' => '-2.00',- '3.000' => '-3.000',- '4.0000' => '-4.0000',- '5.000' => '-5.000',- '6.0000' => '-6.0000',- '7.200' => '-7.200',- '8.2000' => '-8.2000',- '9.330' => '-9.330',- '10.3300' => '-10.3300',- '11.444' => '-11.444',- '12.4440' => '-12.4440',- '13.5555' => '-13.5555',- '14.45678' => '-14.45678',- '15.456789' => '-15.456789',- '16.4567898' => '-16.4567898',- '17.34567898' => '-17.34567898',- '18.134567898' => '-18.134567898',- '19.1634567898' => '-19.1634567898',- '20.16334567898' => '-20.16334567898',- '21.16364567898' => '-21.16364567898',+ '2.00' => '-2.000000000000',+ '3.000' => '-3.000000000000',+ '4.0000' => '-4.000000000000',+ '5.000' => '-5.000000000000',+ '6.0000' => '-6.000000000000',+ '7.200' => '-7.200000000000',+ '8.2000' => '-8.200000000000',+ '9.330' => '-9.330000000000',+ '10.3300' => '-10.330000000000',+ '11.444' => '-11.444000000000',+ '12.4440' => '-12.444000000000',+ '13.5555' => '-13.555500000000',+ '14.45678' => '-14.456780000000',+ '15.456789' => '-15.456789000000',+ '16.4567898' => '-16.456789800000',+ '17.34567898' => '-17.345678980000',+ '18.134567898' => '-18.134567898000',+ '19.1634567898' => '-19.163456789800',+ '20.16334567898' => '-20.163345678980',+ '21.16364567898' => '-21.163645678980','22.163644567898' => '-22.163644567898','22.1636445670069' => '-22.163644567006',// many decimals, mixed, large numbers- '63522.00' => '-63522.00',- '63523.000' => '-63523.000',- '63524.0000' => '-63524.0000',- '63525.000' => '-63525.000',- '63526.0000' => '-63526.0000',- '63527.200' => '-63527.200',- '63528.2000' => '-63528.2000',- '63529.330' => '-63529.330',- '635210.3300' => '-635210.3300',- '635211.444' => '-635211.444',- '635212.4440' => '-635212.4440',- '635213.5555' => '-635213.5555',- '635214.45678' => '-635214.45678',- '635215.456789' => '-635215.456789',- '635216.4567898' => '-635216.4567898',- '635217.34567898' => '-635217.34567898',- '635218.134567898' => '-635218.134567898',- '635219.1634567898' => '-635219.1634567898',- '635220.16334567898' => '-635220.16334567898',- '635221.16364567898' => '-635221.16364567898',+ '63522.00' => '-63522.000000000000',+ '63523.000' => '-63523.000000000000',+ '63524.0000' => '-63524.000000000000',+ '63525.000' => '-63525.000000000000',+ '63526.0000' => '-63526.000000000000',+ '63527.200' => '-63527.200000000000',+ '63528.2000' => '-63528.200000000000',+ '63529.330' => '-63529.330000000000',+ '635210.3300' => '-635210.330000000000',+ '635211.444' => '-635211.444000000000',+ '635212.4440' => '-635212.444000000000',+ '635213.5555' => '-635213.555500000000',+ '635214.45678' => '-635214.456780000000',+ '635215.456789' => '-635215.456789000000',+ '635216.4567898' => '-635216.456789800000',+ '635217.34567898' => '-635217.345678980000',+ '635218.134567898' => '-635218.134567898000',+ '635219.1634567898' => '-635219.163456789800',+ '635220.16334567898' => '-635220.163345678980',+ '635221.16364567898' => '-635221.163645678980','635222.163644567898' => '-635222.163644567898',// many decimals, mixed, also mixed thousands separators- '63 522.00' => '-63522.00',- '63 523.000' => '-63523.000',- '63,524.0000' => '-63524.0000',- '63 525.000' => '-63525.000',- '63,526.0000' => '-63526.0000',- '63 527.200' => '-63527.200',- '63 528.2000' => '-63528.2000',- '63 529.330' => '-63529.330',- '63,5210.3300' => '-635210.3300',- '63,5211.444' => '-635211.444',- '63 5212.4440' => '-635212.4440',- '163 5219.1634567898' => '-1635219.1634567898',- '444 163 5219.1634567898' => '-4441635219.1634567898',- '-0.34918323' => '0.34918323',- '0.208' => '-0.208',- '-0.15' => '0.15',- '-0.03881677' => '0.03881677',- '0.33' => '-0.33',- '-0.1' => '0.1',- '0.01124' => '-0.01124',- '-0.01124' => '0.01124',- '0.115' => '-0.115',- '-0.115' => '0.115',- '1.33' => '-1.33',- '$1.23' => '-1.23',- '€1,44' => '-1.44',- '(33.52)' => '33.52',- '€(63.12)' => '63.12',- '($182.77)' => '182.77',+ '63 522.00' => '-63522.000000000000',+ '63 523.000' => '-63523.000000000000',+ '63,524.0000' => '-63524.000000000000',+ '63 525.000' => '-63525.000000000000',+ '63,526.0000' => '-63526.000000000000',+ '63 527.200' => '-63527.200000000000',+ '63 528.2000' => '-63528.200000000000',+ '63 529.330' => '-63529.330000000000',+ '63,5210.3300' => '-635210.330000000000',+ '63,5211.444' => '-635211.444000000000',+ '63 5212.4440' => '-635212.444000000000',+ '163 5219.1634567898' => '-1635219.163456789800',+ '444 163 5219.1634567898' => '-4441635219.163456789800',+ '-0.34918323' => '0.349183230000',+ '0.208' => '-0.208000000000',+ '-0.15' => '0.150000000000',+ '-0.03881677' => '0.038816770000',+ '0.33' => '-0.330000000000',+ '-0.1' => '0.100000000000',+ '0.01124' => '-0.011240000000',+ '-0.01124' => '0.011240000000',+ '0.115' => '-0.115000000000',+ '-0.115' => '0.115000000000',+ '1.33' => '-1.330000000000',+ '$1.23' => '-1.230000000000',+ '€1,44' => '-1.440000000000',+ '(33.52)' => '33.520000000000',+ '€(63.12)' => '63.120000000000',+ '($182.77)' => '182.770000000000',// double minus because why the hell not- '--0.03881677' => '-0.03881677',- '--0.33' => '-0.33',- '--$1.23' => '-1.23',- '--63 5212.4440' => '-635212.4440',- '--,2' => '-0.2',+ '--0.03881677' => '-0.038816770000',+ '--0.33' => '-0.330000000000',+ '--$1.23' => '-1.230000000000',+ '--63 5212.4440' => '-635212.444000000000',+ '--,2' => '-0.200000000000',];foreach ($values as $value => $expected) {@@ -186,6 +186,6 @@ class AmountNegatedTest extends TestCase{$converter = new AmountNegated;$result = $converter->convert(null);- $this->assertEquals('0', $result);+ $this->assertEquals('0.000000000000', $result);}}diff --git a/tests/Unit/Import/Specifics/PresidentsChoiceTest.php b/tests/Unit/Import/Specifics/PresidentsChoiceTest.phpindex 2387cdbc8b..05e600a70b 100644--- a/tests/Unit/Import/Specifics/PresidentsChoiceTest.php+++ b/tests/Unit/Import/Specifics/PresidentsChoiceTest.php@@ -55,7 +55,7 @@ class PresidentsChoiceTest extends TestCase$parser = new PresidentsChoice;$result = $parser->run($row);- $this->assertEquals('-12.34', $result[3]);+ $this->assertEquals('-12.340000000000', $result[3]);$this->assertEquals('Descr', $result[2]);}diff --git a/tests/Unit/Import/Storage/ImportArrayStorageTest.php b/tests/Unit/Import/Storage/ImportArrayStorageTest.phpindex b1633818db..5edbd06185 100644--- a/tests/Unit/Import/Storage/ImportArrayStorageTest.php+++ b/tests/Unit/Import/Storage/ImportArrayStorageTest.php@@ -24,6 +24,7 @@ declare(strict_types=1);namespace Tests\Unit\Import\Storage;use Amount;+use Event;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Import\Storage\ImportArrayStorage;@@ -39,6 +40,7 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\TransactionRules\Processor;+use FireflyIII\Transformers\TransactionGroupTransformer;use Illuminate\Support\Collection;use Log;use Mockery;@@ -72,13 +74,15 @@ class ImportArrayStorageTest extends TestCase*/public function testBasic(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// mock stuff- $userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $this->mock(TransactionGroupTransformer::class);+ $this->mock(UserRepositoryInterface::class);$this->mock(TagRepositoryInterface::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);@@ -90,7 +94,6 @@ class ImportArrayStorageTest extends TestCasePreferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();-// make fake job$job = new ImportJob;$job->user()->associate($this->user());@@ -112,7 +115,6 @@ class ImportArrayStorageTest extends TestCase// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn([]);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -130,23 +132,23 @@ class ImportArrayStorageTest extends TestCase}/**- * Submit a transfer. Mark it as not duplicate.+ * Same as testBasic but submits the minimum amount of data required to store a transaction.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransfer(): void+ public function testSimple(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportTransfer(),+ $this->singleImportWithdrawal(),];// data that is returned:$withdrawalGroup = $this->getRandomWithdrawalGroup();$tag = $this->getRandomTag();- $transfer = $this->getRandomTransferAsArray();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);@@ -154,10 +156,11 @@ class ImportArrayStorageTest extends TestCase$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);- $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);-+ $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;@@ -187,7 +190,6 @@ class ImportArrayStorageTest extends TestCase// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -201,15 +203,7 @@ class ImportArrayStorageTest extends TestCase$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // also mocks collector:- $collector->shouldReceive('setUser')->atLeast()->once();- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);-+ // fake the event.$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -221,37 +215,38 @@ class ImportArrayStorageTest extends TestCase}/**- * Submit a transfer, and its not duplicate.+ * Same as testBasic but submits the minimum amount of data required to store a transaction.+ *+ * Also applies the rules, but there are none.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransferNotDuplicate(): void+ public function testSimpleApplyNoRules(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportTransfer(),+ $this->singleImportWithdrawal(),];// data that is returned:- $transferGroup = $this->getRandomTransferGroup();- $tag = $this->getRandomTag();- $transfer = $this->getRandomTransferAsArray();-- // make sure the right fields of the transfergroup and the transactions- // are equal, so the duplicate detector is triggered.+ $withdrawalGroup = $this->getRandomWithdrawalGroup();+ $tag = $this->getRandomTag();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $ruleRepos = $this->mock(RuleRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);- $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+$this->mock(Processor::class);- $this->mock(RuleRepositoryInterface::class);+ $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;@@ -267,7 +262,9 @@ class ImportArrayStorageTest extends TestCase$job->stage = 'new';$job->provider = 'fake';$job->file_type = '';- $job->configuration = [];+ $job->configuration = [+ 'apply-rules' => true,+ ];$job->transactions = [];$job->save();@@ -277,33 +274,29 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();$tagRepos->shouldReceive('setUser')->atLeast()->once();+ $ruleRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'stored_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linking_to_tag']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);+ $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'applying_rules']);+ $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'rules_applied']);+// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // also mocks collector:- $collector->shouldReceive('setUser')->atLeast()->once();- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);-+ // calls for application of rules, but returns NO rules.+ $ruleRepos->shouldReceive('getForImport')->once()->andReturn(new Collection);$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -315,51 +308,38 @@ class ImportArrayStorageTest extends TestCase}/**- * Submit a transfer, and the amounts match, but the rest doesn't.+ * Same as testBasic but submits the minimum amount of data required to store a transaction.+ *+ * Also applies the rules, but there are none.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransferNotDuplicateAmount(): void+ public function testSimpleApplyOneRules(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportTransfer(),+ $this->singleImportWithdrawal(),];// data that is returned:- $transferGroup = $this->getRandomTransferGroup();- $tag = $this->getRandomTag();- $transfer = $this->getRandomTransferAsArray();-- // are equal, so the duplicate detector is triggered.- $transactions[0]['transactions'][0]['amount'] = '56.78';- $transfer['amount'] = '56.78';- //$transferGroup['transactions']['amount'] = '12';- /** @var TransactionJournal $journal */- $journal = $transferGroup->transactionJournals->first();- $journal->transactions->each(static function (Transaction $t) {- if ($t->amount < 0) {- $t->amount = '-56.78';- }- if ($t->amount > 0) {- $t->amount = '56.78';- }- $t->save();- });- $transferGroup->refresh();+ $withdrawalGroup = $this->getRandomWithdrawalGroup();+ $tag = $this->getRandomTag();+ $rule = $this->getRandomRule();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $ruleRepos = $this->mock(RuleRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);- $collector = $this->mock(GroupCollectorInterface::class);- $this->mock(Processor::class);- $this->mock(RuleRepositoryInterface::class);+ $processor = $this->mock(Processor::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+ $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;@@ -375,7 +355,9 @@ class ImportArrayStorageTest extends TestCase$job->stage = 'new';$job->provider = 'fake';$job->file_type = '';- $job->configuration = [];+ $job->configuration = [+ 'apply-rules' => true,+ ];$job->transactions = [];$job->save();@@ -385,33 +367,31 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();$tagRepos->shouldReceive('setUser')->atLeast()->once();+ $ruleRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'stored_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linking_to_tag']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);+ $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'applying_rules']);+ $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'rules_applied']);+// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // also mocks collector:- $collector->shouldReceive('setUser')->atLeast()->once();- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);-+ // calls for application of rules, but returns 1 rules.+ $ruleRepos->shouldReceive('getForImport')->once()->andReturn(new Collection([$rule]));+ $processor->shouldReceive('make')->atLeast()->once();+ $processor->shouldReceive('handleTransactionJournal')->atLeast()->once();$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -423,60 +403,42 @@ class ImportArrayStorageTest extends TestCase}/**- * Submit a transfer, and the amounts match, and the description matches, but the rest doesn't+ * Same as testBasic but submits the minimum amount of data required to store a transaction.+ *+ * The one journal in the list is a duplicate.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransferNotDuplicateDescr(): void+ public function testSimpleDuplicate(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportTransfer(),+ $this->singleImportWithdrawal(),];- // data that is returned:- $transferGroup = $this->getRandomTransferGroup();- $tag = $this->getRandomTag();- $transfer = $this->getRandomTransferAsArray();-- // are equal, so the duplicate detector is triggered.- $transactions[0]['transactions'][0]['amount'] = '56.78';- $transfer['amount'] = '56.78';- $transactions[0]['transactions'][0]['description'] = $transfer['description'];--- //$transferGroup['transactions']['amount'] = '12';- /** @var TransactionJournal $journal */- $journal = $transferGroup->transactionJournals->first();- $journal->transactions->each(static function (Transaction $t) {- if ($t->amount < 0) {- $t->amount = '-56.78';- }- if ($t->amount > 0) {- $t->amount = '56.78';- }- $t->save();- });- $transferGroup->refresh();-// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $tagRepos = $this->mock(TagRepositoryInterface::class);- $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);++ $this->mock(TagRepositoryInterface::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);-+ $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;$language->data = 'en_US';Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();+ $meta = new TransactionJournalMeta;+ $meta->transaction_journal_id = 1;+// make fake job$job = new ImportJob;@@ -495,12 +457,10 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setUser')->atLeast()->once();$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();- $tagRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -509,19 +469,11 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);// calls to validate and import transactions:- $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);- $tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);- $repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);+ $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturn($meta);- // also mocks collector:- $collector->shouldReceive('setUser')->atLeast()->once();- $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();- $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);+ // errors because of duplicate:+ $repository->shouldReceive('addErrorMessage')->atLeast()->once()+ ->withArgs([Mockery::any(), 'Row #0 ("") could not be imported. It already exists.']);$storage = new ImportArrayStorage;@@ -534,45 +486,24 @@ class ImportArrayStorageTest extends TestCase}/**- * Submit a transfer, and the amounts match, and the description matches,- * and the date matches, but the rest doesn't+ * Submit a transfer. Mark it as not duplicate.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransferNotDuplicateDate(): void+ public function testTransfer(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [$this->singleImportTransfer(),];// data that is returned:- $transferGroup = $this->getRandomTransferGroup();- $tag = $this->getRandomTag();- $transfer = $this->getRandomTransferAsArray();-- // are equal, so the duplicate detector is triggered.- $transactions[0]['transactions'][0]['amount'] = '56.78';- $transfer['amount'] = '56.78';- $transactions[0]['transactions'][0]['description'] = $transfer['description'];- $transactions[0]['transactions'][0]['date'] = $transfer['date']->format('Y-m-d H:i:s');--- //$transferGroup['transactions']['amount'] = '12';- /** @var TransactionJournal $journal */- $journal = $transferGroup->transactionJournals->first();- $journal->transactions->each(static function (Transaction $t) {- if ($t->amount < 0) {- $t->amount = '-56.78';- }- if ($t->amount > 0) {- $t->amount = '56.78';- }- $t->save();- });- $transferGroup->refresh();+ $withdrawalGroup = $this->getRandomWithdrawalGroup();+ $tag = $this->getRandomTag();+ $transfer = $this->getRandomTransferAsArray();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);@@ -581,6 +512,7 @@ class ImportArrayStorageTest extends TestCase$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);$collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);@@ -613,7 +545,6 @@ class ImportArrayStorageTest extends TestCase// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -623,7 +554,7 @@ class ImportArrayStorageTest extends TestCase// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);@@ -646,17 +577,16 @@ class ImportArrayStorageTest extends TestCase}}-/**- * Submit a transfer, and the amounts match, and the description matches,- * and the date matches, and the accounts match, making it a duplicate.+ * Submit a transfer, and its not duplicate.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testTransferNotDuplicateAccounts(): void+ public function testTransferNotDuplicate(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [$this->singleImportTransfer(),@@ -667,38 +597,17 @@ class ImportArrayStorageTest extends TestCase$tag = $this->getRandomTag();$transfer = $this->getRandomTransferAsArray();+ // make sure the right fields of the transfergroup and the transactions// are equal, so the duplicate detector is triggered.- $transfer['amount'] = '56.78';- $transfer['source_account_id'] = 0;- $transfer['source_account_name'] = 'x';- $transfer['destination_account_id'] = 0;- $transfer['destination_account_name'] = 'x';- $transactions[0]['transactions'][0]['amount'] = '56.78';- $transactions[0]['transactions'][0]['description'] = $transfer['description'];- $transactions[0]['transactions'][0]['date'] = $transfer['date']->format('Y-m-d H:i:s');--- //$transferGroup['transactions']['amount'] = '12';- /** @var TransactionJournal $journal */- $journal = $transferGroup->transactionJournals->first();- $journal->transactions->each(static function (Transaction $t) {- if ($t->amount < 0) {- $t->amount = '-56.78';- }- if ($t->amount > 0) {- $t->amount = '56.78';- }- $t->save();- });- $transferGroup->refresh();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $tagRepos = $this->mock(TagRepositoryInterface::class);$collector = $this->mock(GroupCollectorInterface::class);- $this->mock(TagRepositoryInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);@@ -726,11 +635,11 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setUser')->atLeast()->once();$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();+ $tagRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -740,18 +649,19 @@ class ImportArrayStorageTest extends TestCase// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);+ $tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);+ $repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);// also mocks collector:$collector->shouldReceive('setUser')->atLeast()->once();$collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);- // since a duplicate was found, must register error:- $repository->shouldReceive('addErrorMessage')->atLeast()->once()->withArgs([Mockery::any(), sprintf('Row #0 ("%s") could not be imported. It already exists.', $transfer['description'])]);-$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -762,34 +672,65 @@ class ImportArrayStorageTest extends TestCase}}-/**- * Same as testBasic but submits the minimum amount of data required to store a transaction.+ * Submit a transfer, and the amounts match, and the description matches,+ * and the date matches, and the accounts match, making it a duplicate.+ ** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testSimple(): void+ public function testTransferNotDuplicateAccounts(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportWithdrawal(),+ $this->singleImportTransfer(),];// data that is returned:- $withdrawalGroup = $this->getRandomWithdrawalGroup();- $tag = $this->getRandomTag();+ $transferGroup = $this->getRandomTransferGroup();+ $tag = $this->getRandomTag();+ $transfer = $this->getRandomTransferAsArray();++ // are equal, so the duplicate detector is triggered.+ $transfer['amount'] = '56.78';+ $transfer['source_account_id'] = 0;+ $transfer['source_account_name'] = 'x';+ $transfer['destination_account_id'] = 0;+ $transfer['destination_account_name'] = 'x';+ $transactions[0]['transactions'][0]['amount'] = '56.78';+ $transactions[0]['transactions'][0]['description'] = $transfer['description'];+ $transactions[0]['transactions'][0]['date'] = $transfer['date']->format('Y-m-d H:i:s');+++ //$transferGroup['transactions']['amount'] = '12';+ /** @var TransactionJournal $journal */+ $journal = $transferGroup->transactionJournals->first();+ $journal->transactions->each(+ static function (Transaction $t) {+ if ($t->amount < 0) {+ $t->amount = '-56.78';+ }+ if ($t->amount > 0) {+ $t->amount = '56.78';+ }+ $t->save();+ }+ );+ $transferGroup->refresh();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $tagRepos = $this->mock(TagRepositoryInterface::class);-+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+ $this->mock(TagRepositoryInterface::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);- $this->mock(GroupCollectorInterface::class);+Amount::shouldReceive('something');$language = new Preference;@@ -814,12 +755,10 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setUser')->atLeast()->once();$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();- $tagRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -829,9 +768,19 @@ class ImportArrayStorageTest extends TestCase// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);- $tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);- $repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);++ // also mocks collector:+ $collector->shouldReceive('setUser')->atLeast()->once();+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);++ // since a duplicate was found, must register error:+ $repository->shouldReceive('addErrorMessage')->atLeast()->once()->withArgs(+ [Mockery::any(), sprintf('Row #0 ("%s") could not be imported. It already exists.', $transfer['description'])]+ );$storage = new ImportArrayStorage;@@ -844,40 +793,61 @@ class ImportArrayStorageTest extends TestCase}/**- * Same as testBasic but submits the minimum amount of data required to store a transaction.- *- * The one journal in the list is a duplicate.+ * Submit a transfer, and the amounts match, but the rest doesn't.** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testSimpleDuplicate(): void+ public function testTransferNotDuplicateAmount(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportWithdrawal(),+ $this->singleImportTransfer(),];+ // data that is returned:+ $transferGroup = $this->getRandomTransferGroup();+ $tag = $this->getRandomTag();+ $transfer = $this->getRandomTransferAsArray();++ // are equal, so the duplicate detector is triggered.+ $transactions[0]['transactions'][0]['amount'] = '56.78';+ $transfer['amount'] = '56.78';+ //$transferGroup['transactions']['amount'] = '12';+ /** @var TransactionJournal $journal */+ $journal = $transferGroup->transactionJournals->first();+ $journal->transactions->each(+ static function (Transaction $t) {+ if ($t->amount < 0) {+ $t->amount = '-56.78';+ }+ if ($t->amount > 0) {+ $t->amount = '56.78';+ }+ $t->save();+ }+ );+ $transferGroup->refresh();+// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);-- $this->mock(TagRepositoryInterface::class);+ $tagRepos = $this->mock(TagRepositoryInterface::class);+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);$this->mock(Processor::class);$this->mock(RuleRepositoryInterface::class);- $this->mock(GroupCollectorInterface::class);+Amount::shouldReceive('something');$language = new Preference;$language->data = 'en_US';Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();- $meta = new TransactionJournalMeta;- $meta->transaction_journal_id = 1;-// make fake job$job = new ImportJob;@@ -896,11 +866,11 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setUser')->atLeast()->once();$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();+ $tagRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);@@ -909,11 +879,19 @@ class ImportArrayStorageTest extends TestCase$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);// calls to validate and import transactions:- $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturn($meta);+ $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);+ $tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);+ $repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // errors because of duplicate:- $repository->shouldReceive('addErrorMessage')->atLeast()->once()- ->withArgs([Mockery::any(), 'Row #0 ("") could not be imported. It already exists.']);+ // also mocks collector:+ $collector->shouldReceive('setUser')->atLeast()->once();+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);$storage = new ImportArrayStorage;@@ -926,36 +904,60 @@ class ImportArrayStorageTest extends TestCase}/**- * Same as testBasic but submits the minimum amount of data required to store a transaction.- *- * Also applies the rules, but there are none.+ * Submit a transfer, and the amounts match, and the description matches,+ * and the date matches, but the rest doesn't** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testSimpleApplyNoRules(): void+ public function testTransferNotDuplicateDate(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportWithdrawal(),+ $this->singleImportTransfer(),];// data that is returned:- $withdrawalGroup = $this->getRandomWithdrawalGroup();- $tag = $this->getRandomTag();+ $transferGroup = $this->getRandomTransferGroup();+ $tag = $this->getRandomTag();+ $transfer = $this->getRandomTransferAsArray();++ // are equal, so the duplicate detector is triggered.+ $transactions[0]['transactions'][0]['amount'] = '56.78';+ $transfer['amount'] = '56.78';+ $transactions[0]['transactions'][0]['description'] = $transfer['description'];+ $transactions[0]['transactions'][0]['date'] = $transfer['date']->format('Y-m-d H:i:s');+++ //$transferGroup['transactions']['amount'] = '12';+ /** @var TransactionJournal $journal */+ $journal = $transferGroup->transactionJournals->first();+ $journal->transactions->each(+ static function (Transaction $t) {+ if ($t->amount < 0) {+ $t->amount = '-56.78';+ }+ if ($t->amount > 0) {+ $t->amount = '56.78';+ }+ $t->save();+ }+ );+ $transferGroup->refresh();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $ruleRepos = $this->mock(RuleRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);-+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);$this->mock(Processor::class);+ $this->mock(RuleRepositoryInterface::class);- $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;@@ -971,9 +973,7 @@ class ImportArrayStorageTest extends TestCase$job->stage = 'new';$job->provider = 'fake';$job->file_type = '';- $job->configuration = [- 'apply-rules' => true,- ];+ $job->configuration = [];$job->transactions = [];$job->save();@@ -983,30 +983,32 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();$tagRepos->shouldReceive('setUser')->atLeast()->once();- $ruleRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'stored_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linking_to_tag']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);- $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'applying_rules']);- $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'rules_applied']);-// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // calls for application of rules, but returns NO rules.- $ruleRepos->shouldReceive('getForImport')->once()->andReturn(new Collection);+ // also mocks collector:+ $collector->shouldReceive('setUser')->atLeast()->once();+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);+$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -1017,38 +1019,59 @@ class ImportArrayStorageTest extends TestCase}}-/**- * Same as testBasic but submits the minimum amount of data required to store a transaction.- *- * Also applies the rules, but there are none.+ * Submit a transfer, and the amounts match, and the description matches, but the rest doesn't** @covers \FireflyIII\Import\Storage\ImportArrayStorage**/- public function testSimpleApplyOneRules(): void+ public function testTransferNotDuplicateDescr(): void{- Log::debug(sprintf('Now in test %s', __METHOD__));+ Event::fake();+ Log::info(sprintf('Now in test %s', __METHOD__));// data to submit:$transactions = [- $this->singleImportWithdrawal(),+ $this->singleImportTransfer(),];// data that is returned:- $withdrawalGroup = $this->getRandomWithdrawalGroup();- $tag = $this->getRandomTag();- $rule = $this->getRandomRule();+ $transferGroup = $this->getRandomTransferGroup();+ $tag = $this->getRandomTag();+ $transfer = $this->getRandomTransferAsArray();++ // are equal, so the duplicate detector is triggered.+ $transactions[0]['transactions'][0]['amount'] = '56.78';+ $transfer['amount'] = '56.78';+ $transactions[0]['transactions'][0]['description'] = $transfer['description'];+++ //$transferGroup['transactions']['amount'] = '12';+ /** @var TransactionJournal $journal */+ $journal = $transferGroup->transactionJournals->first();+ $journal->transactions->each(+ static function (Transaction $t) {+ if ($t->amount < 0) {+ $t->amount = '-56.78';+ }+ if ($t->amount > 0) {+ $t->amount = '56.78';+ }+ $t->save();+ }+ );+ $transferGroup->refresh();// mock stuff$userRepos = $this->mock(UserRepositoryInterface::class);$repository = $this->mock(ImportJobRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $ruleRepos = $this->mock(RuleRepositoryInterface::class);$tagRepos = $this->mock(TagRepositoryInterface::class);- $processor = $this->mock(Processor::class);+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);+ $this->mock(Processor::class);+ $this->mock(RuleRepositoryInterface::class);- $this->mock(GroupCollectorInterface::class);Amount::shouldReceive('something');$language = new Preference;@@ -1064,9 +1087,7 @@ class ImportArrayStorageTest extends TestCase$job->stage = 'new';$job->provider = 'fake';$job->file_type = '';- $job->configuration = [- 'apply-rules' => true,- ];+ $job->configuration = [];$job->transactions = [];$job->save();@@ -1076,32 +1097,32 @@ class ImportArrayStorageTest extends TestCase$journalRepos->shouldReceive('setUser')->atLeast()->once();$groupRepos->shouldReceive('setUser')->atLeast()->once();$tagRepos->shouldReceive('setUser')->atLeast()->once();- $ruleRepos->shouldReceive('setUser')->atLeast()->once();// mock other calls.$repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($this->user());// status changes of the job.$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'storing_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'stored_data']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linking_to_tag']);$repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'linked_to_tag']);- $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'applying_rules']);- $repository->shouldReceive('setStatus')->atLeast()->once()->withArgs([Mockery::any(), 'rules_applied']);-// calls to validate and import transactions:$journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($withdrawalGroup);+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($transferGroup);$tagRepos->shouldReceive('store')->atLeast()->once()->andReturn($tag);$repository->shouldReceive('setTag')->atLeast()->once()->andReturn($job);- // calls for application of rules, but returns 1 rules.- $ruleRepos->shouldReceive('getForImport')->once()->andReturn(new Collection([$rule]));- $processor->shouldReceive('make')->atLeast()->once();- $processor->shouldReceive('handleTransactionJournal')->atLeast()->once();+ // also mocks collector:+ $collector->shouldReceive('setUser')->atLeast()->once();+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setGroup')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$transfer]);+$storage = new ImportArrayStorage;$storage->setImportJob($job);@@ -1115,11 +1136,11 @@ class ImportArrayStorageTest extends TestCase/*** @return array*/- private function singleImportWithdrawal(): array+ private function singleImportTransfer(): array{return[- 'type' => 'withdrawal',+ 'type' => 'transfer','tags' => '','user' => $this->user()->id,@@ -1128,7 +1149,7 @@ class ImportArrayStorageTest extends TestCase'notes' => null,// journal data:- 'description' => 'Some TEST withdrawal #1',+ 'description' => 'Some TEST transfer #1','piggy_bank_id' => null,'piggy_bank_name' => null,'bill_id' => null,@@ -1138,7 +1159,7 @@ class ImportArrayStorageTest extends TestCase'transactions' => [['date' => '2019-01-01',- 'type' => 'withdrawal',+ 'type' => 'transfer','currency_id' => null,'currency_code' => 'EUR','description' => null,@@ -1164,11 +1185,11 @@ class ImportArrayStorageTest extends TestCase/*** @return array*/- private function singleImportTransfer(): array+ private function singleImportWithdrawal(): array{return[- 'type' => 'transfer',+ 'type' => 'withdrawal','tags' => '','user' => $this->user()->id,@@ -1177,7 +1198,7 @@ class ImportArrayStorageTest extends TestCase'notes' => null,// journal data:- 'description' => 'Some TEST transfer #1',+ 'description' => 'Some TEST withdrawal #1','piggy_bank_id' => null,'piggy_bank_name' => null,'bill_id' => null,@@ -1187,7 +1208,7 @@ class ImportArrayStorageTest extends TestCase'transactions' => [['date' => '2019-01-01',- 'type' => 'transfer',+ 'type' => 'withdrawal','currency_id' => null,'currency_code' => 'EUR','description' => null,diff --git a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php b/tests/Unit/Jobs/CreateRecurringTransactionsTest.phpindex e668be0707..11b1a3782f 100644--- a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php+++ b/tests/Unit/Jobs/CreateRecurringTransactionsTest.php@@ -31,6 +31,7 @@ use FireflyIII\Jobs\CreateRecurringTransactions;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;+use FireflyIII\Repositories\User\UserRepositoryInterface;use Illuminate\Support\Collection;use Illuminate\Support\Facades\Event;use Log;@@ -54,6 +55,49 @@ class CreateRecurringTransactionsTest extends TestCaseLog::info(sprintf('Now in %s.', get_class($this)));}+ /**+ * Submit one, offer occurence for today.+ *+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions+ */+ public function testBadJournalCount(): void+ {+ Event::fake();+ $date = new Carbon();++ // overrule some fields in the recurrence to make it seem it hasnt fired yet.+ $carbon = new Carbon;+ $carbon->subDays(4);+ $recurrence = $this->getRandomRecurrence();+ $recurrence->latest_date = null;+ $recurrence->first_date = $carbon;+ $recurrence->save();++ // mock classes+ $recurringRepos = $this->mock(RecurringRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $piggyFactory = $this->mock(PiggyBankFactory::class);+ $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);++ // mocks:+ $groupRepos->shouldReceive('setUser')->atLeast()->once();+ $journalRepos->shouldReceive('setUser')->atLeast()->once();+ $recurringRepos->shouldReceive('setUser')->atLeast()->once();++ $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);+ $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);+ Preferences::shouldReceive('mark')->atLeast()->once();++ $job = new CreateRecurringTransactions($date);+ $job->handle();++ $this->assertEquals(0, $job->created);+ $this->assertEquals(1, $job->executed);+ $this->assertEquals(1, $job->submitted);+ }+/*** Submit nothing.*@@ -81,6 +125,70 @@ class CreateRecurringTransactionsTest extends TestCase}+ /**+ * Submit one, offer occurence for today.+ *+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions+ */+ public function testForced(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Event::fake();+ $date = new Carbon();+ $this->expectsEvents([StoredTransactionGroup::class]);++ // overrule some fields in the recurrence.+ $carbon = new Carbon;+ $carbon->subDays(4);+ $recurrence = $this->getRandomRecurrence();+ $recurrence->latest_date = null;+ $recurrence->first_date = $carbon;+ $recurrence->save();+++ $group = $this->getRandomWithdrawalGroup();++ // overrule some fields in the recurrence to make it seem it hasnt fired yet.+ $recurrence->latest_date = null;+ $recurrence->save();++ // mock classes+ $recurringRepos = $this->mock(RecurringRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $piggyFactory = $this->mock(PiggyBankFactory::class);+ $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);++ // mocks:+ $groupRepos->shouldReceive('setUser')->atLeast()->once();+ $journalRepos->shouldReceive('setUser')->atLeast()->once();+ $recurringRepos->shouldReceive('setUser')->atLeast()->once();++ $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);+ $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);+ $recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();+ Preferences::shouldReceive('mark')->atLeast()->once();++ // return data:+ $recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();+ $recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();+ $recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);++ // store journal+ $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);++ //Event::assertDispatched(StoredTransactionGroup::class);++ $job = new CreateRecurringTransactions($date);+ $job->setForce(true);+ $job->handle();++ $this->assertEquals(1, $job->created);+ $this->assertEquals(1, $job->executed);+ $this->assertEquals(1, $job->submitted);+ }+/*** Submit one, but offer no occurrences.*@@ -90,6 +198,7 @@ class CreateRecurringTransactionsTest extends TestCase*/public function testSingle(): void{+ Event::fake();Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes$date = new Carbon;@@ -104,6 +213,7 @@ class CreateRecurringTransactionsTest extends TestCase$recurringRepos = $this->mock(RecurringRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $userRepos = $this->mock(UserRepositoryInterface::class);// mocks:$groupRepos->shouldReceive('setUser')->atLeast()->once();@@ -125,8 +235,6 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(1, $job->submitted);}--/*** Submit one, but has already fired today*@@ -134,8 +242,9 @@ class CreateRecurringTransactionsTest extends TestCase*/public function testSingleFiredToday(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes- $recurrence = $this->getRandomRecurrence();+ $recurrence = $this->getRandomRecurrence();$recurrence->latest_date = new Carbon;$recurrence->save();$recurringRepos = $this->mock(RecurringRepositoryInterface::class);@@ -156,11 +265,10 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(0, $job->created);$this->assertEquals(0, $job->executed);$this->assertEquals(1, $job->submitted);- $recurrence->latest_date =null;+ $recurrence->latest_date = null;$recurrence->save();}-/*** Submit one, but offer no occurrences.*@@ -168,11 +276,12 @@ class CreateRecurringTransactionsTest extends TestCase*/public function testSingleFuture(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes$future = new Carbon;$future->addDays(4);- $recurrence = $this->getRandomRecurrence();- $recurrence->first_date =$future;+ $recurrence = $this->getRandomRecurrence();+ $recurrence->first_date = $future;$recurrence->save();@@ -195,39 +304,35 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(0, $job->executed);$this->assertEquals(1, $job->submitted);- $recurrence->first_date =$date;+ $recurrence->first_date = $date;$recurrence->save();}-/**- * Submit one, but should no longer run.+ * Submit one, but it's inactive.** @covers \FireflyIII\Jobs\CreateRecurringTransactions*/- public function testSingleOverDue(): void+ public function testSingleInactive(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes- $date = new Carbon();- $yesterday = clone $date;- $yesterday->subDays(3);- $recurrence = $this->getRandomRecurrence();+ $recurrence = $this->getRandomRecurrence();- $recurrence->repeat_until =$yesterday;+ $recurrence->active = false;$recurrence->save();-$recurringRepos = $this->mock(RecurringRepositoryInterface::class);$this->mock(JournalRepositoryInterface::class);$this->mock(TransactionGroupRepositoryInterface::class);// mocks:$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);Preferences::shouldReceive('mark')->atLeast()->once();- $job = new CreateRecurringTransactions($date);+ $date = new Carbon();+ $job = new CreateRecurringTransactions($date);$job->handle();@@ -235,58 +340,66 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(0, $job->executed);$this->assertEquals(1, $job->submitted);- $recurrence->repeat_until =null;+ $recurrence->active = true;$recurrence->save();}-/**- * Submit one, but it has fired enough times already.- ** @covers \FireflyIII\Jobs\CreateRecurringTransactions*/- public function testSingleOccurrences(): void+ public function testSingleNotToday(): void{- // mock classes+ Event::fake();+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $date = new Carbon();+ $tomorrow = new Carbon();+ $tomorrow->addDays(2);++ // overrule some fields in the recurrence to make it seem it hasnt fired yet.+ $carbon = new Carbon;+ $carbon->subDays(4);$recurrence = $this->getRandomRecurrence();- $recurrence->repetitions = 1;+ $recurrence->latest_date = null;+ $recurrence->first_date = $carbon;$recurrence->save();- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);- $this->mock(JournalRepositoryInterface::class);- $this->mock(TransactionGroupRepositoryInterface::class);+ // mock classes+ $recurringRepos = $this->mock(RecurringRepositoryInterface::class);+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);+ $piggyFactory = $this->mock(PiggyBankFactory::class);+ $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);// mocks:+ $groupRepos->shouldReceive('setUser')->atLeast()->once();+ $journalRepos->shouldReceive('setUser')->atLeast()->once();+ $recurringRepos->shouldReceive('setUser')->atLeast()->once();++ $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(1);+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);Preferences::shouldReceive('mark')->atLeast()->once();-- $date = new Carbon();- $job = new CreateRecurringTransactions($date);-+ $job = new CreateRecurringTransactions($date);$job->handle();$this->assertEquals(0, $job->created);- $this->assertEquals(0, $job->executed);+ $this->assertEquals(1, $job->executed);$this->assertEquals(1, $job->submitted);- $recurrence->repetitions = 0;- $recurrence->save();}/**- * Submit one, but it's inactive.+ * Submit one, but it has fired enough times already.** @covers \FireflyIII\Jobs\CreateRecurringTransactions*/- public function testSingleInactive(): void+ public function testSingleOccurrences(): void{-+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes- $recurrence = $this->getRandomRecurrence();-- $recurrence->active = false;+ $recurrence = $this->getRandomRecurrence();+ $recurrence->repetitions = 1;$recurrence->save();$recurringRepos = $this->mock(RecurringRepositoryInterface::class);@@ -295,6 +408,7 @@ class CreateRecurringTransactionsTest extends TestCase// mocks:$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(1);Preferences::shouldReceive('mark')->atLeast()->once();@@ -307,86 +421,62 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(0, $job->executed);$this->assertEquals(1, $job->submitted);- $recurrence->active = true;+ $recurrence->repetitions = 0;$recurrence->save();}-/**- * Submit one, offer occurence for today.+ * Submit one, but should no longer run.** @covers \FireflyIII\Jobs\CreateRecurringTransactions*/- public function testSingleToday(): void+ public function testSingleOverDue(): void{- Event::fake();- $date = new Carbon();- $this->expectsEvents([StoredTransactionGroup::class]);-+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock classes- $carbon = new Carbon;- $carbon->subDays(4);- $recurrence = $this->getRandomRecurrence();- $recurrence->latest_date = null;- $recurrence->first_date = $carbon;- $recurrence->save();-- $group = $this->getRandomWithdrawalGroup();+ $date = new Carbon();+ $yesterday = clone $date;+ $yesterday->subDays(3);+ $recurrence = $this->getRandomRecurrence();- // overrule some fields in the recurrence to make it seem it hasnt fired yet.- $recurrence->latest_date = null;+ $recurrence->repeat_until = $yesterday;$recurrence->save();- // mock classes- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $piggyFactory = $this->mock(PiggyBankFactory::class);- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);- // mocks:- $groupRepos->shouldReceive('setUser')->atLeast()->once();- $journalRepos->shouldReceive('setUser')->atLeast()->once();- $recurringRepos->shouldReceive('setUser')->atLeast()->once();+ $recurringRepos = $this->mock(RecurringRepositoryInterface::class);+ $this->mock(JournalRepositoryInterface::class);+ $this->mock(TransactionGroupRepositoryInterface::class);- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);+ // mocks:$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);- $recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();Preferences::shouldReceive('mark')->atLeast()->once();- // return data:- $recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();- $recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();- $recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);-- // store journal- $groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);-- //Event::assertDispatched(StoredTransactionGroup::class);$job = new CreateRecurringTransactions($date);+$job->handle();- $this->assertEquals(1, $job->created);- $this->assertEquals(1, $job->executed);+ $this->assertEquals(0, $job->created);+ $this->assertEquals(0, $job->executed);$this->assertEquals(1, $job->submitted);- }+ $recurrence->repeat_until = null;+ $recurrence->save();+ }/*** Submit one, offer occurence for today.** @covers \FireflyIII\Jobs\CreateRecurringTransactions*/- public function testForced(): void+ public function testSingleToday(): void{- Log::info(sprintf('Now in test %s.', __METHOD__));Event::fake();$date = new Carbon();$this->expectsEvents([StoredTransactionGroup::class]);- // overrule some fields in the recurrence.+ // mock classes$carbon = new Carbon;$carbon->subDays(4);$recurrence = $this->getRandomRecurrence();@@ -394,9 +484,7 @@ class CreateRecurringTransactionsTest extends TestCase$recurrence->first_date = $carbon;$recurrence->save();--- $group = $this->getRandomWithdrawalGroup();+ $group = $this->getRandomWithdrawalGroup();// overrule some fields in the recurrence to make it seem it hasnt fired yet.$recurrence->latest_date = null;@@ -416,7 +504,7 @@ class CreateRecurringTransactionsTest extends TestCase$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();Preferences::shouldReceive('mark')->atLeast()->once();@@ -431,7 +519,6 @@ class CreateRecurringTransactionsTest extends TestCase//Event::assertDispatched(StoredTransactionGroup::class);$job = new CreateRecurringTransactions($date);- $job->setForce(true);$job->handle();$this->assertEquals(1, $job->created);@@ -439,93 +526,6 @@ class CreateRecurringTransactionsTest extends TestCase$this->assertEquals(1, $job->submitted);}-- /**- * Submit one, offer occurence for today.- *- * @covers \FireflyIII\Jobs\CreateRecurringTransactions- */- public function testBadJournalCount(): void- {- Event::fake();- $date = new Carbon();-- // overrule some fields in the recurrence to make it seem it hasnt fired yet.- $carbon = new Carbon;- $carbon->subDays(4);- $recurrence = $this->getRandomRecurrence();- $recurrence->latest_date = null;- $recurrence->first_date = $carbon;- $recurrence->save();-- // mock classes- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $piggyFactory = $this->mock(PiggyBankFactory::class);- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);-- // mocks:- $groupRepos->shouldReceive('setUser')->atLeast()->once();- $journalRepos->shouldReceive('setUser')->atLeast()->once();- $recurringRepos->shouldReceive('setUser')->atLeast()->once();-- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);- Preferences::shouldReceive('mark')->atLeast()->once();-- $job = new CreateRecurringTransactions($date);- $job->handle();-- $this->assertEquals(0, $job->created);- $this->assertEquals(1, $job->executed);- $this->assertEquals(1, $job->submitted);- }-- /**- * @covers \FireflyIII\Jobs\CreateRecurringTransactions- */- public function testSingleNotToday(): void- {- $date = new Carbon();- $tomorrow = new Carbon();- $tomorrow->addDays(2);-- // overrule some fields in the recurrence to make it seem it hasnt fired yet.- $carbon = new Carbon;- $carbon->subDays(4);- $recurrence = $this->getRandomRecurrence();- $recurrence->latest_date = null;- $recurrence->first_date = $carbon;- $recurrence->save();-- // mock classes- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);- $piggyFactory = $this->mock(PiggyBankFactory::class);- $piggyEventFactory = $this->mock(PiggyBankEventFactory::class);-- // mocks:- $groupRepos->shouldReceive('setUser')->atLeast()->once();- $journalRepos->shouldReceive('setUser')->atLeast()->once();- $recurringRepos->shouldReceive('setUser')->atLeast()->once();-- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);- Preferences::shouldReceive('mark')->atLeast()->once();-- $job = new CreateRecurringTransactions($date);- $job->handle();-- $this->assertEquals(0, $job->created);- $this->assertEquals(1, $job->executed);- $this->assertEquals(1, $job->submitted);-- }-/*** Submit one, offer occurence for today, with piggy*@@ -538,7 +538,7 @@ class CreateRecurringTransactionsTest extends TestCase$this->expectsEvents([StoredTransactionGroup::class]);- $group = $this->getRandomWithdrawalGroup();+ $group = $this->getRandomWithdrawalGroup();$piggy = $this->getRandomPiggyBank();// overrule some fields in the recurrence to make it seem it hasnt fired yet.diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.phpindex c6faa59688..80779d8a7a 100644--- a/tests/Unit/Middleware/BinderTest.php+++ b/tests/Unit/Middleware/BinderTest.php@@ -25,9 +25,14 @@ namespace Tests\Unit\Middleware;use Carbon\Carbon;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;use FireflyIII\Http\Middleware\Binder;+use FireflyIII\Import\Prerequisites\BunqPrerequisites;+use FireflyIII\Import\Prerequisites\FakePrerequisites;use FireflyIII\Import\Prerequisites\PrerequisitesInterface;+use FireflyIII\Import\Prerequisites\SpectrePrerequisites;+use FireflyIII\Import\Prerequisites\YnabPrerequisites;use FireflyIII\Models\AccountType;use FireflyIII\Models\AvailableBudget;use FireflyIII\Models\Preference;@@ -64,6 +69,7 @@ class BinderTest extends TestCase*/public function testAccount(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{account}', function () {return 'OK';@@ -82,6 +88,7 @@ class BinderTest extends TestCase*/public function testAccountList(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{accountList}', function (Collection $accounts) {return 'count: ' . $accounts->count();@@ -99,6 +106,7 @@ class BinderTest extends TestCase*/public function testAccountListAllAssets(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{accountList}', function (Collection $accounts) {return 'count: ' . $accounts->count();@@ -121,6 +129,7 @@ class BinderTest extends TestCase*/public function testAccountListEmpty(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{accountList}', static function (Collection $accounts) {return 'count: ' . $accounts->count();@@ -137,6 +146,7 @@ class BinderTest extends TestCase*/public function testAccountListInvalid(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{accountList}', function (Collection $accounts) {return 'count: ' . $accounts->count();@@ -154,6 +164,7 @@ class BinderTest extends TestCase*/public function testAccountListNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{accountList}', function (Collection $accounts) {return 'count: ' . $accounts->count();@@ -169,6 +180,7 @@ class BinderTest extends TestCase*/public function testAccountNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{account}', function () {return 'OK';@@ -186,6 +198,7 @@ class BinderTest extends TestCase*/public function testAccountNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{account}', function () {return 'OK';@@ -202,6 +215,7 @@ class BinderTest extends TestCase*/public function testAttachment(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{attachment}', function () {return 'OK';@@ -219,6 +233,7 @@ class BinderTest extends TestCase*/public function testAttachmentNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{attachment}', function () {return 'OK';@@ -236,6 +251,7 @@ class BinderTest extends TestCase*/public function testAttachmentNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{attachment}', function () {return 'OK';@@ -246,12 +262,47 @@ class BinderTest extends TestCase$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}+ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Models\AvailableBudget+ */+ public function testAvailableBudget(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Route::middleware(Binder::class)->any(+ '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {+ return $availableBudget->id ?? 0;+ }+ );+ $this->be($this->user());+ $response = $this->get('/_test/binder/1');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ }++ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Models\AvailableBudget+ */+ public function testAvailableBudgetNotFound(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Route::middleware(Binder::class)->any(+ '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {+ return $availableBudget->id ?? 0;+ }+ );+ $this->be($this->user());+ $response = $this->get('/_test/binder/-1');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }+/*** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Models\Bill*/public function testBill(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{bill}', function () {return 'OK';@@ -269,6 +320,7 @@ class BinderTest extends TestCase*/public function testBillNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{bill}', function () {return 'OK';@@ -286,6 +338,7 @@ class BinderTest extends TestCase*/public function testBillNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{bill}', function () {return 'OK';@@ -302,6 +355,7 @@ class BinderTest extends TestCase*/public function testBudget(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budget}', function () {return 'OK';@@ -319,6 +373,7 @@ class BinderTest extends TestCase*/public function testBudgetLimit(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetLimit}', function () {return 'OK';@@ -336,6 +391,7 @@ class BinderTest extends TestCase*/public function testBudgetLimitNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetLimit}', function () {return 'OK';@@ -353,6 +409,7 @@ class BinderTest extends TestCase*/public function testBudgetLimitNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetLimit}', function () {return 'OK';@@ -369,6 +426,7 @@ class BinderTest extends TestCase*/public function testBudgetList(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetList}', function (Collection $budgets) {return 'count: ' . $budgets->count();@@ -384,15 +442,16 @@ class BinderTest extends TestCase* @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\BudgetList*/- public function testBudgetListInvalid(): void+ public function testBudgetListEmpty(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetList}', function (Collection $budgets) {return 'count: ' . $budgets->count();});$this->be($this->user());- $response = $this->get('/_test/binder/-1');+ $response = $this->get('/_test/binder/');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}@@ -400,249 +459,103 @@ class BinderTest extends TestCase* @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\BudgetList*/- public function testBudgetListEmpty(): void+ public function testBudgetListInvalid(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{budgetList}', function (Collection $budgets) {return 'count: ' . $budgets->count();});$this->be($this->user());- $response = $this->get('/_test/binder/');+ $response = $this->get('/_test/binder/-1');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\CLIToken- */- public function testCLIToken(): void- {- $repos = $this->mock(UserRepositoryInterface::class);- $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();-- $token = new Preference;- $token->data = 'token';-- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);-- Route::middleware(Binder::class)->any(- '/_test/binder/{cliToken}', static function (string $token) {- return sprintf('token: %s', $token);- }- );-- $response = $this->get('/_test/binder/token');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('token');-- }-- /**- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\CLIToken+ * @covers \FireflyIII\Models\Budget*/- public function testCLITokenNotFound(): void+ public function testBudgetNotFound(): void{- $repos = $this->mock(UserRepositoryInterface::class);- $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();-- $token = new Preference;- $token->data = 'token';-- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);-+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{cliToken}', static function (string $token) {- return sprintf('token: %s', $token);+ '/_test/binder/{budget}', function () {+ return 'OK';});- $response = $this->get('/_test/binder/tokenX');+ $this->be($this->user());+ $response = $this->get('/_test/binder/0');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ConfigurationName- */- public function testConfigName(): void- {- Route::middleware(Binder::class)->any(- '/_test/binder/{configName}', static function (string $name) {- return sprintf('configName: %s', $name);- }- );-- $response = $this->get('/_test/binder/is_demo_site');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('is_demo_site');- }--- /**- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ConfigurationName+ * @covers \FireflyIII\Models\Budget*/- public function testConfigNameNotFOund(): void+ public function testBudgetNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{configName}', static function (string $name) {- return sprintf('configName: %s', $name);+ '/_test/binder/{budget}', function () {+ return 'OK';});- $response = $this->get('/_test/binder/is_demoX_site');+ $response = $this->get('/_test/binder/1');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/**- * Normal user can access file routine- ** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ImportProvider- */- public function testImportProvider(): void- {- $repository = $this->mock(UserRepositoryInterface::class);- $this->mock(PrerequisitesInterface::class);-- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();-- Route::middleware(Binder::class)->any(- '/_test/binder/{import_provider}', static function (string $name) {- return sprintf('import_provider: %s', $name);- }- );-- $this->be($this->user());- $response = $this->get('/_test/binder/file');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('file');- }-- /**- * Normal user cannot access fake import routine.- *- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ImportProvider+ * @covers \FireflyIII\Support\Binder\CLIToken*/- public function testImportProviderFake(): void+ public function testCLIToken(): void{- $repository = $this->mock(UserRepositoryInterface::class);- $this->mock(PrerequisitesInterface::class);-- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();-- Route::middleware(Binder::class)->any(- '/_test/binder/{import_provider}', static function (string $name) {- return sprintf('import_provider: %s', $name);- }- );-- $this->be($this->user());- $response = $this->get('/_test/binder/fake');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());- }+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repos = $this->mock(UserRepositoryInterface::class);+ $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();- /**- * Nobody can access "bad" import routine.- *- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ImportProvider- */- public function testImportProviderBad(): void- {- $repository = $this->mock(UserRepositoryInterface::class);- $this->mock(PrerequisitesInterface::class);+ $token = new Preference;+ $token->data = 'token';- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);Route::middleware(Binder::class)->any(- '/_test/binder/{import_provider}', static function (string $name) {- return sprintf('import_provider: %s', $name);+ '/_test/binder/{cliToken}', static function (string $token) {+ return sprintf('token: %s', $token);});- $this->be($this->user());- $response = $this->get('/_test/binder/bad');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());- }-- /**- * Demo user cannot access file import routine.- *- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ImportProvider- */- public function testImportProviderDemoFile(): void- {- $repository = $this->mock(UserRepositoryInterface::class);- $this->mock(PrerequisitesInterface::class);-- $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();-- Route::middleware(Binder::class)->any(- '/_test/binder/{import_provider}', static function (string $name) {- return sprintf('import_provider: %s', $name);- }- );+ $response = $this->get('/_test/binder/token');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response->assertSee('token');- $this->be($this->user());- $response = $this->get('/_test/binder/file');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\ImportProvider+ * @covers \FireflyIII\Support\Binder\CLIToken*/- public function testImportProviderNotLoggedIn(): void+ public function testCLITokenNotFound(): void{- $this->mock(UserRepositoryInterface::class);- $this->mock(PrerequisitesInterface::class);-- Route::middleware(Binder::class)->any(- '/_test/binder/{import_provider}', static function (string $name) {- return sprintf('import_provider: %s', $name);- }- );-- $response = $this->get('/_test/binder/file');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());- }-+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repos = $this->mock(UserRepositoryInterface::class);+ $repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();- /**- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Budget- */- public function testBudgetNotFound(): void- {- Route::middleware(Binder::class)->any(- '/_test/binder/{budget}', function () {- return 'OK';- }- );+ $token = new Preference;+ $token->data = 'token';- $this->be($this->user());- $response = $this->get('/_test/binder/0');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());- }+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);- /**- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Budget- */- public function testBudgetNotLoggedIn(): void- {Route::middleware(Binder::class)->any(- '/_test/binder/{budget}', function () {- return 'OK';+ '/_test/binder/{cliToken}', static function (string $token) {+ return sprintf('token: %s', $token);});- $response = $this->get('/_test/binder/1');+ $response = $this->get('/_test/binder/tokenX');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}@@ -652,6 +565,7 @@ class BinderTest extends TestCase*/public function testCategory(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{category}', function () {return 'OK';@@ -669,6 +583,7 @@ class BinderTest extends TestCase*/public function testCategoryList(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{categoryList}', function (Collection $categories) {return 'count: ' . $categories->count();@@ -686,6 +601,7 @@ class BinderTest extends TestCase*/public function testCategoryListInvalid(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{categoryList}', function (Collection $categories) {return 'count: ' . $categories->count();@@ -702,6 +618,7 @@ class BinderTest extends TestCase*/public function testCategoryNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{category}', function () {return 'OK';@@ -719,6 +636,7 @@ class BinderTest extends TestCase*/public function testCategoryNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{category}', function () {return 'OK';@@ -729,12 +647,48 @@ class BinderTest extends TestCase$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}+ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Support\Binder\ConfigurationName+ */+ public function testConfigName(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Route::middleware(Binder::class)->any(+ '/_test/binder/{configName}', static function (string $name) {+ return sprintf('configName: %s', $name);+ }+ );++ $response = $this->get('/_test/binder/is_demo_site');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response->assertSee('is_demo_site');+ }++ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Support\Binder\ConfigurationName+ */+ public function testConfigNameNotFound(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Route::middleware(Binder::class)->any(+ '/_test/binder/{configName}', static function (string $name) {+ return sprintf('configName: %s', $name);+ }+ );++ $response = $this->get('/_test/binder/is_demoX_site');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }+/*** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\CurrencyCode*/public function testCurrencyCode(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{fromCurrencyCode}', function () {return 'OK';@@ -752,6 +706,7 @@ class BinderTest extends TestCase*/public function testCurrencyCodeNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{fromCurrencyCode}', function () {return 'OK';@@ -769,6 +724,7 @@ class BinderTest extends TestCase*/public function testCurrencyCodeNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{fromCurrencyCode}', function () {return 'OK';@@ -785,6 +741,7 @@ class BinderTest extends TestCase*/public function testDate(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -810,6 +767,7 @@ class BinderTest extends TestCase*/public function testDateCurrentMonthEnd(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {Log::debug(sprintf('Received in function: "%s"', $date->format('Y-m-d')));@@ -837,6 +795,7 @@ class BinderTest extends TestCase*/public function testDateCurrentMonthStart(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -863,6 +822,7 @@ class BinderTest extends TestCase*/public function testDateCurrentYearEnd(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -889,6 +849,7 @@ class BinderTest extends TestCase*/public function testDateCurrentYearStart(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));$date = new Carbon;$date->startOfYear();$testDate = clone $date;@@ -916,6 +877,7 @@ class BinderTest extends TestCase*/public function testDateFiscalYearEnd(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -943,6 +905,7 @@ class BinderTest extends TestCase*/public function testDateFiscalYearStart(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -970,6 +933,7 @@ class BinderTest extends TestCase*/public function testDateInvalid(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{date}', function (Carbon $date) {return 'date: ' . $date->format('Y-m-d');@@ -992,6 +956,7 @@ class BinderTest extends TestCase*/public function testImportJob(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {return 'OK';@@ -1009,6 +974,7 @@ class BinderTest extends TestCase*/public function testImportJobNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {return 'OK';@@ -1026,6 +992,7 @@ class BinderTest extends TestCase*/public function testImportJobNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {return 'OK';@@ -1037,187 +1004,316 @@ class BinderTest extends TestCase}/**+ * Normal user can access file routine+ ** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\JournalList+ * @covers \FireflyIII\Support\Binder\ImportProvider*/- public function testJournalList(): void+ public function testImportProvider(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repository = $this->mock(UserRepositoryInterface::class);+ $this->mock(PrerequisitesInterface::class);++ // mock all prerequisite classes.+ $bunq = $this->mock(BunqPrerequisites::class);+ $spectre = $this->mock(SpectrePrerequisites::class);+ $ynab = $this->mock(YnabPrerequisites::class);++ $bunq->shouldReceive('setUser')->atLeast()->once();+ $spectre->shouldReceive('setUser')->atLeast()->once();+ $ynab->shouldReceive('setUser')->atLeast()->once();+ $bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+++ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();+Route::middleware(Binder::class)->any(- '/_test/binder/{journalList}', static function (array $journals) {- return 'count: ' . count($journals);+ '/_test/binder/{import_provider}', static function (string $name) {+ return sprintf('import_provider: %s', $name);});+$this->be($this->user());- $withdrawal = $this->getRandomWithdrawal();- $deposit = $this->getRandomDeposit();- $response = $this->get(sprintf('/_test/binder/%d,%d', $withdrawal->id, $deposit->id));+ $response = $this->get('/_test/binder/file');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('count: 2');+ $response->assertSee('file');}/**+ * Nobody can access "bad" import routine.+ ** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\JournalList+ * @covers \FireflyIII\Support\Binder\ImportProvider*/- public function testJournalListEmpty(): void+ public function testImportProviderBad(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repository = $this->mock(UserRepositoryInterface::class);+ $this->mock(PrerequisitesInterface::class);++ // mock all prerequisite classes.+ $bunq = $this->mock(BunqPrerequisites::class);+ $spectre = $this->mock(SpectrePrerequisites::class);+ $ynab = $this->mock(YnabPrerequisites::class);++ $bunq->shouldReceive('setUser')->atLeast()->once();+ $spectre->shouldReceive('setUser')->atLeast()->once();+ $ynab->shouldReceive('setUser')->atLeast()->once();+ $bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+++ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();+Route::middleware(Binder::class)->any(- '/_test/binder/{journalList}', static function (array $journals) {- return 'count: ' . count($journals);- });+ '/_test/binder/{import_provider}', static function (string $name) {+ return sprintf('import_provider: %s', $name);+ }+ );$this->be($this->user());- $response = $this->get('/_test/binder/-1');+ $response = $this->get('/_test/binder/bad');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/**- * Not logged in.+ * Demo user cannot access file import routine.** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\JournalList+ * @covers \FireflyIII\Support\Binder\ImportProvider*/- public function testJournalListNotLoggedIn(): void+ public function testImportProviderDemoFile(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repository = $this->mock(UserRepositoryInterface::class);+ $this->mock(PrerequisitesInterface::class);++ // mock all prerequisite classes.+ $bunq = $this->mock(BunqPrerequisites::class);+ $spectre = $this->mock(SpectrePrerequisites::class);+ $ynab = $this->mock(YnabPrerequisites::class);+ $fake = $this->mock(FakePrerequisites::class);++ $fake->shouldReceive('setUser')->atLeast()->once();+ $fake->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);++ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();+Route::middleware(Binder::class)->any(- '/_test/binder/{journalList}', static function (array $journals) {- return 'count: ' . count($journals);- });+ '/_test/binder/{import_provider}', static function (string $name) {+ return sprintf('import_provider: %s', $name);+ }+ );- $response = $this->get('/_test/binder/-1');+ $this->be($this->user());+ $response = $this->get('/_test/binder/file');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/**+ * Normal user cannot access fake import routine.+ ** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\LinkType+ * @covers \FireflyIII\Support\Binder\ImportProvider*/- public function testLinkType(): void+ public function testImportProviderFake(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $repository = $this->mock(UserRepositoryInterface::class);+ $this->mock(PrerequisitesInterface::class);++ // mock all prerequisite classes.+ $bunq = $this->mock(BunqPrerequisites::class);+ $spectre = $this->mock(SpectrePrerequisites::class);+ $ynab = $this->mock(YnabPrerequisites::class);++ $bunq->shouldReceive('setUser')->atLeast()->once();+ $spectre->shouldReceive('setUser')->atLeast()->once();+ $ynab->shouldReceive('setUser')->atLeast()->once();+ $bunq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $spectre->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);+ $ynab->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);++ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();+Route::middleware(Binder::class)->any(- '/_test/binder/{linkType}', function () {- return 'OK';+ '/_test/binder/{import_provider}', static function (string $name) {+ return sprintf('import_provider: %s', $name);});$this->be($this->user());- $response = $this->get('/_test/binder/1');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response = $this->get('/_test/binder/fake');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\LinkType+ * @covers \FireflyIII\Support\Binder\ImportProvider*/- public function testLinkTypeNotFound(): void+ public function testImportProviderNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));+ $this->mock(UserRepositoryInterface::class);+ $this->mock(PrerequisitesInterface::class);+Route::middleware(Binder::class)->any(- '/_test/binder/{linkType}', function () {- return 'OK';+ '/_test/binder/{import_provider}', static function (string $name) {+ return sprintf('import_provider: %s', $name);});- $this->be($this->user());- $response = $this->get('/_test/binder/0');+ $response = $this->get('/_test/binder/file');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\LinkType+ * @covers \FireflyIII\Support\Binder\JournalList*/- public function testLinkTypeNotLoggedIn(): void+ public function testJournalList(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{linkType}', function () {- return 'OK';+ '/_test/binder/{journalList}', static function (array $journals) {+ return 'count: ' . count($journals);});+ $withdrawalArray = $this->getRandomWithdrawalAsArray();+ $collector = $this->mock(GroupCollectorInterface::class);+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($withdrawalArray);- $response = $this->get('/_test/binder/1');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $this->be($this->user());+ $withdrawal = $this->getRandomWithdrawal();+ $deposit = $this->getRandomDeposit();+ $response = $this->get(sprintf('/_test/binder/%d,%d', $withdrawal->id, $deposit->id));+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response->assertSee('count: 2');}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\PiggyBank+ * @covers \FireflyIII\Support\Binder\JournalList*/- public function testPiggyBank(): void+ public function testJournalListEmpty(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{piggyBank}', function () {- return 'OK';+ '/_test/binder/{journalList}', static function (array $journals) {+ return 'count: ' . count($journals);});+ $collector = $this->mock(GroupCollectorInterface::class);+ $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('setJournalIds')->atLeast()->once()->andReturnSelf();+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([]);++$this->be($this->user());- $response = $this->get('/_test/binder/1');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response = $this->get('/_test/binder/-1');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }++ /**+ * Not logged in.+ *+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Support\Binder\JournalList+ */+ public function testJournalListNotLoggedIn(): void+ {+ Log::info(sprintf('Now in test %s.', __METHOD__));+ Route::middleware(Binder::class)->any(+ '/_test/binder/{journalList}', static function (array $journals) {+ return 'count: ' . count($journals);+ }+ );++ $response = $this->get('/_test/binder/-1');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}-/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Preference+ * @covers \FireflyIII\Models\LinkType*/- public function testPreference(): void+ public function testLinkType(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{preference}', static function (?Preference $preference) {- return $preference->name ?? 'unknown';+ '/_test/binder/{linkType}', function () {+ return 'OK';});$this->be($this->user());- $response = $this->get('/_test/binder/frontPageAccounts');+ $response = $this->get('/_test/binder/1');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('frontPageAccounts');}-/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Recurrence+ * @covers \FireflyIII\Models\LinkType*/- public function testRecurrence(): void+ public function testLinkTypeNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {- return $recurrence->description ?? 'unknown';+ '/_test/binder/{linkType}', function () {+ return 'OK';});+$this->be($this->user());- $response = $this->get('/_test/binder/1');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response = $this->get('/_test/binder/0');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Recurrence+ * @covers \FireflyIII\Models\LinkType*/- public function testRecurrenceNotFound(): void+ public function testLinkTypeNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {- return $recurrence->description ?? 'unknown';+ '/_test/binder/{linkType}', function () {+ return 'OK';});- $this->be($this->user());- $response = $this->get('/_test/binder/-1');++ $response = $this->get('/_test/binder/1');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\TransactionGroup+ * @covers \FireflyIII\Models\PiggyBank*/- public function testTransactionGroup(): void+ public function testPiggyBank(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {- return $transactionGroup->title ?? 'unknown';+ '/_test/binder/{piggyBank}', function () {+ return 'OK';});+$this->be($this->user());$response = $this->get('/_test/binder/1');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());@@ -1225,60 +1321,65 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\TransactionGroup+ * @covers \FireflyIII\Models\PiggyBank*/- public function testTransactionGroupNotFound(): void+ public function testPiggyBankNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {- return $transactionGroup->title ?? 'unknown';+ '/_test/binder/{piggyBank}', function () {+ return 'OK';});+$this->be($this->user());- $response = $this->get('/_test/binder/-1');+ $response = $this->get('/_test/binder/0');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}-/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\AvailableBudget+ * @covers \FireflyIII\Models\PiggyBank*/- public function testAvailableBudget(): void+ public function testPiggyBankNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {- return $availableBudget->id ?? 0;+ '/_test/binder/{piggyBank}', function () {+ return 'OK';});- $this->be($this->user());+$response = $this->get('/_test/binder/1');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\AvailableBudget+ * @covers \FireflyIII\Models\Preference*/- public function testAvailableBudgetNotFound(): void+ public function testPreference(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {- return $availableBudget->id ?? 0;+ '/_test/binder/{preference}', static function (?Preference $preference) {+ return $preference->name ?? 'unknown';});+$this->be($this->user());- $response = $this->get('/_test/binder/-1');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $response = $this->get('/_test/binder/frontPageAccounts');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());+ $response->assertSee('frontPageAccounts');}-/*** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Models\Preference*/public function testPreferenceNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{preference}', static function (?Preference $preference) {return $preference->name ?? 'unknown';@@ -1292,34 +1393,35 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\PiggyBank+ * @covers \FireflyIII\Models\Recurrence*/- public function testPiggyBankNotFound(): void+ public function testRecurrence(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{piggyBank}', function () {- return 'OK';+ '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {+ return $recurrence->description ?? 'unknown';});-$this->be($this->user());- $response = $this->get('/_test/binder/0');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $response = $this->get('/_test/binder/1');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\PiggyBank+ * @covers \FireflyIII\Models\Recurrence*/- public function testPiggyBankNotLoggedIn(): void+ public function testRecurrenceNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any(- '/_test/binder/{piggyBank}', function () {- return 'OK';+ '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {+ return $recurrence->description ?? 'unknown';});-- $response = $this->get('/_test/binder/1');+ $this->be($this->user());+ $response = $this->get('/_test/binder/-1');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}@@ -1329,6 +1431,7 @@ class BinderTest extends TestCase*/public function testRule(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{rule}', function () {return 'OK';@@ -1346,6 +1449,7 @@ class BinderTest extends TestCase*/public function testRuleGroup(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{ruleGroup}', function () {return 'OK';@@ -1363,6 +1467,7 @@ class BinderTest extends TestCase*/public function testRuleGroupNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{ruleGroup}', function () {return 'OK';@@ -1380,6 +1485,7 @@ class BinderTest extends TestCase*/public function testRuleGroupNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{ruleGroup}', function () {return 'OK';@@ -1396,6 +1502,7 @@ class BinderTest extends TestCase*/public function testRuleNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{rule}', function () {return 'OK';@@ -1413,6 +1520,7 @@ class BinderTest extends TestCase*/public function testRuleNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{rule}', function () {return 'OK';@@ -1429,6 +1537,7 @@ class BinderTest extends TestCase*/public function testTJ(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{tj}', function () {return 'OK';@@ -1446,6 +1555,7 @@ class BinderTest extends TestCase*/public function testTJNotFound(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{tj}', function () {return 'OK';@@ -1463,6 +1573,7 @@ class BinderTest extends TestCase*/public function testTJNotLoggedIn(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));Route::middleware(Binder::class)->any('/_test/binder/{tj}', function () {return 'OK';@@ -1516,6 +1627,26 @@ class BinderTest extends TestCase$response->assertSee('count: 2');}+ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Support\Binder\TagList+ */+ public function testTagListEmpty(): void+ {+ $tagRepos = $this->mock(TagRepositoryInterface::class);+ $tagRepos->shouldReceive('setUser');+ $tagRepos->shouldReceive('get')->once()->andReturn(new Collection());++ Route::middleware(Binder::class)->any(+ '/_test/binder/{tagList}', function (Collection $tags) {+ return 'count: ' . $tags->count();+ }+ );+ $this->be($this->user());+ $response = $this->get('/_test/binder/noblaexista');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }+/*** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\TagList@@ -1543,18 +1674,50 @@ class BinderTest extends TestCase}/**- * TODO there is a random element in this test that breaks the middleware.- *+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Models\Tag+ */+ public function testTagNotFound(): void+ {+ Route::middleware(Binder::class)->any(+ '/_test/binder/{tag}', function () {+ return 'OK';+ }+ );++ $this->be($this->user());+ $response = $this->get('/_test/binder/0');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }++ /**+ * @covers \FireflyIII\Http\Middleware\Binder+ * @covers \FireflyIII\Models\Tag+ */+ public function testTagNotLoggedIn(): void+ {+ Route::middleware(Binder::class)->any(+ '/_test/binder/{tag}', function () {+ return 'OK';+ }+ );++ $response = $this->get('/_test/binder/1');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }++ /*** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\TagOrId*/- public function testTagOrIdByTag(): void+ public function testTagOrIdBothNull(): void{$tagRepos = $this->mock(TagRepositoryInterface::class);$tag = $this->getRandomTag();$tagRepos->shouldReceive('setUser');- $tagRepos->shouldReceive('findByTag')->withArgs([$tag->tag])->andReturn($tag)->atLeast()->once();+ $tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();+ $tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturnNull()->atLeast()->once();Route::middleware(Binder::class)->any('/_test/binder/{tagOrId}', static function (?Tag $tag) {@@ -1567,10 +1730,8 @@ class BinderTest extends TestCase);$this->be($this->user());- $response = $this->get(sprintf('/_test/binder/%s', $tag->tag));- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());-- $response->assertSee($tag->tag);+ $response = $this->get(sprintf('/_test/binder/%d', $tag->id));+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}/**@@ -1604,17 +1765,18 @@ class BinderTest extends TestCase}/**+ * TODO there is a random element in this test that breaks the middleware.+ ** @covers \FireflyIII\Http\Middleware\Binder* @covers \FireflyIII\Support\Binder\TagOrId*/- public function testTagOrIdBothNull(): void+ public function testTagOrIdByTag(): void{$tagRepos = $this->mock(TagRepositoryInterface::class);$tag = $this->getRandomTag();$tagRepos->shouldReceive('setUser');- $tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();- $tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturnNull()->atLeast()->once();+ $tagRepos->shouldReceive('findByTag')->withArgs([$tag->tag])->andReturn($tag)->atLeast()->once();Route::middleware(Binder::class)->any('/_test/binder/{tagOrId}', static function (?Tag $tag) {@@ -1627,8 +1789,10 @@ class BinderTest extends TestCase);$this->be($this->user());- $response = $this->get(sprintf('/_test/binder/%d', $tag->id));- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $response = $this->get(sprintf('/_test/binder/%s', $tag->tag));+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());++ $response->assertSee($tag->tag);}/**@@ -1653,32 +1817,29 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Support\Binder\TagList+ * @covers \FireflyIII\Models\TransactionCurrency*/- public function testTagListEmpty(): void+ public function testTransactionCurrency(): void{- $tagRepos = $this->mock(TagRepositoryInterface::class);- $tagRepos->shouldReceive('setUser');- $tagRepos->shouldReceive('get')->once()->andReturn(new Collection());-Route::middleware(Binder::class)->any(- '/_test/binder/{tagList}', function (Collection $tags) {- return 'count: ' . $tags->count();+ '/_test/binder/{currency}', function () {+ return 'OK';});+$this->be($this->user());- $response = $this->get('/_test/binder/noblaexista');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $response = $this->get('/_test/binder/1');+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());}/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Tag+ * @covers \FireflyIII\Models\TransactionCurrency*/- public function testTagNotFound(): void+ public function testTransactionCurrencyNotFound(): void{Route::middleware(Binder::class)->any(- '/_test/binder/{tag}', function () {+ '/_test/binder/{currency}', function () {return 'OK';});@@ -1690,12 +1851,12 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\Tag+ * @covers \FireflyIII\Models\TransactionCurrency*/- public function testTagNotLoggedIn(): void+ public function testTransactionCurrencyNotLoggedIn(): void{Route::middleware(Binder::class)->any(- '/_test/binder/{tag}', function () {+ '/_test/binder/{currency}', function () {return 'OK';});@@ -1706,16 +1867,15 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\TransactionCurrency+ * @covers \FireflyIII\Models\TransactionGroup*/- public function testTransactionCurrency(): void+ public function testTransactionGroup(): void{Route::middleware(Binder::class)->any(- '/_test/binder/{currency}', function () {- return 'OK';+ '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {+ return $transactionGroup->title ?? 'unknown';});-$this->be($this->user());$response = $this->get('/_test/binder/1');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());@@ -1723,34 +1883,17 @@ class BinderTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\TransactionCurrency+ * @covers \FireflyIII\Models\TransactionGroup*/- public function testTransactionCurrencyNotFound(): void+ public function testTransactionGroupNotFound(): void{Route::middleware(Binder::class)->any(- '/_test/binder/{currency}', function () {- return 'OK';+ '/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {+ return $transactionGroup->title ?? 'unknown';});-$this->be($this->user());- $response = $this->get('/_test/binder/0');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());- }-- /**- * @covers \FireflyIII\Http\Middleware\Binder- * @covers \FireflyIII\Models\TransactionCurrency- */- public function testTransactionCurrencyNotLoggedIn(): void- {- Route::middleware(Binder::class)->any(- '/_test/binder/{currency}', function () {- return 'OK';- }- );-- $response = $this->get('/_test/binder/1');+ $response = $this->get('/_test/binder/-1');$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}diff --git a/tests/Unit/Middleware/IsDemoUserTest.php b/tests/Unit/Middleware/IsDemoUserTest.phpindex 15f7255ce1..657df08f5b 100644--- a/tests/Unit/Middleware/IsDemoUserTest.php+++ b/tests/Unit/Middleware/IsDemoUserTest.php@@ -25,6 +25,7 @@ namespace Tests\Unit\Middleware;use FireflyIII\Http\Middleware\IsDemoUser;use FireflyIII\Http\Middleware\StartFireflySession;+use FireflyIII\Repositories\User\UserRepositoryInterface;use Log;use Route;use Symfony\Component\HttpFoundation\Response;@@ -57,6 +58,10 @@ class IsDemoUserTest extends TestCase*/public function testMiddlewareAuthenticated(): void{+ $userRepos =$this->mock(UserRepositoryInterface::class);++ $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnFalse();+$this->be($this->user());$response = $this->get('/_test/is-demo');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());@@ -67,6 +72,10 @@ class IsDemoUserTest extends TestCase*/public function testMiddlewareIsDemoUser(): void{+ $userRepos =$this->mock(UserRepositoryInterface::class);++ $userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnTrue();+$this->be($this->demoUser());$response = $this->get('/_test/is-demo');$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());diff --git a/tests/Unit/Middleware/RangeTest.php b/tests/Unit/Middleware/RangeTest.phpindex 3ab1f92b6c..00b95c0328 100644--- a/tests/Unit/Middleware/RangeTest.php+++ b/tests/Unit/Middleware/RangeTest.php@@ -24,12 +24,16 @@ declare(strict_types=1);namespace Tests\Unit\Middleware;use FireflyIII\Http\Middleware\Range;+use FireflyIII\Models\Preference;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use Log;use Route;use Symfony\Component\HttpFoundation\Response;use Tests\TestCase;+use Preferences;+use Mockery;+use Amount;/*** Class RangeTest@@ -61,6 +65,27 @@ class RangeTest extends TestCase$repository = $this->mock(JournalRepositoryInterface::class);$repository->shouldReceive('firstNull')->andReturn(TransactionJournal::first());$this->withoutExceptionHandling();++ $viewPreference = new Preference;+ $viewPreference->data = '1M';++ $langPreference = new Preference;+ $langPreference->data = 'en_US';++ $currPreference = new Preference;+ $currPreference->data = 'EUR';++ $listPreference = new Preference;+ $listPreference->data = 10;+++ Preferences::shouldReceive('get')->withArgs(['viewRange','1M'])->atLeast()->once()->andReturn($viewPreference);+ Preferences::shouldReceive('get')->withArgs(['language','en_US'])->atLeast()->once()->andReturn($langPreference);+ Preferences::shouldReceive('get')->withArgs(['list-length',10])->atLeast()->once()->andReturn($listPreference);+ Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($this->getEuro());+ //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');++$this->be($this->user());$response = $this->get('/_test/range');$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());diff --git a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php b/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.phpindex b8c9a7ab8c..515417272d 100644--- a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php+++ b/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php@@ -55,6 +55,7 @@ class AccountDestroyServiceTest extends TestCasepublic function testDestroyBasic(): void{$this->mock(RecurrenceDestroyService::class);+ $this->mock(JournalDestroyService::class);$account = Account::create(['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),'virtual_balance' => '0', 'iban' => null, 'active' => true]@@ -73,6 +74,7 @@ class AccountDestroyServiceTest extends TestCasepublic function testDestroyWithRecurrence(): void{$recService = $this->mock(RecurrenceDestroyService::class);+ $this->mock(JournalDestroyService::class);$account = Account::create(['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),'virtual_balance' => '0', 'iban' => null, 'active' => true]@@ -108,6 +110,7 @@ class AccountDestroyServiceTest extends TestCasepublic function testDestroyDontMove(): void{$this->mock(RecurrenceDestroyService::class);+ $this->mock(JournalDestroyService::class);// create objects:$account = Account::create(['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),@@ -132,6 +135,7 @@ class AccountDestroyServiceTest extends TestCasepublic function testDestroyMove(): void{$this->mock(RecurrenceDestroyService::class);+ $this->mock(JournalDestroyService::class);$account = Account::create(['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),'virtual_balance' => '0', 'iban' => null, 'active' => true]diff --git a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.phpindex 88950da7dc..401e9b6695 100644--- a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php+++ b/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php@@ -25,6 +25,8 @@ namespace Tests\Unit\Services\Internal\Update;use Carbon\Carbon;+use FireflyIII\Factory\AccountMetaFactory;+use FireflyIII\Factory\TransactionCurrencyFactory;use FireflyIII\Models\Account;use FireflyIII\Models\Note;use FireflyIII\Models\Transaction;@@ -59,9 +61,15 @@ class AccountUpdateServiceTest extends TestCase*/public function testDeleteExistingIB(): void{- $group = $this->getRandomWithdrawalGroup();- $accountRepos = $this->mock(AccountRepositoryInterface::class);- $destroySerice = $this->mock(TransactionGroupDestroyService::class);+ $group = $this->getRandomWithdrawalGroup();+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $destroySerice = $this->mock(TransactionGroupDestroyService::class);+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);++ $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());+ $metaFactory->shouldReceive('crud');+$accountRepos->shouldReceive('setUser')->atLeast()->once();$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);$destroySerice->shouldReceive('destroy')->atLeast()->once();@@ -93,6 +101,14 @@ class AccountUpdateServiceTest extends TestCase*/public function testUpdateBasic(): void{+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);++ $accountRepos->shouldReceive('setUser')->atLeast()->once();+ $metaFactory->shouldReceive('crud');+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();+/** @var Account $account */$account = $this->user()->accounts()->first();$data = [@@ -116,6 +132,14 @@ class AccountUpdateServiceTest extends TestCase*/public function testUpdateBasicEmptyNote(): void{+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);++ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();+ $accountRepos->shouldReceive('setUser')->atLeast()->once();+ $metaFactory->shouldReceive('crud');+/** @var Account $account */$account = $this->user()->accounts()->first();$data = [@@ -141,6 +165,14 @@ class AccountUpdateServiceTest extends TestCase*/public function testUpdateBasicExistingNote(): void{+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);++ $metaFactory->shouldReceive('crud');+ $accountRepos->shouldReceive('setUser')->atLeast()->once();+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturnNull();+/** @var Account $account */$account = $this->user()->accounts()->first();$note = new Note;@@ -176,13 +208,18 @@ class AccountUpdateServiceTest extends TestCase$destroySerice = $this->mock(TransactionGroupDestroyService::class);$group = $this->getRandomWithdrawalGroup();+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);+// make sure one transaction has the account as the asset.$journal = $group->transactionJournals()->first();$account = $journal->transactions()->first()->account;-+ $metaFactory->shouldReceive('crud');+ $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());$accountRepos->shouldReceive('setUser')->atLeast()->once();$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);+$data = ['name' => 'Some new name #' . $this->randomInt(),'active' => true,@@ -213,7 +250,13 @@ class AccountUpdateServiceTest extends TestCase{$deleteService = $this->mock(JournalDestroyService::class);- //$deleteService->shouldReceive('destroy')->once();+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);+ $metaFactory = $this->mock(AccountMetaFactory::class);++ $accountRepos->shouldReceive('setUser')->atLeast()->once();+ $currencyFactory->shouldReceive('find')->atLeast()->once()->andReturn($this->getEuro());+ $metaFactory->shouldReceive('crud');/** @var Account $account */$account = Account::create(diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.phpindex 980efc868c..bb883471c3 100644--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php@@ -63,6 +63,8 @@ class ConfigureMappingHandlerTest extends TestCasepublic function testApplySpecifics(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);+$importRepos->shouldReceive('setUser')->once();$job = new ImportJob;$job->user_id = $this->user()->id;@@ -145,6 +147,7 @@ class ConfigureMappingHandlerTest extends TestCase// mock repos$repository = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);// run configure mapping handler.// expect specific results:@@ -165,6 +168,7 @@ class ConfigureMappingHandlerTest extends TestCasepublic function testDoColumnConfig(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$importRepos->shouldReceive('setUser')->once();$job = new ImportJob;$job->user_id = $this->user()->id;@@ -230,6 +234,8 @@ class ConfigureMappingHandlerTest extends TestCasepublic function testDoMapOfColumn(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);+$importRepos->shouldReceive('setUser')->once();$job = new ImportJob;$job->user_id = $this->user()->id;@@ -343,6 +349,8 @@ class ConfigureMappingHandlerTest extends TestCasepublic function testGetPreProcessorName(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);+$importRepos->shouldReceive('setUser')->once();$job = new ImportJob;$job->user_id = $this->user()->id;@@ -422,6 +430,8 @@ class ConfigureMappingHandlerTest extends TestCasepublic function testGetValuesForMapping(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);+$importRepos->shouldReceive('setUser')->once();// create a reader to use in method.// 5 columns, of which #4 (index 3) is budget-id@@ -490,6 +500,7 @@ class ConfigureMappingHandlerTest extends TestCase*/public function testSanitizeColumnName(): void{+ $helper = $this->mock(AttachmentHelperInterface::class);$importRepos = $this->mock(ImportJobRepositoryInterface::class);$importRepos->shouldReceive('setUser')->once();$job = new ImportJob;diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.phpindex 07dd1d7e19..935f098d3c 100644--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php@@ -61,7 +61,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testConfigurationCompleteBasic(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);-+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-count' => 5,@@ -84,6 +84,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testConfigurationCompleteForeign(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-count' => 5,@@ -110,6 +111,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testConfigurationCompleteNoAmount(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-count' => 5,'column-roles' => [@@ -173,6 +175,7 @@ class ConfigureRolesHandlerTest extends TestCase];$repository = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$repository->shouldReceive('setUser')->once();$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'ready_to_run']);$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'map']);@@ -189,6 +192,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testGetExampleFromLine(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$lines = [['one', 'two', '', 'three'],['four', 'five', '', 'six'],@@ -212,6 +216,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testGetExamplesFromFile(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$importRepos->shouldReceive('setUser')->once();$importRepos->shouldReceive('setConfiguration')->once()->withAnyArgs();@@ -255,6 +260,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testGetHeadersHas(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);//$importRepos->shouldReceive('setUser')->once();// create a reader to use in method.// 5 columns, of which #4 (index 3) is budget-id@@ -278,6 +284,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testGetHeadersNone(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);// create a reader to use in method.// 5 columns, of which #4 (index 3) is budget-id@@ -418,7 +425,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testIgnoreUnmappableColumns(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);-+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-count' => 5,'column-roles' => [@@ -463,6 +470,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testIsMappingNecessaryNo(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-do-mapping' => [false, false, false],@@ -478,6 +486,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testIsMappingNecessaryYes(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$config = ['column-do-mapping' => [false, true, false, false],@@ -493,6 +502,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testMakeExamplesUnique(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$lines = [['one', 'two', '', 'three'],@@ -521,6 +531,7 @@ class ConfigureRolesHandlerTest extends TestCasepublic function testProcessSpecifics(): void{$importRepos = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);$line = [];$config = [@@ -555,6 +566,8 @@ class ConfigureRolesHandlerTest extends TestCase$job->save();$repository = $this->mock(ImportJobRepositoryInterface::class);+ $helper = $this->mock(AttachmentHelperInterface::class);+$repository->shouldReceive('setUser');$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['column-count' => 0]]);diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.phpindex 513241ab76..0edf095a0d 100644--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php@@ -162,7 +162,9 @@ class ConfigureUploadHandlerTest extends TestCase$job->save();$repository = $this->mock(ImportJobRepositoryInterface::class);+ $accountRepos = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('setUser');+ $accountRepos->shouldReceive('setUser');$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['date-format' => 'Ymd']]);$handler = new ConfigureUploadHandler;@@ -181,6 +183,8 @@ class ConfigureUploadHandlerTest extends TestCase*/public function testGetSpecifics(): void{+ $accountRepos = $this->mock(AccountRepositoryInterface::class);+$array = ['specifics' => ['IngDescription', 'BadFakeNewsThing',diff --git a/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php b/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.phpindex 308fbd735c..d227e570dc 100644--- a/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php+++ b/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php@@ -475,7 +475,7 @@ class ImportTransactionTest extends TestCase$importTransaction = new ImportTransaction;$importTransaction->amountDebit = '1.01';try {- $this->assertEquals('-1.01', $importTransaction->calculateAmount());+ $this->assertEquals('-1.010000000000', $importTransaction->calculateAmount());} catch (FireflyException $e) {$this->assertTrue(false, $e->getMessage());}@@ -507,7 +507,7 @@ class ImportTransactionTest extends TestCase$importTransaction->amount = '2.99';$importTransaction->modifiers['generic-debit-credit'] = 'D';try {- $this->assertEquals('-2.99', $importTransaction->calculateAmount());+ $this->assertEquals('-2.990000000000', $importTransaction->calculateAmount());} catch (FireflyException $e) {$this->assertTrue(false, $e->getMessage());}@@ -523,7 +523,7 @@ class ImportTransactionTest extends TestCase$importTransaction = new ImportTransaction;$importTransaction->amountNegated = '-1.56';try {- $this->assertEquals('1.56', $importTransaction->calculateAmount());+ $this->assertEquals('1.560000000000', $importTransaction->calculateAmount());} catch (FireflyException $e) {$this->assertTrue(false, $e->getMessage());}@@ -539,7 +539,7 @@ class ImportTransactionTest extends TestCase$importTransaction = new ImportTransaction;$importTransaction->amountNegated = '1.56';try {- $this->assertEquals('-1.56', $importTransaction->calculateAmount());+ $this->assertEquals('-1.560000000000', $importTransaction->calculateAmount());} catch (FireflyException $e) {$this->assertTrue(false, $e->getMessage());}@@ -556,7 +556,7 @@ class ImportTransactionTest extends TestCase$importTransaction->amount = '-2.17';$importTransaction->modifiers['rabo-debit-credit'] = 'C';try {- $this->assertEquals('2.17', $importTransaction->calculateAmount());+ $this->assertEquals('2.170000000000', $importTransaction->calculateAmount());} catch (FireflyException $e) {$this->assertTrue(false, $e->getMessage());}@@ -643,7 +643,7 @@ class ImportTransactionTest extends TestCase$importTransaction = new ImportTransaction;$importTransaction->foreignAmount = '6.77';$importTransaction->modifiers['generic-debit-credit'] = 'D';- $this->assertEquals('-6.77', $importTransaction->calculateForeignAmount());+ $this->assertEquals('-6.770000000000', $importTransaction->calculateForeignAmount());}/**@@ -656,7 +656,7 @@ class ImportTransactionTest extends TestCase$importTransaction = new ImportTransaction;$importTransaction->foreignAmount = '-5.77';$importTransaction->modifiers['generic-debit-credit'] = 'C';- $this->assertEquals('5.77', $importTransaction->calculateForeignAmount());+ $this->assertEquals('5.770000000000', $importTransaction->calculateForeignAmount());}/**diff --git a/tests/Unit/Transformers/CategoryTransformerTest.php b/tests/Unit/Transformers/CategoryTransformerTest.phpindex 8734a60f69..85fbbfa712 100644--- a/tests/Unit/Transformers/CategoryTransformerTest.php+++ b/tests/Unit/Transformers/CategoryTransformerTest.php@@ -25,13 +25,11 @@ namespace Tests\Unit\Transformers;use Carbon\Carbon;use FireflyIII\Models\Category;-use FireflyIII\Models\Transaction;-use FireflyIII\Models\TransactionCurrency;-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;+use FireflyIII\Repositories\Category\OperationsRepositoryInterface;use FireflyIII\Transformers\CategoryTransformer;-use Illuminate\Support\Collection;use Log;use Symfony\Component\HttpFoundation\ParameterBag;+use Tests\Support\TestDataTrait;use Tests\TestCase;@@ -43,6 +41,8 @@ use Tests\TestCase;*/class CategoryTransformerTest extends TestCase{+ use TestDataTrait;+/****/@@ -59,8 +59,8 @@ class CategoryTransformerTest extends TestCase*/public function testBasic(): void{- $repository = $this->mock(CategoryRepositoryInterface::class);- $repository->shouldReceive('setUser')->once();+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);+ $opsRepository->shouldReceive('setUser')->once();/** @var Category $category */$category = Category::first();@@ -80,35 +80,20 @@ class CategoryTransformerTest extends TestCase*/public function testWithDates(): void{- $repository = $this->mock(CategoryRepositoryInterface::class);- $repository->shouldReceive('setUser')->once();+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);+ $opsRepository->shouldReceive('setUser')->once();$parameters = new ParameterBag;$parameters->set('start', new Carbon('2018-01-01'));$parameters->set('end', new Carbon('2018-01-31'));- // mock some objects for the spent/earned lists.- $expense = [- 'currency_id' => 1,- 'currency_code' => 'EUR',- 'currency_symbol' => '€',- 'currency_decimal_places' => 2,- 'amount' => -100,- ];- $income = [- 'currency_id' => 1,- 'currency_code' => 'EUR',- 'currency_symbol' => '€',- 'currency_decimal_places' => 2,- 'amount' => 100,- ];--- $incomeCollection = [$income];- $expenseCollection = [$expense];+ $income = $this->categorySumIncome();+ $expense = $this->categorySumExpenses();+ $opsRepository->shouldReceive('sumIncome')+ ->atLeast()->once()->andReturn($income);- $repository->shouldReceive('spentInPeriod')->atLeast()->once()->andReturn($expenseCollection);- $repository->shouldReceive('earnedInPeriod')->atLeast()->once()->andReturn($incomeCollection);+ $opsRepository->shouldReceive('sumExpenses')+ ->atLeast()->once()->andReturn($expense);/** @var Category $category */$category = Category::first();@@ -117,27 +102,5 @@ class CategoryTransformerTest extends TestCase$result = $transformer->transform($category);$this->assertEquals($category->name, $result['name']);- $this->assertEquals(- [- [- 'currency_id' => 1,- 'currency_code' => 'EUR',- 'currency_symbol' => '€',- 'currency_decimal_places' => 2,- 'amount' => -100,- ],- ], $result['spent']- );- $this->assertEquals(- [- [- 'currency_id' => 1,- 'currency_code' => 'EUR',- 'currency_symbol' => '€',- 'currency_decimal_places' => 2,- 'amount' => 100,- ],- ], $result['earned']- );}}diff --git a/tests/Unit/Transformers/RecurrenceTransformerTest.php b/tests/Unit/Transformers/RecurrenceTransformerTest.phpindex c20e508362..37ce53592f 100644--- a/tests/Unit/Transformers/RecurrenceTransformerTest.php+++ b/tests/Unit/Transformers/RecurrenceTransformerTest.php@@ -25,11 +25,13 @@ namespace Tests\Unit\Transformers;use Carbon\Carbon;use FireflyIII\Factory\CategoryFactory;-use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;use FireflyIII\Transformers\RecurrenceTransformer;+use FireflyIII\Transformers\RuleGroupTransformer;+use FireflyIII\Transformers\RuleTransformer;+use FireflyIII\Transformers\TagTransformer;use Log;use Mockery;use Symfony\Component\HttpFoundation\ParameterBag;@@ -59,19 +61,21 @@ class RecurrenceTransformerTest extends TestCasepublic function testBasic(): void{$recurrenceRepos = $this->mock(RecurringRepositoryInterface::class);- $billRepos = $this->mock(BillRepositoryInterface::class);$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);$factory = $this->mock(CategoryFactory::class);$budgetRepos = $this->mock(BudgetRepositoryInterface::class);- $category = $this->getRandomCategory();- $budget = $this->getRandomBudget();- $piggy = $this->getRandomPiggyBank();- $bill = $this->getRandomBill();- $ranges = [new Carbon];- $recurrence = $this->getRandomRecurrence();++ $ruleGroupTransformer = $this->mock(RuleGroupTransformer::class);+ $ruleTransformer = $this->mock(RuleTransformer::class);+ $tagTransformer = $this->mock(TagTransformer::class);++ $category = $this->getRandomCategory();+ $budget = $this->getRandomBudget();+ $piggy = $this->getRandomPiggyBank();+ $ranges = [new Carbon];+ $recurrence = $this->getRandomRecurrence();// mock calls:$recurrenceRepos->shouldReceive('setUser')->atLeast()->once();- $billRepos->shouldReceive('setUser')->atLeast()->once();$piggyRepos->shouldReceive('setUser')->atLeast()->once();$factory->shouldReceive('setUser')->atLeast()->once();$budgetRepos->shouldReceive('setUser')->atLeast()->once();@@ -80,10 +84,9 @@ class RecurrenceTransformerTest extends TestCase$recurrenceRepos->shouldReceive('getNoteText')->once()->andReturn('Hi there');$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);+ $factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null, Mockery::any()])->andReturn($category);$budgetRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($budget);$piggyRepos->shouldReceive('findNull')->andReturn($piggy);- $billRepos->shouldReceive('find')->andReturn($bill);// basic transformation:@@ -95,7 +98,7 @@ class RecurrenceTransformerTest extends TestCase$this->assertEquals($recurrence->id, $result['id']);//$this->assertEquals('deposit', $result['transaction_type']);$this->assertEquals(true, $result['apply_rules']);- $this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);+ $this->assertEquals('Rep descr', $result['repetitions'][0]['description']);}diff --git a/tests/Unit/Transformers/RuleTransformerTest.php b/tests/Unit/Transformers/RuleTransformerTest.phpindex 3489e453b0..98bbbfdf84 100644--- a/tests/Unit/Transformers/RuleTransformerTest.php+++ b/tests/Unit/Transformers/RuleTransformerTest.php@@ -53,13 +53,17 @@ class RuleTransformerTest extends TestCase$repository = $this->mock(RuleRepositoryInterface::class);/** @var RuleTrigger $ruleTrigger */- $ruleTrigger = RuleTrigger::first();+ $ruleTrigger = RuleTrigger::where('trigger_type', '!=', 'user_action')->first();++ /** @var RuleTrigger $ruleTrigger */+ $moment = RuleTrigger::where('trigger_type', '=', 'user_action')->first();+/** @var RuleAction $ruleAction */$ruleAction = RuleAction::first();// mock stuff$repository->shouldReceive('setUser')->atLeast()->once();$repository->shouldReceive('getRuleActions')->atLeast()->once()->andReturn(new Collection([$ruleAction]));- $repository->shouldReceive('getRuleTriggers')->atLeast()->once()->andReturn(new Collection([$ruleTrigger]));+ $repository->shouldReceive('getRuleTriggers')->atLeast()->once()->andReturn(new Collection([$moment]), new Collection([$ruleTrigger]));$transformer = app(RuleTransformer::class);$transformer->setParameters(new ParameterBag);