mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Improve test coverage.
This commit is contained in:
@@ -73,7 +73,6 @@ class AddTag implements ActionInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal->id));
|
||||
|
||||
return false;
|
||||
|
@@ -53,7 +53,7 @@ class ClearBudget implements ActionInterface
|
||||
$journal->budgets()->detach();
|
||||
$journal->touch();
|
||||
|
||||
// also remove categories from transactions:
|
||||
// also remove budgets from transactions (although no longer necessary)
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$transaction->budgets()->detach();
|
||||
|
@@ -39,6 +39,8 @@ class LinkToBill implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
@@ -65,13 +67,13 @@ class LinkToBill implements ActionInterface
|
||||
$journal->bill()->associate($bill);
|
||||
$journal->save();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ class RemoveTag implements ActionInterface
|
||||
|
||||
/**
|
||||
* Remove tag X
|
||||
*
|
||||
* TODO the filter is no longer necessary.
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
|
@@ -49,7 +49,8 @@ class SetBudget implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Set budget X
|
||||
* Set budget.
|
||||
* TODO the filter is no longer necessary.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
@@ -63,14 +64,14 @@ class SetBudget implements ActionInterface
|
||||
$search = $this->action->action_value;
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$budget = $budgets->filter(
|
||||
function (Budget $current) use ($search) {
|
||||
static function (Budget $current) use ($search) {
|
||||
return $current->name === $search;
|
||||
}
|
||||
)->first();
|
||||
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));
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
$journal->budgets()->detach();
|
||||
// set budget on transactions:
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$transaction->budgets()->sync([$budget->id]);
|
||||
}
|
||||
$journal->budgets()->sync([$budget->id]);
|
||||
$journal->touch();
|
||||
|
||||
return true;
|
||||
|
@@ -64,18 +64,11 @@ class SetCategory implements ActionInterface
|
||||
if (null === $category) {
|
||||
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));
|
||||
|
||||
return true;
|
||||
|
@@ -69,13 +69,6 @@ class SetDestinationAccount implements ActionInterface
|
||||
$this->journal = $journal;
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$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:
|
||||
$type = $journal->transactionType->type;
|
||||
|
||||
@@ -103,7 +96,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
// get destination transaction:
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $transaction) {
|
||||
return true;
|
||||
return true; // @codeCoverageIgnore
|
||||
}
|
||||
$transaction->account_id = $this->newDestinationAccount->id;
|
||||
$transaction->save();
|
||||
|
@@ -69,13 +69,6 @@ class SetSourceAccount implements ActionInterface
|
||||
$this->journal = $journal;
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$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:
|
||||
$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:
|
||||
@@ -102,9 +95,11 @@ class SetSourceAccount implements ActionInterface
|
||||
// get source transaction:
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $transaction) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::error(sprintf('Cannot change source account of journal #%d because no source transaction exists.', $journal->id));
|
||||
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$transaction->account_id = $this->newSourceAccount->id;
|
||||
$transaction->save();
|
||||
|
Reference in New Issue
Block a user