Some code optimisations.

This commit is contained in:
James Cole
2019-04-09 15:42:25 +02:00
parent 97726c3822
commit 80896b7181
37 changed files with 153 additions and 129 deletions

View File

@@ -48,42 +48,6 @@ class ConvertToDepositTest extends TestCase
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
* Convert a withdrawal to a deposit.
*
* @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
*/
public function testActWithdrawal()
{
$revenue = $this->getRandomRevenue();
$name = 'Random revenue #' . random_int(1, 10000);
$journal = $this->getRandomWithdrawal();
// journal is a withdrawal:
$this->assertEquals(TransactionType::WITHDRAWAL, $journal->transactionType->type);
// mock used stuff:
$factory = $this->mock(AccountFactory::class);
$factory->shouldReceive('setUser')->once();
$factory->shouldReceive('findOrCreate')->once()->withArgs([$name, AccountType::REVENUE])->andReturn($revenue);
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $name;
$action = new ConvertToDeposit($ruleAction);
try {
$result = $action->act($journal);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);
// journal is now a deposit.
$journal->refresh();
$this->assertEquals(TransactionType::DEPOSIT, $journal->transactionType->type);
}
/**
* Convert a transfer to a deposit.
*
@@ -120,5 +84,41 @@ class ConvertToDepositTest extends TestCase
$this->assertEquals(TransactionType::DEPOSIT, $journal->transactionType->type);
}
/**
* Convert a withdrawal to a deposit.
*
* @covers \FireflyIII\TransactionRules\Actions\ConvertToDeposit
*/
public function testActWithdrawal()
{
$revenue = $this->getRandomRevenue();
$name = 'Random revenue #' . random_int(1, 10000);
$journal = $this->getRandomWithdrawal();
// journal is a withdrawal:
$this->assertEquals(TransactionType::WITHDRAWAL, $journal->transactionType->type);
// mock used stuff:
$factory = $this->mock(AccountFactory::class);
$factory->shouldReceive('setUser')->once();
$factory->shouldReceive('findOrCreate')->once()->withArgs([$name, AccountType::REVENUE])->andReturn($revenue);
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $name;
$action = new ConvertToDeposit($ruleAction);
try {
$result = $action->act($journal);
} catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);
// journal is now a deposit.
$journal->refresh();
$this->assertEquals(TransactionType::DEPOSIT, $journal->transactionType->type);
}
}