Improve test results.

This commit is contained in:
James Cole
2018-09-27 06:26:03 +02:00
parent 6c4f967c39
commit 214c7a6f3e
5 changed files with 189 additions and 6 deletions

View File

@@ -41,6 +41,11 @@ use Log;
*/
class AccountFactory
{
/** @var User */
private $user;
use AccountServiceTrait;
/**
* Constructor.
*/
@@ -51,10 +56,6 @@ class AccountFactory
}
}
use AccountServiceTrait;
/** @var User */
private $user;
/**
* @param array $data
*
@@ -151,17 +152,23 @@ class AccountFactory
*/
public function findOrCreate(string $accountName, string $accountType): Account
{
Log::debug(sprintf('Searching for "%s" of type "%s"', $accountName, $accountType));
$type = AccountType::whereType($accountType)->first();
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get(['accounts.*']);
$return = null;
Log::debug(sprintf('Account type is #%d', $type->id));
/** @var Account $object */
foreach ($accounts as $object) {
if ($object->name === $accountName) {
Log::debug(sprintf('Found account #%d "%s".', $object->id, $object->name));
$return = $object;
break;
}
}
if (null === $return) {
Log::debug('Found nothing. Will create a new one.');
$return = $this->create(
[
'user_id' => $this->user->id,