Refactored API code surrounding accounts to make transformers mockable.

This commit is contained in:
James Cole
2018-12-15 07:59:49 +01:00
parent c54541b839
commit 1284f9cecc
9 changed files with 239 additions and 100 deletions

View File

@@ -27,6 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
@@ -51,7 +52,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function __construct()
{
if ('testing' === env('APP_ENV')) {
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
}
}
@@ -178,6 +179,31 @@ class AccountRepository implements AccountRepositoryInterface
return $this->user->accounts()->find($accountId);
}
/**
* @param Account $account
*
* @return TransactionCurrency|null
*/
public function getAccountCurrency(Account $account): ?TransactionCurrency
{
$currencyId = (int)$this->getMetaValue($account, 'currency_id');
if ($currencyId > 0) {
return TransactionCurrency::find($currencyId);
}
return null;
}
/**
* @param Account $account
*
* @return string
*/
public function getAccountType(Account $account): string
{
return $account->accountType->type;
}
/**
* Return account type or null if not found.
*