Improve test coverage.

This commit is contained in:
James Cole
2019-08-01 06:21:44 +02:00
parent 9b574ce7ad
commit b049ca27f1
45 changed files with 336 additions and 251 deletions

View File

@@ -576,12 +576,12 @@ class BillRepository implements BillRepositoryInterface
} }
// find the most recent date for this bill NOT in the future. Cache this date: // find the most recent date for this bill NOT in the future. Cache this date:
$start = clone $bill->date; $start = clone $bill->date;
Log::debug('nextDateMatch: Start is ' . $start->format('Y-m-d')); //Log::debug('nextDateMatch: Start is ' . $start->format('Y-m-d'));
while ($start < $date) { while ($start < $date) {
Log::debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d'), $date->format('Y-m-d'))); //Log::debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d'), $date->format('Y-m-d')));
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); $start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
Log::debug('Start is now ' . $start->format('Y-m-d')); //Log::debug('Start is now ' . $start->format('Y-m-d'));
} }
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); $end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);

View File

@@ -73,7 +73,6 @@ class AddTag implements ActionInterface
return true; return true;
} }
Log::debug(sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal->id)); Log::debug(sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal->id));
return false; return false;

View File

@@ -53,7 +53,7 @@ class ClearBudget implements ActionInterface
$journal->budgets()->detach(); $journal->budgets()->detach();
$journal->touch(); $journal->touch();
// also remove categories from transactions: // also remove budgets from transactions (although no longer necessary)
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) { foreach ($journal->transactions as $transaction) {
$transaction->budgets()->detach(); $transaction->budgets()->detach();

View File

@@ -39,6 +39,8 @@ class LinkToBill implements ActionInterface
/** /**
* TriggerInterface constructor. * TriggerInterface constructor.
* *
* @codeCoverageIgnore
*
* @param RuleAction $action * @param RuleAction $action
*/ */
public function __construct(RuleAction $action) public function __construct(RuleAction $action)
@@ -65,13 +67,13 @@ class LinkToBill implements ActionInterface
$journal->bill()->associate($bill); $journal->bill()->associate($bill);
$journal->save(); $journal->save();
Log::debug(sprintf('RuleAction LinkToBill set the bill of journal #%d to bill #%d ("%s").', $journal->id, $bill->id, $bill->name)); Log::debug(sprintf('RuleAction LinkToBill set the bill of journal #%d to bill #%d ("%s").', $journal->id, $bill->id, $bill->name));
return true;
} }
if (null === $bill) { Log::error(sprintf('RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": no such bill found!', $journal->id, $billName));
Log::error(sprintf('RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": no such bill found!', $journal->id, $billName));
}
return true; return false;
} }
} }

View File

