Improve code for test coverage

This commit is contained in:
James Cole
2018-02-16 22:14:53 +01:00
parent 278b7ac52b
commit 9cc1bfb4b5
7 changed files with 75 additions and 64 deletions

View File

@@ -240,56 +240,6 @@ class Account extends Model
return $journal;
}
/**
* Returns the amount of the opening balance for this account.
*
* @return string
*
* @throws FireflyException
*/
public function getOpeningBalanceAmount(): string
{
$journal = TransactionJournal::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (null === $journal) {
return '0';
}
$count = $journal->transactions()->count();
if (2 !== $count) {
throw new FireflyException(sprintf('Cannot use getFirstTransaction on journal #%d', $journal->id));
}
$transaction = $journal->transactions()->where('account_id', $this->id)->first();
if (null === $transaction) {
return '0';
}
return strval($transaction->amount);
}
/**
* Returns the date of the opening balance for this account. If no date, will return 01-01-1900.
*
* @return Carbon
*/
public function getOpeningBalanceDate(): Carbon
{
$date = new Carbon('1900-01-01');
$journal = TransactionJournal::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (null === $journal) {
return $date;
}
return $journal->date;
}
/**
* @codeCoverageIgnore
* Get all of the notes.

View File

@@ -41,7 +41,7 @@ class Note extends Model
'deleted_at' => 'datetime',
];
/** @var array */
protected $fillable = ['title', 'text'];
protected $fillable = ['title', 'text', 'noteable_id', 'noteable_type'];
/**
* @codeCoverageIgnore