Refactor journal repository and fix tests.

This commit is contained in:
James Cole
2019-08-10 13:42:33 +02:00
parent b7f3c53688
commit 93f1854be0
14 changed files with 286 additions and 130 deletions

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetBudget;
use Illuminate\Support\Collection;
@@ -42,9 +41,6 @@ class SetBudgetTest extends TestCase
// 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([$budget]));
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
@@ -65,17 +61,13 @@ class SetBudgetTest extends TestCase
{
// 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;
$ruleAction->action_value = 'non-existing budget #' . $this->randomInt();
$action = new SetBudget($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
@@ -91,9 +83,6 @@ class SetBudgetTest extends TestCase
// get journal, remove all budgets
$journal = $this->getRandomDeposit();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());