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

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