diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.php
index 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.php
index 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.php
index fc047ee06e..0e484418f5 100644
--- a/app/Exceptions/GracefulNotFoundHandler.php
+++ b/app/Exceptions/GracefulNotFoundHandler.php
@@ -60,7 +60,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
switch ($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.php
index 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.php
index 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.php
index 211b075e2b..0c42ebf815 100644
--- a/app/Import/Storage/ImportArrayStorage.php
+++ b/app/Import/Storage/ImportArrayStorage.php
@@ -583,7 +583,6 @@ class ImportArrayStorage
DB::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.php
index 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.php
index 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.php
index 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.php
index 11a51616d5..94a7c058ff 100644
--- a/app/Support/FireflyConfig.php
+++ b/app/Support/FireflyConfig.php
@@ -40,7 +40,7 @@ class FireflyConfig
public 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 FireflyConfig
public 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.php
index 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.php
index 72bd3a2f03..999f515d43 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -99,7 +99,7 @@ class Preferences
public 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 Preferences
public 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.php
index bbab73358f..69415cd78c 100644
--- a/app/Support/Twig/General.php
+++ b/app/Support/Twig/General.php
@@ -208,10 +208,6 @@ class General extends Twig_Extension
return 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.php
index 4d1c91238e..de46620276 100644
--- a/app/Support/Twig/TransactionGroupTwig.php
+++ b/app/Support/Twig/TransactionGroupTwig.php
@@ -148,9 +148,6 @@ class TransactionGroupTwig extends Twig_Extension
return 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.php
index 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.php
index 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.php
index 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.php
index 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 TestCase
public 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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 TestCase
Preferences::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.php
index 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('
');
- }
-
}
diff --git a/tests/Feature/Controllers/Recurring/ShowControllerTest.php b/tests/Feature/Controllers/Recurring/ShowControllerTest.php
new file mode 100644
index 0000000000..4dc7c0b467
--- /dev/null
+++ b/tests/Feature/Controllers/Recurring/ShowControllerTest.php
@@ -0,0 +1,96 @@
+.
+ */
+
+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('');
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Feature/Controllers/Report/BudgetControllerTest.php b/tests/Feature/Controllers/Report/BudgetControllerTest.php
index 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.php
index 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 TestCase
public 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 TestCase
public 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 TestCase
public 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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 TestCase
public 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 TestCase
public 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.php
index 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.php
index 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.php
index 0fe38bb4e6..9cbb706b83 100644
--- a/tests/Support/TestDataTrait.php
+++ b/tests/Support/TestDataTrait.php
@@ -171,6 +171,41 @@ trait TestDataTrait
return $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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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());
@@ -171,6 +174,124 @@ class AccountFactoryTest extends TestCase
$account->forceDelete();
}
+ /**
+ * Test minimal set of data to make factory work (asset account).
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ 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);
+ $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',
+ ];
+
+ // 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);
+
+ $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);
+
+ }
+
/**
* Leave virtual balance empty.
*
@@ -197,12 +318,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', '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());
@@ -226,6 +350,47 @@ class AccountFactoryTest extends TestCase
$account->forceDelete();
}
+ /**
+ * Should return existing account.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ */
+ public function testCreateExisting(): void
+ {
+ $this->mock(AccountRepositoryInterface::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();
+ 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->id, $existing->id);
+ }
+
/**
* Create an expense account. This overrules the virtual balance.
* Role should not be set.
@@ -250,14 +415,17 @@ class AccountFactoryTest extends TestCase
'account_role' => 'defaultAsset',
];
- $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);
+
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user());
@@ -308,16 +476,20 @@ class AccountFactoryTest extends TestCase
'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(), '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();
try {
@@ -344,6 +516,281 @@ class AccountFactoryTest extends TestCase
$account->forceDelete();
}
+ /**
+ * Add valid IBAN.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testCreateIban(): void
+ {
+ 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 = [
+ 'account_type_id' => null,
+ 'account_type' => 'asset',
+ 'iban' => 'NL02ABNA0870809585',
+ 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
+ 'virtual_balance' => null,
+ 'active' => true,
+ '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(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
+ //$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
+ $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
+
+ /** @var AccountFactory $factory */
+ $factory = app(AccountFactory::class);
+ $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('NL02ABNA0870809585', $account->iban);
+ $this->assertTrue($account->active);
+ $this->assertEquals('0', $account->virtual_balance);
+
+ $account->forceDelete();
+ }
+
+ /**
+ * Add invalid IBAN.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testCreateInvalidIban(): void
+ {
+ 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 = [
+ 'account_type_id' => null,
+ 'account_type' => 'asset',
+ 'iban' => 'NL1XRABO032674X238',
+ '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', '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();
+
+ $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);
+
+ }
+
+ /**
+ * Submit IB data for asset account.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testCreateNegativeIB(): void
+ {
+ 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 = [
+ '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,
+ ];
+
+ 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(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
+ $currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->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);
+
+ $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.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testCreateNotes(): void
+ {
+ 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 = [
+ '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',
+ 'notes' => 'Hello!',
+ ];
+
+ $euro = $this->getEuro();
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);
+
+ /** @var AccountFactory $factory */
+ $factory = app(AccountFactory::class);
+ $factory->setUser($this->user());
+
+ // 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();
+
+ 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);
+
+ $note = $account->notes()->first();
+ $this->assertEquals('Hello!', $note->text);
+ }
+
/**
* Submit valid opening balance data for asset account.
*
@@ -376,12 +823,16 @@ class AccountFactoryTest extends TestCase
$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);
+ $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);
$factory->setUser($this->user());
@@ -411,7 +862,7 @@ class AccountFactoryTest extends TestCase
public function testCreateOBZero(): void
{
// mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
@@ -433,180 +884,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(), '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());
+ $langPreference = new Preference;
+ $langPreference->data = 'en_US';
+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($langPreference);
- 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);
-
- $account->forceDelete();
- }
-
- /**
- * Add valid IBAN.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testCreateIban(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $this->mock(TransactionGroupFactory::class);
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => 'NL02ABNA0870809585',
- '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', '1'])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
- $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $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('NL02ABNA0870809585', $account->iban);
- $this->assertTrue($account->active);
- $this->assertEquals('0', $account->virtual_balance);
-
- $account->forceDelete();
- }
-
- /**
- * Add invalid IBAN.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testCreateInvalidIban(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $this->mock(TransactionGroupFactory::class);
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => 'NL1XRABO032674X238',
- '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', '1'])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
- $metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
- $currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $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);
-
- }
-
- /**
- * Submit IB data for asset account.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testCreateNegativeIB(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $groupFactory = $this->mock(TransactionGroupFactory::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- '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', '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);
-
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@@ -620,6 +906,68 @@ class AccountFactoryTest extends TestCase
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);
+
+ $account->forceDelete();
+ }
+
+ /**
+ * 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 testCreateWithNumbers(): void
+ {
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $metaFactory = $this->mock(AccountMetaFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+ $this->mock(TransactionGroupFactory::class);
+ $euro = $this->getEuro();
+ $data = [
+ 'account_type_id' => null,
+ 'account_type' => 'asset',
+ '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->name, $data['name']);
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
@@ -630,243 +978,6 @@ class AccountFactoryTest extends TestCase
$account->forceDelete();
}
- /**
- * Add some notes to asset account.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testCreateNotes(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $metaFactory = $this->mock(AccountMetaFactory::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $this->mock(TransactionGroupFactory::class);
- $data = [
- 'account_type_id' => null,
- 'account_type' => 'asset',
- 'iban' => null,
- 'name' => sprintf('Basic asset account #%d', $this->randomInt()),
- 'virtual_balance' => null,
- 'active' => true,
- 'account_role' => 'defaultAsset',
- 'notes' => 'Hello!',
- ];
-
- /** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
- $factory->setUser($this->user());
-
- // 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();
-
- 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);
-
- $note = $account->notes()->first();
- $this->assertEquals('Hello!', $note->text);
- }
-
- /**
- * Test minimal set of data to make factory work (asset account).
- *
- * @covers \FireflyIII\Factory\AccountFactory
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- 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);
-
- /** @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);
- $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',
- ];
-
- // 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);
-
- /** @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);
-
- }
-
- /**
- * Should return existing account.
- *
- * @covers \FireflyIII\Factory\AccountFactory
- */
- public function testCreateExisting(): void
- {
- $this->mock(AccountRepositoryInterface::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',
- ];
-
-
- /** @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->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',
- ];
-
- /** @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());
- }
- }
-
/**
* @covers \FireflyIII\Factory\AccountFactory
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
@@ -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.php
index 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.php
index 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',
],
],
@@ -275,6 +302,110 @@ class RecurrenceFactoryTest extends TestCase
$this->assertEquals($result->title, $data['recurrence']['title']);
}
+ /**
+ * Deposit. With piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testCreateDeposit(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $source = $this->getRandomRevenue();
+ $destination = $this->getRandomAsset();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category = $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $accountFactory = $this->mock(AccountFactory::class);
+ $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);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $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:
+ $validator->shouldReceive('setUser')->once();
+ $validator->shouldReceive('setTransactionType')->atLeast()->once();
+ $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
+ $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'deposit',
+ 'first_date' => Carbon::now()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . $this->randomInt(),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ '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));
+
+ /** @var RecurrenceFactory $factory */
+ $factory = app(RecurrenceFactory::class);
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
/**
* With piggy bank. With tags. With budget. With category.
* Submit account names, not types. Also a withdrawal
@@ -346,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',
@@ -376,6 +502,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',
],
],
@@ -389,113 +518,6 @@ class RecurrenceFactoryTest extends TestCase
$this->assertEquals($result->title, $data['recurrence']['title']);
}
-
- /**
- * Deposit. With piggy bank. With tags. With budget. With category.
- *
- * @covers \FireflyIII\Factory\RecurrenceFactory
- * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
- */
- public function testCreateDeposit(): void
- {
- // objects to return:
- $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
- $source = $this->getRandomRevenue();
- $destination = $this->getRandomAsset();
- $budget = $this->user()->budgets()->inRandomOrder()->first();
- $category = $this->user()->categories()->inRandomOrder()->first();
-
- // mock other factories:
- $piggyFactory = $this->mock(PiggyBankFactory::class);
- $budgetFactory = $this->mock(BudgetFactory::class);
- $categoryFactory = $this->mock(CategoryFactory::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
- $typeFactory = $this->mock(TransactionTypeFactory::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $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);
-
- $accountRepos->shouldReceive('setUser')->twice();
- $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:
- $validator->shouldReceive('setUser')->once();
- $validator->shouldReceive('setTransactionType')->atLeast()->once();
- $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
- $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
-
- // data for basic recurrence.
- $data = [
- 'recurrence' => [
- 'type' => 'deposit',
- 'first_date' => Carbon::now()->addDay(),
- 'repetitions' => 0,
- 'title' => 'Test recurrence' . $this->randomInt(),
- 'description' => 'Description thing',
- 'apply_rules' => true,
- 'active' => true,
- 'repeat_until' => null,
- ],
- 'meta' => [
- 'tags' => ['a', 'b', 'c'],
- 'piggy_bank_id' => 1,
- 'piggy_bank_name' => 'Bla bla',
- ],
- 'repetitions' => [
- [
- 'type' => 'daily',
- 'moment' => '',
- 'skip' => 0,
- 'weekend' => 1,
- ],
- ],
- 'transactions' => [
- [
- 'source_id' => 1,
- 'source_name' => 'Some name',
- 'destination_id' => 2,
- 'destination_name' => 'some otjer name',
- 'currency_id' => 1,
- 'currency_code' => 'EUR',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'description' => 'Bla bla bla',
- 'amount' => '100',
- 'budget_id' => 1,
- 'budget_name' => 'Some budget',
- 'category_id' => 2,
- 'category_name' => 'Some category',
-
- ],
- ],
- ];
-
-
- $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(2));
-
- /** @var RecurrenceFactory $factory */
- $factory = app(RecurrenceFactory::class);
- $factory->setUser($this->user());
-
- $result = $factory->create($data);
- $this->assertEquals($result->title, $data['recurrence']['title']);
- }
-
/**
* No piggy bank. With tags. With budget. With category. Withdrawal.
*
@@ -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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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 TestCase
public 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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.php
index 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 TestCase
Preferences::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']);
@@ -129,6 +131,360 @@ class ImportArrayStorageTest extends TestCase
}
}
+ /**
+ * Same as testBasic but submits the minimum amount of data required to store a transaction.
+ *
+ * @covers \FireflyIII\Import\Storage\ImportArrayStorage
+ *
+ */
+ public function testSimple(): void
+ {
+ Event::fake();
+ Log::info(sprintf('Now in test %s', __METHOD__));
+ // data to submit:
+ $transactions = [
+ $this->singleImportWithdrawal(),
+ ];
+
+ // data that is returned:
+ $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);
+ $tagRepos = $this->mock(TagRepositoryInterface::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();
+
+
+ // make fake job
+ $job = new ImportJob;
+ $job->user()->associate($this->user());
+ $job->key = 'a_storage' . $this->randomInt();
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->transactions = [];
+ $job->save();
+
+
+ // mock user calls
+ $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();
+
+ // 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']);
+
+ // 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);
+
+ // fake the event.
+
+ $storage = new ImportArrayStorage;
+ $storage->setImportJob($job);
+ try {
+ $storage->store();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * 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 testSimpleApplyNoRules(): void
+ {
+ Event::fake();
+ Log::info(sprintf('Now in test %s', __METHOD__));
+ // data to submit:
+ $transactions = [
+ $this->singleImportWithdrawal(),
+ ];
+
+ // data that is returned:
+ $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);
+ $transformer = $this->mock(TransactionGroupTransformer::class);
+
+ $this->mock(Processor::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();
+
+
+ // make fake job
+ $job = new ImportJob;
+ $job->user()->associate($this->user());
+ $job->key = 'a_storage' . $this->randomInt();
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'apply-rules' => true,
+ ];
+ $job->transactions = [];
+ $job->save();
+
+
+ // mock user calls
+ $repository->shouldReceive('setUser')->atLeast()->once();
+ $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();
+
+ // 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);
+ $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);
+
+ $storage = new ImportArrayStorage;
+ $storage->setImportJob($job);
+ try {
+ $storage->store();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * 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 testSimpleApplyOneRules(): void
+ {
+ Event::fake();
+ Log::info(sprintf('Now in test %s', __METHOD__));
+ // data to submit:
+ $transactions = [
+ $this->singleImportWithdrawal(),
+ ];
+
+ // data that is returned:
+ $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);
+ $processor = $this->mock(Processor::class);
+ $transformer = $this->mock(TransactionGroupTransformer::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();
+
+
+ // make fake job
+ $job = new ImportJob;
+ $job->user()->associate($this->user());
+ $job->key = 'a_storage' . $this->randomInt();
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'apply-rules' => true,
+ ];
+ $job->transactions = [];
+ $job->save();
+
+
+ // mock user calls
+ $repository->shouldReceive('setUser')->atLeast()->once();
+ $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();
+
+ // 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);
+ $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();
+
+ $storage = new ImportArrayStorage;
+ $storage->setImportJob($job);
+ try {
+ $storage->store();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * 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 testSimpleDuplicate(): void
+ {
+ Event::fake();
+ Log::info(sprintf('Now in test %s', __METHOD__));
+ // data to submit:
+ $transactions = [
+ $this->singleImportWithdrawal(),
+ ];
+
+ // mock stuff
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $groupRepos = $this->mock(TransactionGroupRepositoryInterface::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;
+ $job->user()->associate($this->user());
+ $job->key = 'a_storage' . $this->randomInt();
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->transactions = [];
+ $job->save();
+
+
+ // mock user calls
+ $repository->shouldReceive('setUser')->atLeast()->once();
+ $journalRepos->shouldReceive('setUser')->atLeast()->once();
+ $groupRepos->shouldReceive('setUser')->atLeast()->once();
+
+ // mock other calls.
+ $repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);
+ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
+
+ // 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']);
+
+ // calls to validate and import transactions:
+ $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturn($meta);
+
+ // errors because of duplicate:
+ $repository->shouldReceive('addErrorMessage')->atLeast()->once()
+ ->withArgs([Mockery::any(), 'Row #0 ("") could not be imported. It already exists.']);
+
+
+ $storage = new ImportArrayStorage;
+ $storage->setImportJob($job);
+ try {
+ $storage->store();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
/**
* Submit a transfer. Mark it as not duplicate.
*
@@ -137,7 +493,8 @@ class ImportArrayStorageTest extends TestCase
*/
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(),
@@ -155,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);
@@ -187,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']);
@@ -228,7 +585,8 @@ class ImportArrayStorageTest extends TestCase
*/
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(),
@@ -249,6 +607,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);
@@ -281,7 +640,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']);
@@ -314,6 +672,126 @@ 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.
+ *
+ * @covers \FireflyIII\Import\Storage\ImportArrayStorage
+ *
+ */
+ public function testTransferNotDuplicateAccounts(): void
+ {
+ 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.
+ $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);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $transformer = $this->mock(TransactionGroupTransformer::class);
+ $this->mock(TagRepositoryInterface::class);
+ $this->mock(Processor::class);
+ $this->mock(RuleRepositoryInterface::class);
+
+ Amount::shouldReceive('something');
+
+ $language = new Preference;
+ $language->data = 'en_US';
+ Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
+
+
+ // make fake job
+ $job = new ImportJob;
+ $job->user()->associate($this->user());
+ $job->key = 'a_storage' . $this->randomInt();
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->transactions = [];
+ $job->save();
+
+
+ // mock user calls
+ $repository->shouldReceive('setUser')->atLeast()->once();
+ $journalRepos->shouldReceive('setUser')->atLeast()->once();
+ $groupRepos->shouldReceive('setUser')->atLeast()->once();
+
+ // mock other calls.
+ $repository->shouldReceive('getTransactions')->atLeast()->once()->andReturn($transactions);
+ Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
+
+ // 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']);
+
+ // calls to validate and import transactions:
+ $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturnNull();
+
+ // 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;
+ $storage->setImportJob($job);
+ try {
+ $storage->store();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
/**
* Submit a transfer, and the amounts match, but the rest doesn't.
*
@@ -322,7 +800,8 @@ class ImportArrayStorageTest extends TestCase
*/
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->singleImportTransfer(),
@@ -339,15 +818,17 @@ class ImportArrayStorageTest extends TestCase
//$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';
+ $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();
}
- if ($t->amount > 0) {
- $t->amount = '56.78';
- }
- $t->save();
- });
+ );
$transferGroup->refresh();
// mock stuff
@@ -357,6 +838,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);
@@ -389,118 +871,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']);
- $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']);
-
- // 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]);
-
-
- $storage = new ImportArrayStorage;
- $storage->setImportJob($job);
- try {
- $storage->store();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Submit a transfer, and the amounts match, and the description matches, but the rest doesn't
- *
- * @covers \FireflyIII\Import\Storage\ImportArrayStorage
- *
- */
- public function testTransferNotDuplicateDescr(): void
- {
- Log::debug(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'];
-
-
- //$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(Processor::class);
- $this->mock(RuleRepositoryInterface::class);
-
- Amount::shouldReceive('something');
-
- $language = new Preference;
- $language->data = 'en_US';
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
-
-
- // make fake job
- $job = new ImportJob;
- $job->user()->associate($this->user());
- $job->key = 'a_storage' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->transactions = [];
- $job->save();
-
-
- // mock user calls
- $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']);
@@ -542,7 +912,8 @@ class ImportArrayStorageTest extends TestCase
*/
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->singleImportTransfer(),
@@ -563,15 +934,17 @@ class ImportArrayStorageTest extends TestCase
//$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';
+ $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();
}
- if ($t->amount > 0) {
- $t->amount = '56.78';
- }
- $t->save();
- });
+ );
$transferGroup->refresh();
// mock stuff
@@ -581,6 +954,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 +987,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']);
@@ -646,17 +1019,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 the amounts match, and the description matches, but the rest doesn't
*
* @covers \FireflyIII\Import\Storage\ImportArrayStorage
*
*/
- public function testTransferNotDuplicateAccounts(): 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->singleImportTransfer(),
@@ -668,28 +1040,25 @@ class ImportArrayStorageTest extends TestCase
$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';
+ $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';
+ $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();
}
- if ($t->amount > 0) {
- $t->amount = '56.78';
- }
- $t->save();
- });
+ );
$transferGroup->refresh();
// mock stuff
@@ -697,8 +1066,9 @@ class ImportArrayStorageTest extends TestCase
$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 +1096,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 +1110,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,405 +1133,6 @@ class ImportArrayStorageTest extends TestCase
}
}
-
- /**
- * Same as testBasic but submits the minimum amount of data required to store a transaction.
- * @covers \FireflyIII\Import\Storage\ImportArrayStorage
- *
- */
- public function testSimple(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- // data to submit:
- $transactions = [
- $this->singleImportWithdrawal(),
- ];
-
- // data that is returned:
- $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);
- $tagRepos = $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();
-
-
- // make fake job
- $job = new ImportJob;
- $job->user()->associate($this->user());
- $job->key = 'a_storage' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->transactions = [];
- $job->save();
-
-
- // mock user calls
- $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']);
- $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']);
-
- // 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);
-
-
- $storage = new ImportArrayStorage;
- $storage->setImportJob($job);
- try {
- $storage->store();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * 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 testSimpleDuplicate(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- // data to submit:
- $transactions = [
- $this->singleImportWithdrawal(),
- ];
-
- // 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);
- $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;
- $job->user()->associate($this->user());
- $job->key = 'a_storage' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->transactions = [];
- $job->save();
-
-
- // mock user calls
- $repository->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $groupRepos->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']);
-
- // calls to validate and import transactions:
- $journalRepos->shouldReceive('findByHash')->withArgs([Mockery::any()])->atLeast()->once()->andReturn($meta);
-
- // errors because of duplicate:
- $repository->shouldReceive('addErrorMessage')->atLeast()->once()
- ->withArgs([Mockery::any(), 'Row #0 ("") could not be imported. It already exists.']);
-
-
- $storage = new ImportArrayStorage;
- $storage->setImportJob($job);
- try {
- $storage->store();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * 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 testSimpleApplyNoRules(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- // data to submit:
- $transactions = [
- $this->singleImportWithdrawal(),
- ];
-
- // data that is returned:
- $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);
-
- $this->mock(Processor::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();
-
-
- // make fake job
- $job = new ImportJob;
- $job->user()->associate($this->user());
- $job->key = 'a_storage' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'apply-rules' => true,
- ];
- $job->transactions = [];
- $job->save();
-
-
- // mock user calls
- $repository->shouldReceive('setUser')->atLeast()->once();
- $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);
- $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);
-
- $storage = new ImportArrayStorage;
- $storage->setImportJob($job);
- try {
- $storage->store();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
-
- /**
- * 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 testSimpleApplyOneRules(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- // data to submit:
- $transactions = [
- $this->singleImportWithdrawal(),
- ];
-
- // data that is returned:
- $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);
- $processor = $this->mock(Processor::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();
-
-
- // make fake job
- $job = new ImportJob;
- $job->user()->associate($this->user());
- $job->key = 'a_storage' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'apply-rules' => true,
- ];
- $job->transactions = [];
- $job->save();
-
-
- // mock user calls
- $repository->shouldReceive('setUser')->atLeast()->once();
- $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);
- $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();
-
- $storage = new ImportArrayStorage;
- $storage->setImportJob($job);
- try {
- $storage->store();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @return array
- */
- private function singleImportWithdrawal(): array
- {
- return
- [
- 'type' => 'withdrawal',
- 'tags' => '',
- 'user' => $this->user()->id,
-
- // all custom fields:
- 'internal_reference' => null,
- 'notes' => null,
-
- // journal data:
- 'description' => 'Some TEST withdrawal #1',
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
-
- // transaction data:
- 'transactions' => [
- [
- 'date' => '2019-01-01',
- 'type' => 'withdrawal',
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'description' => null,
- 'amount' => '12.34',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => null,
- 'source_id' => null,
- 'source_name' => 'Checking Account',
- 'destination_id' => null,
- 'destination_name' => 'Random TEST expense account #2',
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ];
- }
-
/**
* @return array
*/
@@ -1209,4 +1181,53 @@ class ImportArrayStorageTest extends TestCase
],
];
}
+
+ /**
+ * @return array
+ */
+ private function singleImportWithdrawal(): array
+ {
+ return
+ [
+ 'type' => 'withdrawal',
+ 'tags' => '',
+ 'user' => $this->user()->id,
+
+ // all custom fields:
+ 'internal_reference' => null,
+ 'notes' => null,
+
+ // journal data:
+ 'description' => 'Some TEST withdrawal #1',
+ 'piggy_bank_id' => null,
+ 'piggy_bank_name' => null,
+ 'bill_id' => null,
+ 'bill_name' => null,
+
+ // transaction data:
+ 'transactions' => [
+ [
+ 'date' => '2019-01-01',
+ 'type' => 'withdrawal',
+ 'currency_id' => null,
+ 'currency_code' => 'EUR',
+ 'description' => null,
+ 'amount' => '12.34',
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ 'source_id' => null,
+ 'source_name' => 'Checking Account',
+ 'destination_id' => null,
+ 'destination_name' => 'Random TEST expense account #2',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'reconciled' => false,
+ 'identifier' => 0,
+ ],
+ ],
+ ];
+ }
}
diff --git a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php b/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
index 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,392 +55,6 @@ class CreateRecurringTransactionsTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this)));
}
- /**
- * Submit nothing.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testBasic(): void
- {
- // mock classes
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $this->mock(JournalRepositoryInterface::class);
- $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
- $job->setForce(false);
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(0, $job->submitted);
-
- }
-
- /**
- * Submit one, but offer no occurrences.
- *
- * TODO there is a random element in this test that breaks the test.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingle(): void
- {
- Log::info(sprintf('Now in test %s.', __METHOD__));
- // mock classes
- $date = new Carbon;
- $date->subDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = null;
- $recurrence->first_date = $date;
- $recurrence->save();
-
- Log::debug(sprintf('Test is going to use Recurrence #%d', $recurrence->id), $recurrence->toArray());
-
- $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
-
- // mocks:
- $groupRepos->shouldReceive('setUser')->atLeast()->once();
- $journalRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('setUser')->atLeast()->once();
- $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
- $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
- $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(1, $job->executed);
- $this->assertEquals(1, $job->submitted);
- }
-
-
-
- /**
- * Submit one, but has already fired today
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleFiredToday(): void
- {
- // mock classes
- $recurrence = $this->getRandomRecurrence();
- $recurrence->latest_date = new Carbon;
- $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();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
- $recurrence->latest_date =null;
- $recurrence->save();
- }
-
-
- /**
- * Submit one, but offer no occurrences.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleFuture(): void
- {
- // mock classes
- $future = new Carbon;
- $future->addDays(4);
- $recurrence = $this->getRandomRecurrence();
- $recurrence->first_date =$future;
- $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();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->first_date =$date;
- $recurrence->save();
- }
-
-
- /**
- * Submit one, but should no longer run.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleOverDue(): void
- {
- // mock classes
- $date = new Carbon();
- $yesterday = clone $date;
- $yesterday->subDays(3);
- $recurrence = $this->getRandomRecurrence();
-
- $recurrence->repeat_until =$yesterday;
- $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);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->repeat_until =null;
- $recurrence->save();
- }
-
-
- /**
- * Submit one, but it has fired enough times already.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleOccurrences(): void
- {
- // mock classes
- $recurrence = $this->getRandomRecurrence();
- $recurrence->repetitions = 1;
- $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(1);
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->repetitions = 0;
- $recurrence->save();
- }
-
- /**
- * Submit one, but it's inactive.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleInactive(): void
- {
-
- // mock classes
- $recurrence = $this->getRandomRecurrence();
-
- $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]));
- Preferences::shouldReceive('mark')->atLeast()->once();
-
-
- $date = new Carbon();
- $job = new CreateRecurringTransactions($date);
-
- $job->handle();
-
- $this->assertEquals(0, $job->created);
- $this->assertEquals(0, $job->executed);
- $this->assertEquals(1, $job->submitted);
-
- $recurrence->active = true;
- $recurrence->save();
- }
-
-
- /**
- * Submit one, offer occurence for today.
- *
- * @covers \FireflyIII\Jobs\CreateRecurringTransactions
- */
- public function testSingleToday(): void
- {
- Event::fake();
- $date = new Carbon();
- $this->expectsEvents([StoredTransactionGroup::class]);
-
- // mock classes
- $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(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(1, $job->submitted);
- }
-
-
- /**
- * 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, offer occurence for today.
*
@@ -483,12 +98,260 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(1, $job->submitted);
}
+ /**
+ * Submit nothing.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testBasic(): void
+ {
+ // mock classes
+ $recurringRepos = $this->mock(RecurringRepositoryInterface::class);
+ $this->mock(JournalRepositoryInterface::class);
+ $this->mock(TransactionGroupRepositoryInterface::class);
+
+ // mocks:
+ $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+ $job->setForce(false);
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(0, $job->executed);
+ $this->assertEquals(0, $job->submitted);
+
+ }
+
+ /**
+ * 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.
+ *
+ * TODO there is a random element in this test that breaks the test.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testSingle(): void
+ {
+ Event::fake();
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ // mock classes
+ $date = new Carbon;
+ $date->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->latest_date = null;
+ $recurrence->first_date = $date;
+ $recurrence->save();
+
+ Log::debug(sprintf('Test is going to use Recurrence #%d', $recurrence->id), $recurrence->toArray());
+
+ $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();
+ $journalRepos->shouldReceive('setUser')->atLeast()->once();
+ $recurringRepos->shouldReceive('setUser')->atLeast()->once();
+ $recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
+ $recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
+ $recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(1, $job->executed);
+ $this->assertEquals(1, $job->submitted);
+ }
+
+ /**
+ * Submit one, but has already fired today
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testSingleFiredToday(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ // mock classes
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->latest_date = new Carbon;
+ $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();
+
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(0, $job->executed);
+ $this->assertEquals(1, $job->submitted);
+ $recurrence->latest_date = null;
+ $recurrence->save();
+ }
+
+ /**
+ * Submit one, but offer no occurrences.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ 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->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();
+
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(0, $job->executed);
+ $this->assertEquals(1, $job->submitted);
+
+ $recurrence->first_date = $date;
+ $recurrence->save();
+ }
+
+ /**
+ * Submit one, but it's inactive.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testSingleInactive(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ // mock classes
+ $recurrence = $this->getRandomRecurrence();
+
+ $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]));
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(0, $job->executed);
+ $this->assertEquals(1, $job->submitted);
+
+ $recurrence->active = true;
+ $recurrence->save();
+ }
+
/**
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleNotToday(): void
{
- $date = new Carbon();
+ Event::fake();
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ $date = new Carbon();
$tomorrow = new Carbon();
$tomorrow->addDays(2);
@@ -526,6 +389,143 @@ class CreateRecurringTransactionsTest extends TestCase
}
+ /**
+ * Submit one, but it has fired enough times already.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testSingleOccurrences(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ // mock classes
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->repetitions = 1;
+ $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(1);
+ Preferences::shouldReceive('mark')->atLeast()->once();
+
+
+ $date = new Carbon();
+ $job = new CreateRecurringTransactions($date);
+
+ $job->handle();
+
+ $this->assertEquals(0, $job->created);
+ $this->assertEquals(0, $job->executed);
+ $this->assertEquals(1, $job->submitted);
+
+ $recurrence->repetitions = 0;
+ $recurrence->save();
+ }
+
+ /**
+ * Submit one, but should no longer run.
+ *
+ * @covers \FireflyIII\Jobs\CreateRecurringTransactions
+ */
+ public function testSingleOverDue(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ // mock classes
+ $date = new Carbon();
+ $yesterday = clone $date;
+ $yesterday->subDays(3);
+ $recurrence = $this->getRandomRecurrence();
+
+ $recurrence->repeat_until = $yesterday;
+ $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);
+
+ $job->handle();
+
+ $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 testSingleToday(): void
+ {
+ Event::fake();
+ $date = new Carbon();
+ $this->expectsEvents([StoredTransactionGroup::class]);
+
+ // mock classes
+ $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(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(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.php
index 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();
@@ -380,28 +438,13 @@ class BinderTest extends TestCase
$response->assertSee('count: 3');
}
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\BudgetList
- */
- public function testBudgetListInvalid(): void
- {
- 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');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\BudgetList
*/
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();
@@ -412,12 +455,65 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Support\Binder\BudgetList
+ */
+ 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/-1');
+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Models\Budget
+ */
+ public function testBudgetNotFound(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ Route::middleware(Binder::class)->any(
+ '/_test/binder/{budget}', 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\Budget
+ */
+ public function testBudgetNotLoggedIn(): void
+ {
+ Log::info(sprintf('Now in test %s.', __METHOD__));
+ Route::middleware(Binder::class)->any(
+ '/_test/binder/{budget}', 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\CLIToken
*/
public function testCLIToken(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
$repos = $this->mock(UserRepositoryInterface::class);
$repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
@@ -444,6 +540,7 @@ class BinderTest extends TestCase
*/
public function testCLITokenNotFound(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
$repos = $this->mock(UserRepositoryInterface::class);
$repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
@@ -462,196 +559,13 @@ 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
- {
- 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
- {
- 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());
- }
-
- /**
- * 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
- */
- public function testImportProviderFake(): 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());
- }
-
- /**
- * 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);
-
- $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/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);
- }
- );
-
- $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
- */
- public function testImportProviderNotLoggedIn(): 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());
- }
-
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Budget
- */
- public function testBudgetNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budget}', 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\Budget
- */
- public function testBudgetNotLoggedIn(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{budget}', function () {
- return 'OK';
- }
- );
-
- $response = $this->get('/_test/binder/1');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Category
*/
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';
@@ -1036,17 +1003,196 @@ class BinderTest extends TestCase
$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
+ {
+ 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/{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');
+ }
+
+ /**
+ * Nobody can access "bad" import routine.
+ *
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Support\Binder\ImportProvider
+ */
+ 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/{import_provider}', static function (string $name) {
+ return sprintf('import_provider: %s', $name);
+ }
+ );
+
+ $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
+ {
+ 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/{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_NOT_FOUND, $response->getStatusCode());
+ }
+
+ /**
+ * Normal user cannot access fake import routine.
+ *
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Support\Binder\ImportProvider
+ */
+ 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/{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());
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Support\Binder\ImportProvider
+ */
+ 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/{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());
+ }
+
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\JournalList
*/
public function testJournalList(): 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);
}
);
+ $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);
+
$this->be($this->user());
$withdrawal = $this->getRandomWithdrawal();
$deposit = $this->getRandomDeposit();
@@ -1061,10 +1207,22 @@ class BinderTest extends TestCase
*/
public function testJournalListEmpty(): 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);
- });
+ }
+ );
+
+ $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');
@@ -1079,10 +1237,12 @@ class BinderTest extends TestCase
*/
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());
@@ -1094,6 +1254,7 @@ class BinderTest extends TestCase
*/
public function testLinkType(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
@@ -1111,6 +1272,7 @@ class BinderTest extends TestCase
*/
public function testLinkTypeNotFound(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
@@ -1128,6 +1290,7 @@ class BinderTest extends TestCase
*/
public function testLinkTypeNotLoggedIn(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
@@ -1144,6 +1307,7 @@ class BinderTest extends TestCase
*/
public function testPiggyBank(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
@@ -1155,147 +1319,13 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Preference
- */
- public function testPreference(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{preference}', static function (?Preference $preference) {
- return $preference->name ?? 'unknown';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/frontPageAccounts');
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
- $response->assertSee('frontPageAccounts');
- }
-
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\Recurrence
- */
- public function testRecurrence(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
- return $recurrence->description ?? 'unknown';
- }
- );
- $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\Recurrence
- */
- public function testRecurrenceNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
- return $recurrence->description ?? 'unknown';
- }
- );
- $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\TransactionGroup
- */
- public function testTransactionGroup(): void
- {
- Route::middleware(Binder::class)->any(
- '/_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());
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\TransactionGroup
- */
- public function testTransactionGroupNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_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_NOT_FOUND, $response->getStatusCode());
- }
-
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Models\AvailableBudget
- */
- public function testAvailableBudget(): void
- {
- 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
- {
- 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\Preference
- */
- public function testPreferenceNotFound(): void
- {
- Route::middleware(Binder::class)->any(
- '/_test/binder/{preference}', static function (?Preference $preference) {
- return $preference->name ?? 'unknown';
- }
- );
-
- $this->be($this->user());
- $response = $this->get('/_test/binder/frontPageAccountsX');
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\PiggyBank
*/
public function testPiggyBankNotFound(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
@@ -1313,6 +1343,7 @@ class BinderTest extends TestCase
*/
public function testPiggyBankNotLoggedIn(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
@@ -1323,12 +1354,84 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Models\Preference
+ */
+ public function testPreference(): 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';
+ }
+ );
+
+ $this->be($this->user());
+ $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';
+ }
+ );
+
+ $this->be($this->user());
+ $response = $this->get('/_test/binder/frontPageAccountsX');
+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Models\Recurrence
+ */
+ public function testRecurrence(): 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';
+ }
+ );
+ $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\Recurrence
+ */
+ public function testRecurrenceNotFound(): 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';
+ }
+ );
+ $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\Rule
*/
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
@@ -1542,6 +1673,97 @@ class BinderTest extends TestCase
$response->assertSee('count: 2');
}
+ /**
+ * @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 testTagOrIdBothNull(): 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();
+
+ Route::middleware(Binder::class)->any(
+ '/_test/binder/{tagOrId}', static function (?Tag $tag) {
+ if ($tag) {
+ return $tag->tag;
+ }
+
+ return 'unfound';
+ }
+ );
+
+ $this->be($this->user());
+ $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Support\Binder\TagOrId
+ */
+ public function testTagOrIdById(): 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])->andReturn($tag)->atLeast()->once();
+
+ Route::middleware(Binder::class)->any(
+ '/_test/binder/{tagOrId}', static function (?Tag $tag) {
+ if ($tag) {
+ return $tag->tag;
+ }
+
+ return 'unfound';
+ }
+ );
+
+ $this->be($this->user());
+ $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
+ $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
+
+ $response->assertSee($tag->tag);
+ }
+
/**
* TODO there is a random element in this test that breaks the middleware.
*
@@ -1573,64 +1795,6 @@ class BinderTest extends TestCase
$response->assertSee($tag->tag);
}
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdById(): 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])->andReturn($tag)->atLeast()->once();
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
-
- $response->assertSee($tag->tag);
- }
-
- /**
- * @covers \FireflyIII\Http\Middleware\Binder
- * @covers \FireflyIII\Support\Binder\TagOrId
- */
- public function testTagOrIdBothNull(): 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();
-
- Route::middleware(Binder::class)->any(
- '/_test/binder/{tagOrId}', static function (?Tag $tag) {
- if ($tag) {
- return $tag->tag;
- }
-
- return 'unfound';
- }
- );
-
- $this->be($this->user());
- $response = $this->get(sprintf('/_test/binder/%d', $tag->id));
- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
- }
-
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
@@ -1651,59 +1815,6 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
- /**
- * @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\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\Models\TransactionCurrency
@@ -1754,6 +1865,38 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Models\TransactionGroup
+ */
+ public function testTransactionGroup(): void
+ {
+ Route::middleware(Binder::class)->any(
+ '/_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());
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Middleware\Binder
+ * @covers \FireflyIII\Models\TransactionGroup
+ */
+ public function testTransactionGroupNotFound(): void
+ {
+ Route::middleware(Binder::class)->any(
+ '/_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_NOT_FOUND, $response->getStatusCode());
+ }
+
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournalLink
diff --git a/tests/Unit/Middleware/IsDemoUserTest.php b/tests/Unit/Middleware/IsDemoUserTest.php
index 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.php
index 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.php
index 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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.php
index 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.php
index 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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.php
index 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 TestCase
public function testConfigurationCompleteBasic(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
+ $helper = $this->mock(AttachmentHelperInterface::class);
$config = [
'column-count' => 5,
@@ -84,6 +84,7 @@ class ConfigureRolesHandlerTest extends TestCase
public function testConfigurationCompleteForeign(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
+ $helper = $this->mock(AttachmentHelperInterface::class);
$config = [
'column-count' => 5,
@@ -110,6 +111,7 @@ class ConfigureRolesHandlerTest extends TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public 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 TestCase
public function testMakeExamplesUnique(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
+ $helper = $this->mock(AttachmentHelperInterface::class);
$lines = [
['one', 'two', '', 'three'],
@@ -521,6 +531,7 @@ class ConfigureRolesHandlerTest extends TestCase
public 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.php
index 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.php
index 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.php
index 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,
- ];
+ $income = $this->categorySumIncome();
+ $expense = $this->categorySumExpenses();
+ $opsRepository->shouldReceive('sumIncome')
+ ->atLeast()->once()->andReturn($income);
-
- $incomeCollection = [$income];
- $expenseCollection = [$expense];
-
- $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.php
index 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 TestCase
public 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.php
index 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);