mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test results.
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user