@@ -47,7 +47,7 @@ class RemoveTag implements ActionInterface
/** /**
* Remove tag X * Remove tag X
* * TODO the filter is no longer necessary.
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return bool * @return bool

View File

@@ -49,7 +49,8 @@ class SetBudget implements ActionInterface
} }
/** /**
* Set budget X * Set budget.
* TODO the filter is no longer necessary.
* *
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
@@ -63,14 +64,14 @@ class SetBudget implements ActionInterface
$search = $this->action->action_value; $search = $this->action->action_value;
$budgets = $repository->getActiveBudgets(); $budgets = $repository->getActiveBudgets();
$budget = $budgets->filter( $budget = $budgets->filter(
function (Budget $current) use ($search) { static function (Budget $current) use ($search) {
return $current->name === $search; return $current->name === $search;
} }
)->first(); )->first();
if (null === $budget) { if (null === $budget) {
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search)); Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
return true; return false;
} }
if (TransactionType::WITHDRAWAL !== $journal->transactionType->type) { if (TransactionType::WITHDRAWAL !== $journal->transactionType->type) {
@@ -88,12 +89,7 @@ class SetBudget implements ActionInterface
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name)); Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
$journal->budgets()->detach(); $journal->budgets()->sync([$budget->id]);
// set budget on transactions:
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$transaction->budgets()->sync([$budget->id]);
}
$journal->touch(); $journal->touch();
return true; return true;

View File

@@ -64,18 +64,11 @@ class SetCategory implements ActionInterface
if (null === $category) { if (null === $category) {
Log::error(sprintf('Action SetCategory did not fire because "%s" did not result in a valid category.', $name)); Log::error(sprintf('Action SetCategory did not fire because "%s" did not result in a valid category.', $name));
return true; return false;
} }
$journal->categories()->detach();
// set category on transactions:
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$transaction->categories()->sync([$category->id]);
}
$journal->touch();
$journal->categories()->sync([$category->id]);
$journal->touch();
Log::debug(sprintf('RuleAction SetCategory set the category of journal #%d to category #%d ("%s").', $journal->id, $category->id, $category->name)); Log::debug(sprintf('RuleAction SetCategory set the category of journal #%d to category #%d ("%s").', $journal->id, $category->id, $category->name));
return true; return true;

View File

@@ -69,13 +69,6 @@ class SetDestinationAccount implements ActionInterface
$this->journal = $journal; $this->journal = $journal;
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($journal->user); $this->repository->setUser($journal->user);
$count = $journal->transactions()->count();
if ($count > 2) {
Log::error(sprintf('Cannot change destination account of journal #%d because it is a split journal.', $journal->id));
return false;
}
// journal type: // journal type:
$type = $journal->transactionType->type; $type = $journal->transactionType->type;
@@ -103,7 +96,7 @@ class SetDestinationAccount implements ActionInterface
// get destination transaction: // get destination transaction:
$transaction = $journal->transactions()->where('amount', '>', 0)->first(); $transaction = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $transaction) { if (null === $transaction) {
return true; return true; // @codeCoverageIgnore
} }
$transaction->account_id = $this->newDestinationAccount->id; $transaction->account_id = $this->newDestinationAccount->id;
$transaction->save(); $transaction->save();

View File

@@ -69,13 +69,6 @@ class SetSourceAccount implements ActionInterface
$this->journal = $journal; $this->journal = $journal;
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($journal->user); $this->repository->setUser($journal->user);
$count = $journal->transactions()->count();
if ($count > 2) {
Log::error(sprintf('Cannot change source account of journal #%d because it is a split journal.', $journal->id));
return false;
}
// journal type: // journal type:
$type = $journal->transactionType->type; $type = $journal->transactionType->type;
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist: // if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
@@ -102,9 +95,11 @@ class SetSourceAccount implements ActionInterface
// get source transaction: // get source transaction:
$transaction = $journal->transactions()->where('amount', '<', 0)->first(); $transaction = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $transaction) { if (null === $transaction) {
// @codeCoverageIgnoreStart
Log::error(sprintf('Cannot change source account of journal #%d because no source transaction exists.', $journal->id)); Log::error(sprintf('Cannot change source account of journal #%d because no source transaction exists.', $journal->id));
return false; return false;
// @codeCoverageIgnoreEnd
} }
$transaction->account_id = $this->newSourceAccount->id; $transaction->account_id = $this->newSourceAccount->id;
$transaction->save(); $transaction->save();

View File

@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Unit/Rules</directory> <directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory> <directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory> <directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
</testsuite> </testsuite>
<testsuite name="Feature"> <testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory> <directory suffix="Test.php">./tests/Feature</directory>

View File

@@ -49,6 +49,7 @@
<directory suffix="Test.php">./tests/Unit/Rules</directory> <directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory> <directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory> <directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
</testsuite> </testsuite>
<testsuite name="Feature"> <testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory> <directory suffix="Test.php">./tests/Feature</directory>

View File

@@ -49,6 +49,7 @@
<directory suffix="Test.php">./tests/Unit/Rules</directory> <directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory> <directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory> <directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
</testsuite> </testsuite>
<testsuite name="Feature"> <testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory> <directory suffix="Test.php">./tests/Feature</directory>

View File

@@ -24,8 +24,6 @@ namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Factory\TagFactory; use FireflyIII\Factory\TagFactory;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Actions\AddTag; use FireflyIII\TransactionRules\Actions\AddTag;
use Log; use Log;
use Tests\TestCase; use Tests\TestCase;
@@ -49,42 +47,84 @@ class AddTagTest extends TestCase
*/ */
public function testActExistingTag(): void public function testActExistingTag(): void
{ {
$tag = $this->user()->tags()->inRandomOrder()->whereNull('deleted_at')->first();
$tagFactory = $this->mock(TagFactory::class); $tagFactory = $this->mock(TagFactory::class);
$tag = $this->getRandomTag();
$journal = $this->getRandomWithdrawal();
// make sure journal has no tags:
$journal->tags()->sync([]);
$journal->save();
// add single existing tag:
$journal->tags()->sync([$tag->id]);
$tagFactory->shouldReceive('setUser')->once(); $tagFactory->shouldReceive('setUser')->once();
$tagFactory->shouldReceive('findOrCreate')->once()->withArgs([$tag->tag])->andReturn($tag); $tagFactory->shouldReceive('findOrCreate')->once()->withArgs([$tag->tag])->andReturn($tag);
// assert connection exists.
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->sync([]);
$journal->tags()->sync([$tag->id]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]); $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
// file action
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = $tag->tag; $ruleAction->action_value = $tag->tag;
$action = new AddTag($ruleAction); $action = new AddTag($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertFalse($result); $this->assertFalse($result);
// assert DB is unchanged.
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
}
/**
* @covers \FireflyIII\TransactionRules\Actions\AddTag
*/
public function testActNewTag(): void
{
$tagFactory = $this->mock(TagFactory::class);
$tag = $this->getRandomTag();
$journal = $this->getRandomWithdrawal();
// make sure journal has no tags:
$journal->tags()->sync([]);
$journal->save();
$tagFactory->shouldReceive('setUser')->once();
$tagFactory->shouldReceive('findOrCreate')->once()->withArgs([$tag->tag])->andReturn($tag);
// assert connection does not exist.
$this->assertDatabaseMissing('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
// file action
$ruleAction = new RuleAction;
$ruleAction->action_value = $tag->tag;
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
// assert DB is unchanged.
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]); $this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
} }
/** /**
* @covers \FireflyIII\TransactionRules\Actions\AddTag * @covers \FireflyIII\TransactionRules\Actions\AddTag
*/ */
public function testActNoTag(): void public function testActNullTag(): void
{ {
$newTagName = 'TestTag-' . $th; // try to add non-existing tag
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $tagFactory = $this->mock(TagFactory::class);
$newTagName = 'TestTag-' . $this->randomInt();
// should return null:
$tagFactory->shouldReceive('setUser')->once();
$tagFactory->shouldReceive('findOrCreate')->once()->withArgs([$newTagName])->andReturnNull();
$journal = $this->getRandomWithdrawal();
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = $newTagName; $ruleAction->action_value = $newTagName;
$action = new AddTag($ruleAction); $action = new AddTag($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertFalse($result);
// find newly created tag:
$tag = Tag::orderBy('id', 'DESC')->first();
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
} }
} }

