Improve test coverage.

This commit is contained in:
James Cole
2018-09-02 20:13:25 +02:00
parent 96dd89fbeb
commit de754ca4e0
31 changed files with 861 additions and 385 deletions

View File

@@ -105,10 +105,10 @@ class EditController extends Controller
'times' => (string)trans('firefly.repeat_times'),
];
if (null !== $recurrence->repeat_until) {
$repetitionEnd = 'until_date';
$repetitionEnd = 'until_date'; // @codeCoverageIgnore
}
if ($recurrence->repetitions > 0) {
$repetitionEnd = 'times';
$repetitionEnd = 'times'; // @codeCoverageIgnore
}
$weekendResponses = [

View File

@@ -63,10 +63,12 @@ class AccountController extends Controller
$accountReport = $accountTasker->getAccountReport($accounts, $start, $end);
try {
$result = view('reports.partials.accounts', compact('accountReport'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;

View File

@@ -61,10 +61,12 @@ class BalanceController extends Controller
$balance = $helper->getBalanceReport($accounts, $start, $end);
try {
$result = view('reports.partials.balance', compact('balance'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;

View File

@@ -63,10 +63,12 @@ class BudgetController extends Controller
$budgets = $helper->getBudgetReport($start, $end, $accounts);
try {
$result = view('reports.partials.budgets', compact('budgets'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -103,10 +105,12 @@ class BudgetController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
try {
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;

View File

@@ -67,10 +67,12 @@ class CategoryController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
@@ -107,10 +109,12 @@ class CategoryController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -160,10 +164,12 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.categories', compact('report'))->render();
$cache->store($result);
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
return $result;
}

View File

@@ -107,10 +107,12 @@ class ExpenseController extends Controller
}
try {
$result = view('reports.partials.exp-budgets', compact('together'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::budget: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -170,10 +172,12 @@ class ExpenseController extends Controller
}
try {
$result = view('reports.partials.exp-categories', compact('together'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -220,10 +224,12 @@ class ExpenseController extends Controller
}
try {
$result = view('reports.partials.exp-not-grouped', compact('result'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -271,10 +277,12 @@ class ExpenseController extends Controller
);
try {
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::topExpense: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -320,10 +328,12 @@ class ExpenseController extends Controller
);
try {
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Could not render category::topIncome: %s', $e->getMessage()));
$result = 'An error prevented Firefly III from rendering. Apologies.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;

View File

@@ -81,10 +81,12 @@ class OperationsController extends Controller
$type = 'expense-entry';
try {
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
@@ -114,10 +116,12 @@ class OperationsController extends Controller
$type = 'income-entry';
try {
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
@@ -166,10 +170,12 @@ class OperationsController extends Controller
);
try {
$result = view('reports.partials.operations', compact('incomeSum', 'expensesSum'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.operations: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;

View File

@@ -258,10 +258,13 @@ class CreateController extends Controller
'count' => $index + 1,
]
)->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
Log::debug($e->getTraceAsString());
$string = '';
// @codeCoverageIgnoreEnd
}
if ('' !== $string) {
$result[] = $string;

View File

@@ -49,7 +49,8 @@ class CronController
*/
private function runRecurring(): string
{
$recurring = new RecurringCronjob;
/** @var RecurringCronjob $recurring */
$recurring = app(RecurringCronjob::class);
try {
$result = $recurring->fire();
} catch (FireflyException $e) {

View File

@@ -118,7 +118,7 @@ class RecurrenceFormRequest extends Request
// fill in source and destination account data
switch ($this->string('transaction_type')) {
default:
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type'))); // @codeCoverageIgnore
case 'withdrawal':
$return['transactions'][0]['source_id'] = $this->integer('source_id');
$return['transactions'][0]['destination_name'] = $this->string('destination_name');
@@ -227,8 +227,6 @@ class RecurrenceFormRequest extends Request
$rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,' . $recurrence->id;
$rules['first_date'] = 'required|date';
}
return $rules;
}

View File

@@ -28,9 +28,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollector;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
@@ -46,7 +44,7 @@ class TransactionControllerTest extends TestCase
/**
*
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
@@ -1329,16 +1327,8 @@ class TransactionControllerTest extends TestCase
*/
public function testShowDeposit(): void
{
$loop = 0;
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$transaction = $journal->transactions()->first();
$deposit = $this->getRandomDeposit();
$transaction = $deposit->transactions()->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsByType')
@@ -1350,7 +1340,7 @@ class TransactionControllerTest extends TestCase
$collector->setUser($this->user());
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setJournals(new Collection([$journal]));
$collector->setJournals(new Collection([$deposit]));
$collector->setLimit(5)->setPage(1);
$transactions = $collector->getTransactions();
@@ -1374,7 +1364,7 @@ class TransactionControllerTest extends TestCase
[
'data' => [[
'attributes' => [
'description' => $journal->description,
'description' => $deposit->description,
'type' => 'Deposit',
],
]],
@@ -1393,15 +1383,7 @@ class TransactionControllerTest extends TestCase
*/
public function testShowWithdrawal(): void
{
$loop = 0;
do {
// this is kind of cheating but OK.
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
/** @var Transaction $transaction */
$journal = $this->getRandomWithdrawal();
$transaction = $journal->transactions()->first();
$transaction->description = null;
$transaction->save();
@@ -2441,7 +2423,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
$data = [
$data = [
'description' => 'Some deposit #' . random_int(1, 10000),
'date' => '2018-01-01',
'transactions' => [
@@ -2452,12 +2434,7 @@ class TransactionControllerTest extends TestCase
],
],
];
do {
/** @var TransactionJournal $deposit */
$deposit = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->first();
$count = $deposit->transactions()->count();
} while ($count !== 2);
$deposit = $this->getRandomDeposit();
$transaction = $deposit->transactions()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('update')->andReturn($deposit)->once();
@@ -2494,13 +2471,8 @@ class TransactionControllerTest extends TestCase
],
],
];
do {
/** @var TransactionJournal $withdrawal */
$withdrawal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$count = $withdrawal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
$transaction = $withdrawal->transactions()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('update')->andReturn($withdrawal)->once();

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@@ -74,35 +75,189 @@ class CreateControllerTest extends TestCase
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$recurrence = $this->user()->recurrences()->first();
$data = [
'title' => 'hello',
'title' => 'hello' . random_int(1, 100000),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr',
'recurring_description' => 'Some descr' . random_int(1, 100000),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
'foreign_currency_id' => '2',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'withdrawal',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '1',
'source_name' => '',
'destination_id' => '',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'create_another' => '1',
'repetition_end' => 'times',
'repetitions' => 3,
];
'repetition_end' => 'times',
'repetitions' => 3,
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
$this->be($this->user());
$response = $this->post(route('recurring.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
*/
public function testStoreDeposit(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
'title' => 'hello' . random_int(1, 100000),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
'foreign_currency_id' => '2',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'deposit',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '2',
'source_name' => 'Some source',
'destination_id' => '1',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'create_another' => '1',
'repetition_end' => 'times',
'repetitions' => 3,
];
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
$this->be($this->user());
$response = $this->post(route('recurring.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
*/
public function testStoreTransfer(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
'title' => 'hello' . random_int(1, 100000),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
'foreign_currency_id' => '2',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'transfer',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '2',
'source_name' => 'Some source',
'destination_id' => '1',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'create_another' => '1',
'repetition_end' => 'times',
'repetitions' => 3,
];
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
$this->be($this->user());
$response = $this->post(route('recurring.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
*/
public function testStoreUntilDate(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
'title' => 'hello' . random_int(1, 100000),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
'foreign_currency_id' => '2',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'withdrawal',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '1',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'create_another' => '1',
'repetition_end' => 'until_date',
'repeat_until' => $tomorrow->format('Y-m-d'),
];
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();

View File

@@ -0,0 +1,77 @@
<?php
/**
* DeleteControllerTest.php
* Copyright (c) 2018 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\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
*
* Class DeleteControllerTest
*/
class DeleteControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
*/
public function testDelete(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$recurringRepos->shouldReceive('getTransactions')->andReturn(new Collection())->once();
$this->be($this->user());
$response = $this->get(route('recurring.delete', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
*/
public function testDestroy(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$recurringRepos->shouldReceive('destroy')->once();
$this->be($this->user());
$response = $this->post(route('recurring.destroy', [1]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* EditControllerTest.php
* Copyright (c) 2018 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 Carbon\Carbon;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
*
* Class EditControllerTest
*/
class EditControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
*/
public function testEdit(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$recurringRepos->shouldReceive('setUser');
$recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
$recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
$recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
$budgetRepos->shouldReceive('findNull')->andReturn($this->user()->budgets()->first());
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
//\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
$response = $this->get(route('recurring.edit', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
*/
public function testUpdate(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$recurringRepos->shouldReceive('update')->once();
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
'id' => $recurrence->id,
'title' => 'hello',
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr',
'active' => '1',
'apply_rules' => '1',
'return_to_edit' => '1',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'withdrawal',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '1',
'source_name' => '',
'destination_id' => '',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'create_another' => '1',
'repetition_end' => 'times',
'repetitions' => 3,
];
$this->be($this->user());
$response = $this->post(route('recurring.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* IndexControllerTest.php
* Copyright (c) 2018 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\Models\Configuration;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
*
* Class IndexControllerTest
*/
class IndexControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
*/
public function testIndex(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
$config = new Configuration;
$config->data = 0;
$falseConfig = new Configuration;
$falseConfig->data = false;
$collection = $this->user()->recurrences()->take(2)->get();
// mock cron job config:
\FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
\FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
$repository->shouldReceive('get')->andReturn($collection)->once();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$this->be($this->user());
$response = $this->get(route('recurring.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
public function testShow(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$repository->shouldReceive('getTransactions')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -231,7 +231,6 @@ class ExpenseControllerTest extends TestCase
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
//$collector->shouldReceive('')->andReturnSelf();
$this->be($this->user());
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
@@ -248,6 +247,36 @@ class ExpenseControllerTest extends TestCase
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
// fake collection:
$transA = new Transaction;
$transA->transaction_currency_id = 1;
$transA->transaction_category_name = 'Category';
$transA->transaction_category_id = 1;
$transA->transaction_currency_symbol = 'A';
$transA->transaction_currency_dp = 2;
$transA->transaction_amount = '100';
$transA->opposing_account_id = $expense->id;
$transB = new Transaction;
$transB->transaction_currency_id = 2;
$transB->transaction_category_name = null;
$transB->transaction_category_id = 0;
$transB->transaction_journal_budget_name = 'Category2';
$transB->transaction_journal_budget_id = 2;
$transB->transaction_currency_symbol = 'A';
$transB->transaction_currency_dp = 2;
$transB->transaction_amount = '100';
$transB->opposing_account_id = $expense->id;
$collection = new Collection([$transA, $transB]);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
//$collector->shouldReceive('')->andReturnSelf();
$this->be($this->user());
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
$response->assertStatus(200);

View File

@@ -63,6 +63,23 @@ class CreateControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
*/
public function testCreateFromBill(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('rules.create-from-bill', [1,1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
*/

View File

@@ -0,0 +1,117 @@
<?php
/**
* CronControllerTest.php
* Copyright (c) 2018 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\System;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
/**
*
* Class CronControllerTest
*/
class CronControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\System\CronController
* @covers \FireflyIII\Support\Binder\CLIToken
*/
public function testCron(): void
{
$users = new Collection([$this->user()]);
$job = $this->mock(RecurringCronjob::class);
$preference = new Preference();
$preference->data = 'token';
$job->shouldReceive('fire')->once()->andReturn(true);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));
$response->assertStatus(200);
$response->assertSee('The recurring transaction cron job fired successfully.');
}
/**
* @covers \FireflyIII\Http\Controllers\System\CronController
* @covers \FireflyIII\Support\Binder\CLIToken
*/
public function testCronException(): void
{
$users = new Collection([$this->user()]);
$job = $this->mock(RecurringCronjob::class);
$preference = new Preference();
$preference->data = 'token';
$job->shouldReceive('fire')->once()->andThrow(new FireflyException('Exception noted.'));
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));
$response->assertStatus(200);
$response->assertSee('Exception noted.');
}
/**
* @covers \FireflyIII\Http\Controllers\System\CronController
* @covers \FireflyIII\Support\Binder\CLIToken
*/
public function testCronFalse(): void
{
$users = new Collection([$this->user()]);
$job = $this->mock(RecurringCronjob::class);
$preference = new Preference();
$preference->data = 'token';
$job->shouldReceive('fire')->once()->andReturn(false);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));
$response->assertStatus(200);
$response->assertSee('The recurring transaction cron job did not fire.');
}
}

View File

@@ -55,7 +55,6 @@ class ConvertControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexDepositTransfer(): void
@@ -64,13 +63,7 @@ class ConvertControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$deposit = $this->getRandomDeposit();
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
@@ -102,13 +95,7 @@ class ConvertControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$deposit = $this->getRandomDeposit();
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
@@ -135,13 +122,7 @@ class ConvertControllerTest extends TestCase
// mock stuff:
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$deposit = $this->getRandomDeposit();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
@@ -190,13 +171,7 @@ class ConvertControllerTest extends TestCase
// mock stuff:
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$transfer = $this->getRandomTransfer();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
@@ -215,13 +190,7 @@ class ConvertControllerTest extends TestCase
public function testIndexTransferWithdrawal(): void
{
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$transfer = $this->getRandomTransfer();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -247,13 +216,7 @@ class ConvertControllerTest extends TestCase
{
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$withdrawal = $this->getRandomWithdrawal();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -278,13 +241,7 @@ class ConvertControllerTest extends TestCase
public function testIndexWithdrawalTransfer(): void
{
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$withdrawal = $this->getRandomWithdrawal();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -379,13 +336,7 @@ class ConvertControllerTest extends TestCase
$account = $this->user()->accounts()->first();
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$withdrawal = $this->getRandomWithdrawal();
// mock stuff
$messageBag = new MessageBag;
@@ -459,12 +410,7 @@ class ConvertControllerTest extends TestCase
public function testPostIndexTransferDeposit(): void
{
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$transfer =$this->getRandomTransfer();
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);

View File

@@ -249,7 +249,9 @@ class SingleControllerTest extends TestCase
// mock new account list:
$currency = TransactionCurrency::first();
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]])->andReturn(new Collection([$account]))->once();
->withArgs(
[[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]]
)->andReturn(new Collection([$account]))->once();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(6);
$this->be($this->user());
@@ -867,13 +869,7 @@ class SingleControllerTest extends TestCase
}
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$withdrawal = $this->getRandomWithdrawal();
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
$this->session(['transactions.edit.uri' => 'http://localhost']);

View File

@@ -24,9 +24,11 @@ declare(strict_types=1);
namespace Tests;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
@@ -41,7 +43,6 @@ use Mockery;
abstract class TestCase extends BaseTestCase
{
/**
* @param User $user
* @param string $range
@@ -76,8 +77,6 @@ abstract class TestCase extends BaseTestCase
}
}
use CreatesApplication;
/**
* @return array
*/
@@ -94,6 +93,8 @@ abstract class TestCase extends BaseTestCase
];
}
use CreatesApplication;
/**
* @return User
*/
@@ -110,6 +111,30 @@ abstract class TestCase extends BaseTestCase
return User::find(2);
}
/**
* @return TransactionJournal
*/
public function getRandomDeposit(): TransactionJournal
{
return $this->getRandomJournal(TransactionType::DEPOSIT);
}
/**
* @return TransactionJournal
*/
public function getRandomWithdrawal(): TransactionJournal
{
return $this->getRandomJournal(TransactionType::WITHDRAWAL);
}
/**
* @return TransactionJournal
*/
public function getRandomTransfer(): TransactionJournal
{
return $this->getRandomJournal(TransactionType::TRANSFER);
}
/**
* @return User
*/
@@ -146,10 +171,38 @@ abstract class TestCase extends BaseTestCase
/**
*
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
}
/**
* @param string $type
*
* @return TransactionJournal
*/
private function getRandomJournal(string $type): TransactionJournal
{
$query = DB::table('transactions')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('transaction_journals.user_id', $this->user()->id)
->whereNull('transaction_journals.deleted_at')
->whereNull('transactions.deleted_at')
->where('transaction_types.type', $type)
->groupBy('transactions.transaction_journal_id')
->having('ct', '=', 2)
->inRandomOrder()->take(1);
$result = $query->get(
[
'transactions.transaction_journal_id',
'transaction_journalstransaction_type_id',
DB::raw('COUNT(transaction_journal_id) as ct'),
]
)->first();
return TransactionJournal::find((int)$result->transaction_journal_id);
}
}

View File

@@ -137,17 +137,12 @@ class JournalUpdateServiceTest extends TestCase
$service->shouldReceive('setUser');
$service->shouldReceive('updateBudget')->withArgs([Mockery::any(), $budget->id])->twice();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
// call update service to update budget. Should call transaction service twice.
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->updateBudget($journal, $budget->id);
$service->updateBudget($withdrawal, $budget->id);
}
/**
@@ -160,16 +155,12 @@ class JournalUpdateServiceTest extends TestCase
$service->shouldReceive('updateCategory')->withArgs([Mockery::any(), 'New category'])->twice();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
// call update service to update budget. Should call transaction service twice.
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->updateCategory($journal, 'New category');
$service->updateCategory($withdrawal, 'New category');
}

View File

@@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetDestinationAccount;
use Tests\TestCase;
@@ -46,18 +45,11 @@ class SetDestinationAccountTest extends TestCase
*/
public function testActDepositExisting(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$deposit = $this->getRandomDeposit();
$destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
$destination = $destinationTr->account;
$user = $journal->user;
$user = $deposit->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
$this->assertNotEquals($destination->id, $account->id);
@@ -70,12 +62,11 @@ class SetDestinationAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = $account->name;
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($deposit);
$this->assertTrue($result);
// test journal for new account
$journal = TransactionJournal::find($journal->id);
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
$destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
$newDestination = $destinationTr->account;
$this->assertNotEquals($destination->id, $newDestination->id);
$this->assertEquals($newDestination->id, $account->id);
@@ -89,13 +80,7 @@ class SetDestinationAccountTest extends TestCase
public function testActDepositNotExisting(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$deposit = $this->getRandomDeposit();
// find account? Return account:
$accountRepos->shouldReceive('setUser');
@@ -105,7 +90,7 @@ class SetDestinationAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Not existing asset account #' . random_int(1, 10000);
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($deposit);
$this->assertFalse($result);
}
@@ -117,15 +102,8 @@ class SetDestinationAccountTest extends TestCase
public function testActWithDrawalNotExisting(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 4)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
// find account? Return account:
$accountRepos->shouldReceive('setUser');
@@ -136,7 +114,7 @@ class SetDestinationAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Not existing expense account #' . random_int(1, 10000);
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($withdrawal);
$this->assertTrue($result);
}
@@ -148,19 +126,11 @@ class SetDestinationAccountTest extends TestCase
*/
public function testActWithdrawalExisting(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal();
$destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
$destination = $destinationTr->account;
$user = $journal->user;
$user = $withdrawal->user;
$accountType = AccountType::whereType(AccountType::EXPENSE)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
$this->assertNotEquals($destination->id, $account->id);
@@ -173,12 +143,11 @@ class SetDestinationAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = $account->name;
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($withdrawal);
$this->assertTrue($result);
// test journal for new account
$journal = TransactionJournal::find($journal->id);
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
$destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
$newDestination = $destinationTr->account;
$this->assertNotEquals($destination->id, $newDestination->id);
$this->assertEquals($newDestination->id, $account->id);

View File

@@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetSourceAccount;
use Tests\TestCase;
@@ -45,21 +44,12 @@ class SetSourceAccountTest extends TestCase
public function testActDepositExistingUpdated(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$deposit = $this->getRandomDeposit();
$sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $deposit->user;
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$this->assertNotEquals($source->id, $account->id);
// find account? Return account:
@@ -70,12 +60,11 @@ class SetSourceAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = $account->name;
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($deposit);
$this->assertTrue($result);
// test journal for new account
$journal = TransactionJournal::find($journal->id);
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
$newSource = $sourceTr->account;
$this->assertNotEquals($source->id, $newSource->id);
$this->assertEquals($newSource->id, $account->id);
@@ -89,14 +78,8 @@ class SetSourceAccountTest extends TestCase
public function testActDepositRevenue(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 5)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$deposit = $this->getRandomDeposit();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('findByName')->andReturn(null);
@@ -106,7 +89,7 @@ class SetSourceAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Some new revenue #' . random_int(1, 10000);
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($deposit);
$this->assertTrue($result);
}
@@ -118,17 +101,11 @@ class SetSourceAccountTest extends TestCase
public function testActWithdrawalExistingUpdated(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$withdrawal = $this->getRandomWithdrawal();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$user = $withdrawal->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$this->assertNotEquals($source->id, $account->id);
@@ -141,12 +118,11 @@ class SetSourceAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = $account->name;
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($withdrawal);
$this->assertTrue($result);
// test journal for new account
$journal = TransactionJournal::find($journal->id);
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
$newSource = $sourceTr->account;
$this->assertNotEquals($source->id, $newSource->id);
$this->assertEquals($newSource->id, $account->id);
@@ -160,13 +136,7 @@ class SetSourceAccountTest extends TestCase
public function testActWithdrawalNotExisting(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('findByName')->andReturn(null);
@@ -175,7 +145,7 @@ class SetSourceAccountTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Some new account #' . random_int(1, 10000);
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$result = $action->act($withdrawal);
$this->assertFalse($result);
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Triggers\BudgetIs;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -38,18 +37,14 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$withdrawal = $this->getRandomWithdrawal();
$budget = $withdrawal->user->budgets()->first();
$withdrawal->budgets()->detach();
$withdrawal->budgets()->save($budget);
$this->assertEquals(1, $withdrawal->budgets()->count());
$trigger = BudgetIs::makeFromStrings($budget->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}
@@ -58,19 +53,15 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredNotJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$budget = $journal->user->budgets()->first();
$otherBudget = $journal->user->budgets()->where('id', '!=', $budget->id)->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$withdrawal = $this->getRandomWithdrawal();
$budget = $withdrawal->user->budgets()->first();
$otherBudget = $withdrawal->user->budgets()->where('id', '!=', $budget->id)->first();
$withdrawal->budgets()->detach();
$withdrawal->budgets()->save($budget);
$this->assertEquals(1, $withdrawal->budgets()->count());
$trigger = BudgetIs::makeFromStrings($otherBudget->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}
@@ -79,16 +70,12 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$withdrawal = $this->getRandomWithdrawal();
/** @var Collection $transactions */
$transactions = $journal->transactions()->get();
$budget = $journal->user->budgets()->first();
$transactions = $withdrawal->transactions()->get();
$budget = $withdrawal->user->budgets()->first();
$journal->budgets()->detach();
$withdrawal->budgets()->detach();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$transaction->budgets()->detach();
@@ -96,10 +83,10 @@ class BudgetIsTest extends TestCase
$this->assertEquals(1, $transaction->budgets()->count());
}
$this->assertEquals(0, $journal->budgets()->count());
$this->assertEquals(0, $withdrawal->budgets()->count());
$trigger = BudgetIs::makeFromStrings($budget->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}

View File

@@ -36,18 +36,14 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$withdrawal = $this->getRandomWithdrawal();
$category = $withdrawal->user->categories()->first();
$withdrawal->categories()->detach();
$withdrawal->categories()->save($category);
$this->assertEquals(1, $withdrawal->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}
@@ -56,19 +52,15 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredNotJournal(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$category = $journal->user->categories()->first();
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
$journal->categories()->detach();
$journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count());
$withdrawal = $this->getRandomWithdrawal();
$category = $withdrawal->user->categories()->first();
$otherCategory = $withdrawal->user->categories()->where('id', '!=', $category->id)->first();
$withdrawal->categories()->detach();
$withdrawal->categories()->save($category);
$this->assertEquals(1, $withdrawal->categories()->count());
$trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}
@@ -77,22 +69,18 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transactions = $journal->transactions()->count();
} while ($transactions !== 2);
$withdrawal = $this->getRandomWithdrawal();
$transaction = $withdrawal->transactions()->first();
$category = $withdrawal->user->categories()->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$withdrawal->categories()->detach();
$transaction->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(0, $withdrawal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());
$trigger = CategoryIs::makeFromStrings($category->name, false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}

View File

@@ -38,21 +38,15 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggered(): void
{
$loop = 0;
do {
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$withdrawal = $this->getRandomWithdrawal();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
$budget = $withdrawal->user->budgets()->first();
$withdrawal->budgets()->detach();
$withdrawal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count());
$this->assertEquals(1, $withdrawal->budgets()->count());
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}
@@ -62,25 +56,18 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggeredNot(): void
{
$loop = 0;
do {
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$withdrawal = $this->getRandomWithdrawal();
$withdrawal->budgets()->detach();
$this->assertEquals(0, $withdrawal->budgets()->count());
// also detach all transactions:
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
foreach ($withdrawal->transactions()->get() as $transaction) {
$transaction->budgets()->detach();
}
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}
@@ -90,28 +77,17 @@ class HasAnyBudgetTest extends TestCase
public function testTriggeredTransactions(): void
{
Log::debug('Now in testTriggeredTransactions()');
$loop = 0;
do {
Log::debug(sprintf('Loop is now at #%d', $loop));
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$withdrawal = $this->getRandomWithdrawal();
Log::debug(sprintf('Found journal #%d with %d transactions', $journal->id, $count));
$loop++;
} while ($count !== 2 && $loop < 30);
Log::debug('end of loop!');
$budget = $journal->user->budgets()->first();
$budget = $withdrawal->user->budgets()->first();
Log::debug(sprintf('First budget is %d ("%s")', $budget->id, $budget->name));
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$withdrawal->budgets()->detach();
$this->assertEquals(0, $withdrawal->budgets()->count());
Log::debug('Survived the assumption.');
// append to transaction
Log::debug('Do transaction loop.');
foreach ($journal->transactions()->get() as $index => $transaction) {
foreach ($withdrawal->transactions()->get() as $index => $transaction) {
Log::debug(sprintf('Now at index #%d, transaction #%d', $index, $transaction->id));
$transaction->budgets()->detach();
if (0 === $index) {
@@ -121,7 +97,7 @@ class HasAnyBudgetTest extends TestCase
}
Log::debug('Done with loop, make trigger');
$trigger = HasAnyBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}

View File

@@ -73,27 +73,21 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggeredTransactions(): void
{
$count = 0;
$journal = null;
while ($count === 0) {
/** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
}
$withdrawal = $this->getRandomWithdrawal();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
$category = $withdrawal->user->categories()->first();
$withdrawal->categories()->detach();
$this->assertEquals(0, $withdrawal->categories()->count());
// append to transaction, not to journal.
foreach ($journal->transactions()->get() as $index => $transaction) {
foreach ($withdrawal->transactions()->get() as $index => $transaction) {
$transaction->categories()->sync([$category->id]);
$this->assertEquals(1, $transaction->categories()->count());
}
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(0, $withdrawal->categories()->count());
$trigger = HasAnyCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}

View File

@@ -36,17 +36,14 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggered(): void
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
} while ($count !== 0);
$withdrawal = $this->getRandomWithdrawal();
$attachment = $journal->user->attachments()->first();
$journal->attachments()->save($attachment);
$this->assertEquals(1, $journal->attachments()->count());
$attachment = $withdrawal->user->attachments()->first();
$withdrawal->attachments()->save($attachment);
$this->assertEquals(1, $withdrawal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertTrue($result);
}
@@ -55,16 +52,12 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggeredFalse(): void
{
do {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
} while ($count !== 0);
$withdrawal = $this->getRandomWithdrawal();
$this->assertEquals(0, $journal->attachments()->count());
$this->assertEquals(0, $withdrawal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}

View File

@@ -72,25 +72,21 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
$loopCount = 0;
do {
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($loopCount < 30 && $count !== 2);
$withdrawal = $this->getRandomWithdrawal();
$transactions = $journal->transactions()->get();
$budget = $journal->user->budgets()->first();
$transactions = $withdrawal->transactions()->get();
$budget = $withdrawal->user->budgets()->first();
$journal->budgets()->detach();
$withdrawal->budgets()->detach();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$transaction->budgets()->sync([$budget->id]);
$this->assertEquals(1, $transaction->budgets()->count());
}
$this->assertEquals(0, $journal->budgets()->count());
$this->assertEquals(0, $withdrawal->budgets()->count());
$trigger = HasNoBudget::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}

View File

@@ -75,21 +75,17 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredTransaction(): void
{
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
}
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$withdrawal = $this->getRandomWithdrawal();
$transaction = $withdrawal->transactions()->first();
$category = $withdrawal->user->categories()->first();
$journal->categories()->detach();
$withdrawal->categories()->detach();
$transaction->categories()->sync([$category->id]);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(0, $withdrawal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());
$trigger = HasNoCategory::makeFromStrings('', false);
$result = $trigger->triggered($journal);
$result = $trigger->triggered($withdrawal);
$this->assertFalse($result);
}