Improve test coverage.

This commit is contained in:
James Cole
2019-08-02 05:25:24 +02:00
parent 4bd8e1b11e
commit fc70afa3ea
23 changed files with 202 additions and 57923 deletions

View File

@@ -31,6 +31,7 @@ use Log;
/**
* Class AssetAccountMapper
* Can also handle liability accounts.
*/
class AssetAccountMapper
{
@@ -41,6 +42,17 @@ class AssetAccountMapper
/** @var User */
private $user;
/** @var array */
private $types;
/**
* AssetAccountMapper constructor.
*/
public function __construct()
{
$this->types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
}
/**
* Based upon data in the importable, try to find or create the asset account account.
*
@@ -56,12 +68,12 @@ class AssetAccountMapper
if ((int)$accountId > 0) {
// find asset account with this ID:
$result = $this->repository->findNull($accountId);
if (null !== $result && $result->accountType->type === AccountType::ASSET) {
Log::debug(sprintf('Found asset account "%s" based on given ID %d', $result->name, $accountId));
if (null !== $result && in_array($result->accountType->type, $this->types, true)) {
Log::debug(sprintf('Found %s "%s" based on given ID %d', $result->accountType->type, $result->name, $accountId));
return $result;
}
if (null !== $result && $result->accountType->type !== AccountType::ASSET) {
if (null !== $result && in_array($result->accountType->type, $this->types, true)) {
Log::warning(
sprintf('Found account "%s" based on given ID %d but its a %s, return nothing.', $result->name, $accountId, $result->accountType->type)
);
@@ -76,8 +88,8 @@ class AssetAccountMapper
Log::debug(sprintf('Array does not contain a value for %s. Continue', $field));
continue;
}
$result = $this->repository->$function($value, [AccountType::ASSET]);
Log::debug(sprintf('Going to run %s() with argument "%s" (asset account)', $function, $value));
$result = $this->repository->$function($value, $this->types);
Log::debug(sprintf('Going to run %s() with argument "%s" (asset account or liability)', $function, $value));
if (null !== $result) {
Log::debug(sprintf('Found asset account "%s". Return it!', $result->name));