Improve test coverage.

This commit is contained in:
James Cole
2019-08-29 17:53:25 +02:00
parent 91b6b86202
commit 19feefda2d
86 changed files with 3173 additions and 2626 deletions

View File

@@ -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,

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Log;
/**
* Class BackToJournals
@@ -110,8 +111,10 @@ class BackToJournals extends Command
foreach ($chunks as $chunk) {
$set = DB::table('transactions')
->whereIn('transactions.id', $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();
Log::debug(sprintf('Total: %d', count($allIds)));
$chunks = array_chunk($allIds, 500);
foreach ($chunks as $journalIds) {
$collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'categories', 'transactions.categories'])->get();
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)));

View File

@@ -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':

View File

@@ -96,7 +96,6 @@ class RecurrenceFactory
);
$recurrence->save();
//$this->updateMetaData($recurrence, $data);
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
try {
$this->createTransactions($recurrence, $data['transactions'] ?? []);

View File

@@ -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',

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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.');

View File

@@ -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',

View File

@@ -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.');

View File

@@ -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');

View File

@@ -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.',
],
],

View File

@@ -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"');

View File

@@ -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.

View File

@@ -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);

View File

@@ -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'));

View File

@@ -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([]);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -162,47 +162,5 @@ class IndexControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
*/
public function testShow(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$this->mockDefaultSession();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' => null,
'latest_date' => null,
'recurrence_repetitions' => [
[
'occurrences' => [
'2019-01-01',
],
],
],
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* ShowControllerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Recurring;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
use Mockery;
/**
*
* Class ShowControllerTest
*/
class ShowControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
*/
public function testShow(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$this->mockDefaultSession();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' => null,
'latest_date' => null,
'repetitions' => [
[
'occurrences' => [
'2019-01-01',
],
],
],
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -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);

View File

@@ -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;
/**
*
*/
@@ -59,9 +63,14 @@ class CategoryControllerTest extends TestCase
$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');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -87,9 +96,16 @@ class CategoryControllerTest extends TestCase
];
$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);
@@ -108,11 +124,20 @@ class CategoryControllerTest extends TestCase
{
$this->mockDefaultSession();
$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]));

View File

@@ -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']));

View File

@@ -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();

View File

@@ -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',

View File

@@ -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);

View File

@@ -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');

View File

@@ -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:
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);
$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();
// first journal:
$journal = $deposit->transactionJournals()->first();
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]));
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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.

View File

@@ -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))

View File

@@ -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);

View File

@@ -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.')

View File

@@ -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);

View File

@@ -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')

View File

@@ -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(
[

View File

@@ -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();

View File

@@ -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).')

View File

@@ -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;

View File

@@ -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).')

View File

@@ -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();

View File

@@ -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')

View File

@@ -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).')

File diff suppressed because it is too large Load Diff

View File

@@ -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));
}

View File

@@ -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.
*
@@ -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',
],
],
@@ -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);
}
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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');

View File

@@ -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();

View File

@@ -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');

View File

