mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-08 15:05:29 +00:00
Expand factory tests.
This commit is contained in:
@@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Exception;
|
||||
use FireflyIII\Factory\AccountFactory;
|
||||
use FireflyIII\Factory\AccountMetaFactory;
|
||||
use FireflyIII\Factory\TransactionFactory;
|
||||
@@ -57,7 +57,6 @@ trait AccountServiceTrait
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteIB(Account $account): bool
|
||||
{
|
||||
@@ -67,7 +66,11 @@ trait AccountServiceTrait
|
||||
// opening balance data? update it!
|
||||
if (null !== $openingBalance) {
|
||||
Log::debug('Opening balance journal found, delete journal.');
|
||||
$openingBalance->delete();
|
||||
try {
|
||||
$openingBalance->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('Could not delete opening balance: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -126,7 +129,6 @@ trait AccountServiceTrait
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function storeIBJournal(Account $account, array $data): ?TransactionJournal
|
||||
{
|
||||
@@ -233,8 +235,6 @@ trait AccountServiceTrait
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateIB(Account $account, array $data): bool
|
||||
{
|
||||
@@ -266,8 +266,6 @@ trait AccountServiceTrait
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
|
||||
{
|
||||
@@ -279,7 +277,12 @@ trait AccountServiceTrait
|
||||
Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount));
|
||||
if (0 === bccomp($amount, '0')) {
|
||||
Log::notice(sprintf('Amount "%s" is zero, delete opening balance.', $amount));
|
||||
$journal->delete();
|
||||
try {
|
||||
$journal->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('Could not delete opening balance: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ use FireflyIII\Models\Note;
|
||||
*/
|
||||
trait BillServiceTrait
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param string $note
|
||||
|
||||
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Factory\BillFactory;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
||||
@@ -74,7 +73,7 @@ trait JournalServiceTrait
|
||||
$factory->setUser($journal->user);
|
||||
$set = [];
|
||||
if (!is_array($data['tags'])) {
|
||||
return;
|
||||
return; // @codeCoverageIgnore
|
||||
}
|
||||
foreach ($data['tags'] as $string) {
|
||||
if (strlen($string) > 0) {
|
||||
@@ -102,11 +101,7 @@ trait JournalServiceTrait
|
||||
];
|
||||
/** @var TransactionJournalMetaFactory $factory */
|
||||
$factory = app(TransactionJournalMetaFactory::class);
|
||||
try {
|
||||
$factory->updateOrCreate($set);
|
||||
} catch (Exception $e) {
|
||||
// don't care
|
||||
}
|
||||
$factory->updateOrCreate($set);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,8 +24,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\AccountFactory;
|
||||
use FireflyIII\Factory\BudgetFactory;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
@@ -39,6 +37,7 @@ use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Trait TransactionServiceTrait
|
||||
@@ -53,7 +52,6 @@ trait TransactionServiceTrait
|
||||
* @param string $direction
|
||||
*
|
||||
* @return string|null
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function accountType(TransactionJournal $journal, string $direction): ?string
|
||||
{
|
||||
@@ -61,7 +59,11 @@ trait TransactionServiceTrait
|
||||
$type = $journal->transactionType->type;
|
||||
switch ($type) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot handle type "%s" in accountType()', $type));
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::error(sprintf('Cannot handle type "%s" in accountType()', $type));
|
||||
|
||||
return null;
|
||||
// @codeCoverageIgnoreEnd
|
||||
case TransactionType::WITHDRAWAL:
|
||||
$types['source'] = AccountType::ASSET;
|
||||
$types['destination'] = AccountType::EXPENSE;
|
||||
@@ -83,20 +85,22 @@ trait TransactionServiceTrait
|
||||
return $types[$direction];
|
||||
}
|
||||
if (!isset($types[$direction])) {
|
||||
throw new FireflyException(sprintf('No type set for direction "%s" and type "%s"', $type, $direction));
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::error(sprintf('No type set for direction "%s" and type "%s"', $type, $direction));
|
||||
|
||||
return null;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $types[$direction];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $expectedType
|
||||
* @param string|null $expectedType
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): Account
|
||||
{
|
||||
@@ -105,7 +109,7 @@ trait TransactionServiceTrait
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
if(is_null($expectedType)) {
|
||||
if (is_null($expectedType)) {
|
||||
return $repository->findNull($accountId);
|
||||
}
|
||||
|
||||
@@ -153,7 +157,11 @@ trait TransactionServiceTrait
|
||||
return $repository->getCashAccount();
|
||||
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot find account of type "%s".', $expectedType));
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::error(sprintf('Cannot find account of type "%s".', $expectedType));
|
||||
|
||||
return null;
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
}
|
||||
}
|
||||
@@ -233,7 +241,7 @@ trait TransactionServiceTrait
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @param string|null $amount
|
||||
* @param string|null $amount
|
||||
*/
|
||||
protected function setForeignAmount(Transaction $transaction, ?string $amount): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user