mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test coverage.
This commit is contained in:
@@ -57,17 +57,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $types): int
|
||||
{
|
||||
return $this->user->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
@@ -87,6 +76,17 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $types): int
|
||||
{
|
||||
return $this->user->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param array $types
|
||||
@@ -97,7 +97,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts()
|
||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||
->where('account_meta.name', 'accountNumber')
|
||||
->where('account_meta.name', 'account_number')
|
||||
->where('account_meta.data', json_encode($number));
|
||||
|
||||
if (count($types) > 0) {
|
||||
@@ -298,30 +298,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $factory->findOrCreate('Cash account', $type->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $account
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInterestPerDay(Account $account): string
|
||||
{
|
||||
$interest = $this->getMetaValue($account, 'interest');
|
||||
$interestPeriod = $this->getMetaValue($account, 'interest_period');
|
||||
Log::debug(sprintf('Start with interest of %s percent', $interest));
|
||||
|
||||
// calculate
|
||||
if ('monthly' === $interestPeriod) {
|
||||
$interest = bcdiv(bcmul($interest, '12'), '365'); // per year
|
||||
Log::debug(sprintf('Interest is now (monthly to daily) %s percent', $interest));
|
||||
}
|
||||
if ('yearly' === $interestPeriod) {
|
||||
$interest = bcdiv($interest, '365'); // per year
|
||||
Log::debug(sprintf('Interest is now (yearly to daily) %s percent', $interest));
|
||||
}
|
||||
|
||||
return $interest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return meta value for account. Null if not found.
|
||||
*
|
||||
@@ -444,18 +420,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAsset(Account $account): bool
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
|
||||
return AccountType::ASSET === $type || AccountType::DEFAULT === $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
@@ -466,47 +430,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return in_array($account->accountType->type, [AccountType::CREDITCARD, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function latestJournal(Account $account): ?TransactionJournal
|
||||
{
|
||||
$first = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->first(['transaction_journals.id']);
|
||||
if (null !== $first) {
|
||||
return TransactionJournal::find((int)$first->id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function latestJournalDate(Account $account): ?Carbon
|
||||
{
|
||||
$result = null;
|
||||
$journal = $this->latestJournal($account);
|
||||
if (null !== $journal) {
|
||||
$result = $journal->date;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
@@ -581,7 +504,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(array $data): Account
|
||||
{
|
||||
@@ -597,7 +520,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
* @throws FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user