@@ -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',

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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]);
}

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,7 @@ use FireflyIII\Jobs\CreateRecurringTransactions;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use Log;
@@ -54,6 +55,49 @@ class CreateRecurringTransactionsTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Submit one, offer occurence for today.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testBadJournalCount(): void
{
Event::fake();
$date = new Carbon();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$carbon = new Carbon;
$carbon->subDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
$recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit nothing.
*
@@ -81,6 +125,70 @@ class CreateRecurringTransactionsTest extends TestCase
}
/**
* Submit one, offer occurence for today.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testForced(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
Event::fake();
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
// overrule some fields in the recurrence.
$carbon = new Carbon;
$carbon->subDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
$recurrence->first_date = $carbon;
$recurrence->save();
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
Preferences::shouldReceive('mark')->atLeast()->once();
// return data:
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
// store journal
$groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
//Event::assertDispatched(StoredTransactionGroup::class);
$job = new CreateRecurringTransactions($date);
$job->setForce(true);
$job->handle();
$this->assertEquals(1, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, but offer no occurrences.
*
@@ -90,6 +198,7 @@ class CreateRecurringTransactionsTest extends TestCase
*/
public function testSingle(): void
{
Event::fake();
Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
$date = new Carbon;
@@ -104,6 +213,7 @@ class CreateRecurringTransactionsTest extends TestCase
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
@@ -125,8 +235,6 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, but has already fired today
*
@@ -134,6 +242,7 @@ class CreateRecurringTransactionsTest extends TestCase
*/
public function testSingleFiredToday(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = new Carbon;
@@ -156,11 +265,10 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->latest_date =null;
$recurrence->latest_date = null;
$recurrence->save();
}
/**
* Submit one, but offer no occurrences.
*
@@ -168,11 +276,12 @@ class CreateRecurringTransactionsTest extends TestCase
*/
public function testSingleFuture(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
$future = new Carbon;
$future->addDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->first_date =$future;
$recurrence->first_date = $future;
$recurrence->save();
@@ -195,38 +304,34 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->first_date =$date;
$recurrence->first_date = $date;
$recurrence->save();
}
/**
* Submit one, but should no longer run.
* Submit one, but it's inactive.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleOverDue(): void
public function testSingleInactive(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
$date = new Carbon();
$yesterday = clone $date;
$yesterday->subDays(3);
$recurrence = $this->getRandomRecurrence();
$recurrence->repeat_until =$yesterday;
$recurrence->active = false;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
@@ -235,10 +340,54 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->repeat_until =null;
$recurrence->active = true;
$recurrence->save();
}
/**
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleNotToday(): void
{
Event::fake();
Log::info(sprintf('Now in test %s.', __METHOD__));
$date = new Carbon();
$tomorrow = new Carbon();
$tomorrow->addDays(2);
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$carbon = new Carbon;
$carbon->subDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
$recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, but it has fired enough times already.
@@ -247,6 +396,7 @@ class CreateRecurringTransactionsTest extends TestCase
*/
public function testSingleOccurrences(): void
{
Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurrence->repetitions = 1;
@@ -276,29 +426,33 @@ class CreateRecurringTransactionsTest extends TestCase
}
/**
* Submit one, but it's inactive.
* Submit one, but should no longer run.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleInactive(): void
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->active = false;
$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();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
@@ -307,11 +461,10 @@ class CreateRecurringTransactionsTest extends TestCase
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->active = true;
$recurrence->repeat_until = null;
$recurrence->save();
}
/**
* Submit one, offer occurence for today.
*
@@ -373,159 +526,6 @@ class CreateRecurringTransactionsTest extends TestCase
$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.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testBadJournalCount(): void
{
Event::fake();
$date = new Carbon();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$carbon = new Carbon;
$carbon->subDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
$recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleNotToday(): void
{
$date = new Carbon();
$tomorrow = new Carbon();
$tomorrow->addDays(2);
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$carbon = new Carbon;
$carbon->subDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
$recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, offer occurence for today, with piggy
*

File diff suppressed because it is too large Load Diff

View File

@@ -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());

View File

@@ -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());

View File

@@ -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]

View File

@@ -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;
@@ -62,6 +64,12 @@ class AccountUpdateServiceTest extends TestCase
$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(

View File

@@ -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;

View File

@@ -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]]);

View File

@@ -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',

View File

@@ -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());
}
/**

View File

@@ -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']
);
}
}

View File

@@ -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);
$ruleGroupTransformer = $this->mock(RuleGroupTransformer::class);
$ruleTransformer = $this->mock(RuleTransformer::class);
$tagTransformer = $this->mock(TagTransformer::class);
$category = $this->getRandomCategory();
$budget = $this->getRandomBudget();
$piggy = $this->getRandomPiggyBank();
$bill = $this->getRandomBill();
$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']);
}

View File

@@ -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);