View File

@@ -49,11 +49,10 @@ class AppendDescriptionTest extends TestCase
{ {
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = 'APPEND'; $ruleAction->action_value = 'APPEND';
$journal = $this->getRandomWithdrawal();
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $oldDescription = $journal->description;
$oldDescription = $journal->description; $action = new AppendDescription($ruleAction);
$action = new AppendDescription($ruleAction); $result = $action->act($journal);
$result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);
$journal = TransactionJournal::find($journal->id); $journal = TransactionJournal::find($journal->id);

View File

@@ -49,7 +49,7 @@ class AppendNotesTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// give journal some notes. // give journal some notes.
$journal = TransactionJournal::find(3); $journal = $this->getRandomWithdrawal();
$note = $journal->notes()->first(); $note = $journal->notes()->first();
$start = 'Default note text'; $start = 'Default note text';
$toAppend = 'This is appended'; $toAppend = 'This is appended';

View File

@@ -49,8 +49,8 @@ class ClearBudgetTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// associate budget with journal: // associate budget with journal:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$budget = $journal->user->budgets()->first(); $budget = $this->getRandomBudget();
$journal->budgets()->save($budget); $journal->budgets()->save($budget);
$this->assertGreaterThan(0, $journal->budgets()->count()); $this->assertGreaterThan(0, $journal->budgets()->count());

View File

@@ -49,8 +49,8 @@ class ClearCategoryTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// associate budget with journal: // associate budget with journal:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$category = $journal->user->categories()->first(); $category = $this->getRandomCategory();;
$journal->categories()->save($category); $journal->categories()->save($category);
$this->assertGreaterThan(0, $journal->categories()->count()); $this->assertGreaterThan(0, $journal->categories()->count());

View File

@@ -51,7 +51,7 @@ class ClearNotesTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// give journal a note: // give journal a note:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$note = $journal->notes()->first(); $note = $journal->notes()->first();
if (null === $note) { if (null === $note) {
$note = new Note; $note = new Note;

View File

@@ -53,11 +53,8 @@ class ConvertToDepositTest extends TestCase
* *
* @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit * @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
*/ */
public function testActTransfer() public function testActTransfer(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$revenue = $this->getRandomRevenue(); $revenue = $this->getRandomRevenue();
$name = 'Random revenue #' . $this->randomInt(); $name = 'Random revenue #' . $this->randomInt();
$journal = $this->getRandomTransfer(); $journal = $this->getRandomTransfer();
@@ -92,11 +89,8 @@ class ConvertToDepositTest extends TestCase
* *
* @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit * @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
*/ */
public function testActWithdrawal() public function testActWithdrawal(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$revenue = $this->getRandomRevenue(); $revenue = $this->getRandomRevenue();
$name = 'Random revenue #' . $this->randomInt(); $name = 'Random revenue #' . $this->randomInt();
$journal = $this->getRandomWithdrawal(); $journal = $this->getRandomWithdrawal();

View File

@@ -27,6 +27,7 @@ namespace Tests\Unit\TransactionRules\Actions;
use Exception; use Exception;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -56,24 +57,21 @@ class ConvertToTransferTest extends TestCase
*/ */
public function testActDeposit(): void public function testActDeposit(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
/** @var Account $asset */ /** @var Account $asset */
$asset = $this->user()->accounts()->where('name', 'Bitcoin Account')->first(); $asset = $this->getRandomAsset();
// journal is a withdrawal:
$this->assertEquals(TransactionType::DEPOSIT, $deposit->transactionType->type);
// mock used stuff: // mock used stuff:
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once(); $accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]]) $accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($asset);
->andReturn($asset);
// fire the action: // fire the action:
$rule = new Rule;
$rule->title = 'OK';
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = $asset->name; $ruleAction->action_value = $asset->name;
$ruleAction->rule = $rule;
$action = new ConvertToTransfer($ruleAction); $action = new ConvertToTransfer($ruleAction);
try { try {
@@ -95,24 +93,21 @@ class ConvertToTransferTest extends TestCase
*/ */
public function testActWithdrawal(): void public function testActWithdrawal(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
/** @var Account $asset */ /** @var Account $asset */
$asset = $this->user()->accounts()->where('name', 'Bitcoin Account')->first(); $asset = $this->getRandomAsset();
// journal is a withdrawal:
$this->assertEquals(TransactionType::WITHDRAWAL, $withdrawal->transactionType->type);
// mock used stuff: // mock used stuff:
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once(); $accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]]) $accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($asset);
->andReturn($asset);
// fire the action: // fire the action:
$rule = new Rule;
$rule->title = 'OK';
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = $asset->name; $ruleAction->action_value = $asset->name;
$ruleAction->rule = $rule;
$action = new ConvertToTransfer($ruleAction); $action = new ConvertToTransfer($ruleAction);
try { try {

View File

@@ -55,9 +55,6 @@ class ConvertToWithdrawalTest extends TestCase
*/ */
public function testActDeposit() public function testActDeposit()
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$expense = $this->getRandomExpense(); $expense = $this->getRandomExpense();
$name = 'Random expense #' . $this->randomInt(); $name = 'Random expense #' . $this->randomInt();
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
@@ -94,16 +91,10 @@ class ConvertToWithdrawalTest extends TestCase
*/ */
public function testActTransfer() public function testActTransfer()
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$expense = $this->getRandomExpense(); $expense = $this->getRandomExpense();
$name = 'Random expense #' . $this->randomInt(); $name = 'Random expense #' . $this->randomInt();
$transfer = $this->getRandomTransfer(); $transfer = $this->getRandomTransfer();
// journal is a transfer:
$this->assertEquals(TransactionType::TRANSFER, $transfer->transactionType->type);
// mock used stuff: // mock used stuff:
$factory = $this->mock(AccountFactory::class); $factory = $this->mock(AccountFactory::class);
$factory->shouldReceive('setUser')->once(); $factory->shouldReceive('setUser')->once();

View File

@@ -0,0 +1,95 @@
<?php
/**
* LinkToBillTest.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/>.
*/
namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\TransactionRules\Actions\LinkToBill;
use Log;
use Tests\TestCase;
/**
* Class LinkToBillTest
*/
class LinkToBillTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\TransactionRules\Actions\LinkToBill
*/
public function testBasic(): void
{
$repos = $this->mock(BillRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal();
$rule = $this->getRandomRule();
$bill = $this->getRandomBill();
$ruleAction = new RuleAction;
$ruleAction->rule = $rule;
$ruleAction->action_type = 'link_to_bill';
$ruleAction->action_value = $bill->name;
$repos->shouldReceive('setUser');
$repos->shouldReceive('findByName')->withArgs([$bill->name])->andReturn($bill);
$action = new LinkToBill($ruleAction);
$result = $action->act($withdrawal);
$this->assertTrue($result);
}
/**
* @covers \FireflyIII\TransactionRules\Actions\LinkToBill
*/
public function testNoBill(): void
{
$repos = $this->mock(BillRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal();
$rule = $this->getRandomRule();
$bill = $this->getRandomBill();
$ruleAction = new RuleAction;
$ruleAction->rule = $rule;
$ruleAction->action_type = 'link_to_bill';
$ruleAction->action_value = $bill->name;
$repos->shouldReceive('setUser');
$repos->shouldReceive('findByName')->withArgs([$bill->name])->andReturnNull();
$action = new LinkToBill($ruleAction);
$result = $action->act($withdrawal);
$this->assertFalse($result);
}
}

View File

@@ -39,8 +39,8 @@ class PrependDescriptionTest extends TestCase
{ {
// get journal, give fixed description // get journal, give fixed description
$description = 'text' . $this->randomInt(); $description = 'text' . $this->randomInt();
$prepend = 'prepend' . random_int(1, 1234); $prepend = 'prepend' . $this->randomInt();
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->description = $description; $journal->description = $description;
$journal->save(); $journal->save();

View File

@@ -39,7 +39,7 @@ class PrependNotesTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// give journal some notes. // give journal some notes.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$note = $journal->notes()->first(); $note = $journal->notes()->first();
$start = 'Default note text'; $start = 'Default note text';
$toPrepend = 'This is prepended'; $toPrepend = 'This is prepended';
@@ -62,13 +62,12 @@ class PrependNotesTest extends TestCase
} }
/** /**
* @covers \FireflyIII\TransactionRules\Actions\PrependNotes()
* @covers \FireflyIII\TransactionRules\Actions\PrependNotes * @covers \FireflyIII\TransactionRules\Actions\PrependNotes
*/ */
public function testActNewNote(): void public function testActNewNote(): void
{ {
// give journal some notes. // give journal some notes.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$note = $journal->notes()->first(); $note = $journal->notes()->first();
if (null !== $note) { if (null !== $note) {
$note->forceDelete(); $note->forceDelete();

View File

@@ -60,21 +60,20 @@ class RemoveTagTest extends TestCase
} }
/** /**
* @covers \FireflyIII\TransactionRules\Actions\RemoveTag()
* @covers \FireflyIII\TransactionRules\Actions\RemoveTag * @covers \FireflyIII\TransactionRules\Actions\RemoveTag
*/ */
public function testActNoTag(): void public function testActNoTag(): void
{ {
// get journal, link al tags: // get journal, link al tags:
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$tags = $journal->user->tags()->get(); $tags = $journal->user->tags()->get();
$journal->tags()->sync($tags->pluck('id')->toArray()); $journal->tags()->sync($tags->pluck('id')->toArray());
$this->assertEquals($tags->count(), $journal->tags()->get()->count()); $this->assertEquals($tags->count(), $journal->tags()->get()->count());
// fire the action: // fire the action:
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = random_int(1, 1234) . 'nosuchtag'; $ruleAction->action_value = $this->randomInt() . 'nosuchtag';
$action = new RemoveTag($ruleAction); $action = new RemoveTag($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);

View File

@@ -24,7 +24,6 @@ namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetBudget; use FireflyIII\TransactionRules\Actions\SetBudget;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -41,8 +40,57 @@ class SetBudgetTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// get journal, remove all budgets // get journal, remove all budgets
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$budget = $journal->user->budgets()->first(); $budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $budget->name;
$action = new SetBudget($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$this->assertEquals(1, $journal->budgets()->count());
}
/**
* @covers \FireflyIII\TransactionRules\Actions\SetBudget
*/
public function testActNull(): void
{
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $budget->name;
$action = new SetBudget($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
$this->assertEquals(0, $journal->budgets()->count());
}
/**
* @covers \FireflyIII\TransactionRules\Actions\SetBudget
*/
public function testActDeposit(): void
{
// get journal, remove all budgets
$journal = $this->getRandomDeposit();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget])); $budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
@@ -56,10 +104,6 @@ class SetBudgetTest extends TestCase
$action = new SetBudget($ruleAction); $action = new SetBudget($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);
/** @var Transaction $transaction */ $this->assertEquals(0, $journal->budgets()->count());
foreach ($journal->transactions as $transaction) {
$this->assertEquals(1, $transaction->budgets()->count());
$this->assertEquals($budget->name, $transaction->budgets()->first()->name);
}
} }
} }

View File

@@ -22,9 +22,8 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Actions; namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\TransactionRules\Actions\SetCategory; use FireflyIII\TransactionRules\Actions\SetCategory;
use Tests\TestCase; use Tests\TestCase;
@@ -39,8 +38,13 @@ class SetCategoryTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// get journal, remove all budgets // get journal, remove all budgets
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$category = $journal->user->categories()->first(); $category = $this->getRandomCategory();
$factory = $this->mock(CategoryFactory::class);
$factory->shouldReceive('setUser');
$factory->shouldReceive('findOrCreate')->andReturn($category);
$journal->categories()->detach(); $journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count()); $this->assertEquals(0, $journal->categories()->count());
@@ -51,12 +55,31 @@ class SetCategoryTest extends TestCase
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);
/** @var Transaction $transaction */ $this->assertEquals(1, $journal->categories()->count());
foreach ($journal->transactions as $transaction) { }
$this->assertEquals(1, $transaction->categories()->count()); /**
$this->assertEquals($category->name, $transaction->categories()->first()->name); * @covers \FireflyIII\TransactionRules\Actions\SetCategory
} */
public function testActNull(): void
{
$factory = $this->mock(CategoryFactory::class);
$factory->shouldReceive('setUser');
$factory->shouldReceive('findOrCreate')->andReturnNull();
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$category = $this->getRandomCategory();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $category->name;
$action = new SetCategory($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
$this->assertEquals(0, $journal->categories()->count());
} }
} }

View File

@@ -39,8 +39,8 @@ class SetDescriptionTest extends TestCase
{ {
// get journal, give fixed description // get journal, give fixed description
$description = 'text' . $this->randomInt(); $description = 'text' . $this->randomInt();
$newDescription = 'new description' . random_int(1, 1234); $newDescription = 'new description' . $this->randomInt();
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->description = $description; $journal->description = $description;
$journal->save(); $journal->save();

View File

@@ -45,9 +45,6 @@ class SetDestinationAccountTest extends TestCase
*/ */
public function testActDepositExisting(): void public function testActDepositExisting(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
$destinationTr = $deposit->transactions()->where('amount', '>', 0)->first(); $destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
@@ -82,9 +79,6 @@ class SetDestinationAccountTest extends TestCase
*/ */
public function testActDepositNotExisting(): void public function testActDepositNotExisting(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
@@ -107,11 +101,8 @@ class SetDestinationAccountTest extends TestCase
*/ */
public function testActWithDrawalNotExisting(): void public function testActWithDrawalNotExisting(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 4)->first(); $account = $this->getRandomExpense();
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
// find account? Return account: // find account? Return account:
@@ -135,9 +126,6 @@ class SetDestinationAccountTest extends TestCase
*/ */
public function testActWithdrawalExisting(): void public function testActWithdrawalExisting(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
$destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first(); $destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
@@ -165,30 +153,4 @@ class SetDestinationAccountTest extends TestCase
$this->assertEquals($newDestination->id, $account->id); $this->assertEquals($newDestination->id, $account->id);
} }
/**
* Test this on a split journal.
*
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount
*/
public function testSplitJournal(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id')
->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')])
->first();
$journal = TransactionJournal::find($transaction->transaction_journal_id);
// mock
$accountRepos->shouldReceive('setUser');
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Some new asset ' . $this->randomInt();
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
}
} }

View File

@@ -39,7 +39,7 @@ class SetNotesTest extends TestCase
public function testAct(): void public function testAct(): void
{ {
// give journal a note: // give journal a note:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$note = $journal->notes()->first(); $note = $journal->notes()->first();
if (null === $note) { if (null === $note) {
$note = new Note; $note = new Note;
@@ -51,7 +51,7 @@ class SetNotesTest extends TestCase
// fire the action: // fire the action:
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = 'These are new notes ' . random_int(1, 1234); $ruleAction->action_value = 'These are new notes ' . $this->randomInt();
$action = new SetNotes($ruleAction); $action = new SetNotes($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);
@@ -68,13 +68,13 @@ class SetNotesTest extends TestCase
public function testActNoNotes(): void public function testActNoNotes(): void
{ {
// give journal a note: // give journal a note:
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->forceDelete(); $journal->notes()->forceDelete();
$this->assertEquals(0, $journal->notes()->count()); $this->assertEquals(0, $journal->notes()->count());
// fire the action: // fire the action:
$ruleAction = new RuleAction; $ruleAction = new RuleAction;
$ruleAction->action_value = 'These are new notes ' . random_int(1, 1234); $ruleAction->action_value = 'These are new notes ' . $this->randomInt();
$action = new SetNotes($ruleAction); $action = new SetNotes($ruleAction);
$result = $action->act($journal); $result = $action->act($journal);
$this->assertTrue($result); $this->assertTrue($result);

View File

@@ -43,9 +43,6 @@ class SetSourceAccountTest extends TestCase
*/ */
public function testActDepositExistingUpdated(): void public function testActDepositExistingUpdated(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
$sourceTr = $deposit->transactions()->where('amount', '<', 0)->first(); $sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
@@ -80,11 +77,8 @@ class SetSourceAccountTest extends TestCase
*/ */
public function testActDepositRevenue(): void public function testActDepositRevenue(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 5)->first(); $account = $this->getRandomRevenue();
$deposit = $this->getRandomDeposit(); $deposit = $this->getRandomDeposit();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser');
@@ -106,9 +100,6 @@ class SetSourceAccountTest extends TestCase
*/ */
public function testActWithdrawalExistingUpdated(): void public function testActWithdrawalExistingUpdated(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
@@ -144,9 +135,6 @@ class SetSourceAccountTest extends TestCase
*/ */
public function testActWithdrawalNotExisting(): void public function testActWithdrawalNotExisting(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal(); $withdrawal = $this->getRandomWithdrawal();
@@ -160,30 +148,4 @@ class SetSourceAccountTest extends TestCase
$result = $action->act($withdrawal); $result = $action->act($withdrawal);
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* Test this on a split journal.
*
* @covers \FireflyIII\TransactionRules\Actions\SetSourceAccount
*/
public function testSplitJournal(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id')
->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')])
->first();
$journal = TransactionJournal::find($transaction->transaction_journal_id);
// mock
$accountRepos->shouldReceive('setUser');
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = 'Some new asset ' . $this->randomInt();
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
}
} }

View File

@@ -37,8 +37,8 @@ class HasAnyCategoryTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$category = $journal->user->categories()->first(); $category = $this->getRandomCategory();;
$journal->categories()->detach(); $journal->categories()->detach();
$journal->categories()->save($category); $journal->categories()->save($category);
@@ -53,7 +53,7 @@ class HasAnyCategoryTest extends TestCase
*/ */
public function testTriggeredNot(): void public function testTriggeredNot(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->categories()->detach(); $journal->categories()->detach();
// also detach transactions: // also detach transactions:

View File

@@ -36,7 +36,7 @@ class HasAnyTagTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$tag = $journal->user->tags()->first(); $tag = $journal->user->tags()->first();
$journal->tags()->detach(); $journal->tags()->detach();
$journal->tags()->save($tag); $journal->tags()->save($tag);
@@ -52,7 +52,7 @@ class HasAnyTagTest extends TestCase
*/ */
public function testTriggeredNot(): void public function testTriggeredNot(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->tags()->detach(); $journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count()); $this->assertEquals(0, $journal->tags()->count());
$trigger = HasAnyTag::makeFromStrings('', false); $trigger = HasAnyTag::makeFromStrings('', false);

View File

@@ -38,7 +38,7 @@ class HasNoBudgetTest extends TestCase
public function testTriggeredBudget(): void public function testTriggeredBudget(): void
{ {
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first(); $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first(); $budget = $this->getRandomBudget();
$journal->budgets()->detach(); $journal->budgets()->detach();
$journal->budgets()->save($budget); $journal->budgets()->save($budget);
$this->assertEquals(1, $journal->budgets()->count()); $this->assertEquals(1, $journal->budgets()->count());

View File

@@ -37,8 +37,8 @@ class HasNoCategoryTest extends TestCase
*/ */
public function testTriggeredCategory(): void public function testTriggeredCategory(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$category = $journal->user->categories()->first(); $category = $this->getRandomCategory();;
$journal->categories()->detach(); $journal->categories()->detach();
$journal->categories()->save($category); $journal->categories()->save($category);
$this->assertEquals(1, $journal->categories()->count()); $this->assertEquals(1, $journal->categories()->count());
@@ -53,7 +53,7 @@ class HasNoCategoryTest extends TestCase
*/ */
public function testTriggeredNoCategory(): void public function testTriggeredNoCategory(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->categories()->detach(); $journal->categories()->detach();
// also detach transactions: // also detach transactions:

View File

@@ -36,7 +36,7 @@ class HasNoTagTest extends TestCase
*/ */
public function testTriggeredNoTag(): void public function testTriggeredNoTag(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->tags()->detach(); $journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count()); $this->assertEquals(0, $journal->tags()->count());
@@ -50,7 +50,7 @@ class HasNoTagTest extends TestCase
*/ */
public function testTriggeredTag(): void public function testTriggeredTag(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$tag = $journal->user->tags()->first(); $tag = $journal->user->tags()->first();
$journal->tags()->detach(); $journal->tags()->detach();
$journal->tags()->save($tag); $journal->tags()->save($tag);

View File

@@ -37,7 +37,7 @@ class NotesAnyTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesAnyTest extends TestCase
*/ */
public function testTriggeredEmpty(): void public function testTriggeredEmpty(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesAnyTest extends TestCase
*/ */
public function testTriggeredNone(): void public function testTriggeredNone(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$trigger = NotesAny::makeFromStrings('', false); $trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);

View File

@@ -37,7 +37,7 @@ class NotesAreTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesAreTest extends TestCase
*/ */
public function testTriggeredDifferent(): void public function testTriggeredDifferent(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesAreTest extends TestCase
*/ */
public function testTriggeredEmpty(): void public function testTriggeredEmpty(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -85,7 +85,7 @@ class NotesAreTest extends TestCase
*/ */
public function testTriggeredNone(): void public function testTriggeredNone(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$trigger = NotesAre::makeFromStrings('Bla bla', false); $trigger = NotesAre::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);

View File

@@ -37,7 +37,7 @@ class NotesContainTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesContainTest extends TestCase
*/ */
public function testTriggeredDifferent(): void public function testTriggeredDifferent(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesContainTest extends TestCase
*/ */
public function testTriggeredEmpty(): void public function testTriggeredEmpty(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -85,7 +85,7 @@ class NotesContainTest extends TestCase
*/ */
public function testTriggeredNone(): void public function testTriggeredNone(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$trigger = NotesContain::makeFromStrings('Bla bla', false); $trigger = NotesContain::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
@@ -97,7 +97,7 @@ class NotesContainTest extends TestCase
*/ */
public function testTriggeredPartial(): void public function testTriggeredPartial(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesEmptyTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$trigger = NotesEmpty::makeFromStrings('', false); $trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
@@ -49,7 +49,7 @@ class NotesEmptyTest extends TestCase
*/ */
public function testTriggeredEmpty(): void public function testTriggeredEmpty(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -65,7 +65,7 @@ class NotesEmptyTest extends TestCase
*/ */
public function testTriggeredPartial(): void public function testTriggeredPartial(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesEndTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesEndTest extends TestCase
*/ */
public function testTriggeredLonger(): void public function testTriggeredLonger(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesEndTest extends TestCase
*/ */
public function testTriggeredNoMatch(): void public function testTriggeredNoMatch(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class NotesStartTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -53,7 +53,7 @@ class NotesStartTest extends TestCase
*/ */
public function testTriggeredLonger(): void public function testTriggeredLonger(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
@@ -69,7 +69,7 @@ class NotesStartTest extends TestCase
*/ */
public function testTriggeredNoMatch(): void public function testTriggeredNoMatch(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->notes()->delete(); $journal->notes()->delete();
$note = new Note(); $note = new Note();
$note->noteable()->associate($journal); $note->noteable()->associate($journal);

View File

@@ -37,7 +37,7 @@ class TagIsTest extends TestCase
*/ */
public function testNotTriggered(): void public function testNotTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->tags()->detach(); $journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count()); $this->assertEquals(0, $journal->tags()->count());
@@ -51,7 +51,7 @@ class TagIsTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$journal->tags()->detach(); $journal->tags()->detach();
/** @var Collection $tags */ /** @var Collection $tags */
$tags = $journal->user->tags()->take(3)->get(); $tags = $journal->user->tags()->take(3)->get();

View File

@@ -82,7 +82,7 @@ class ToAccountEndsTest extends TestCase
$collection = new Collection([$account]); $collection = new Collection([$account]);
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection); $repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 1234), false); $trigger = ToAccountEnds::makeFromStrings((string)$this->randomInt(), false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
$this->assertFalse($result); $this->assertFalse($result);
} }

View File

@@ -36,7 +36,7 @@ class TransactionTypeTest extends TestCase
*/ */
public function testTriggered(): void public function testTriggered(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$type = $journal->transactionType->type; $type = $journal->transactionType->type;
$trigger = TransactionType::makeFromStrings($type, false); $trigger = TransactionType::makeFromStrings($type, false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
@@ -48,7 +48,7 @@ class TransactionTypeTest extends TestCase
*/ */
public function testTriggeredFalse(): void public function testTriggeredFalse(): void
{ {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first(); $journal = $this->getRandomWithdrawal();
$trigger = TransactionType::makeFromStrings('NonExisting', false); $trigger = TransactionType::makeFromStrings('NonExisting', false);
$result = $trigger->triggered($journal); $result = $trigger->triggered($journal);
$this->assertFalse($result); $this->assertFalse($result);