mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Improve test coverage.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user