mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test coverage.
This commit is contained in:
@@ -53,7 +53,6 @@ trait BasicDataSupport
|
||||
unset($data[$entryId]);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@@ -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));
|
||||
|
||||
|
@@ -228,19 +228,12 @@ class ImportableConverter
|
||||
{
|
||||
$type = 'unknown';
|
||||
|
||||
if ($source === AccountType::ASSET && $destination === AccountType::ASSET) {
|
||||
Log::debug('Source and destination are asset accounts. This is a transfer.');
|
||||
$type = 'transfer';
|
||||
}
|
||||
if ($source === AccountType::REVENUE) {
|
||||
Log::debug('Source is a revenue account. This is a deposit.');
|
||||
$type = 'deposit';
|
||||
}
|
||||
if ($destination === AccountType::EXPENSE) {
|
||||
Log::debug('Destination is an expense account. This is a withdrawal.');
|
||||
$type = 'withdrawal';
|
||||
}
|
||||
$newType = config(sprintf('firefly.account_to_transaction.%s.%s', $source, $destination));
|
||||
if (null !== $newType) {
|
||||
Log::debug(sprintf('Source is %s, destination is %s, so this is a %s.', $source, $destination, $newType));
|
||||
|
||||
return (string)$newType;
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
@@ -60,15 +60,19 @@ class OpposingAccountMapper
|
||||
Log::debug(sprintf('Because amount is %s, will instead search for accounts of type %s', $amount, $expectedType));
|
||||
}
|
||||
|
||||
// append expected types with liability types:
|
||||
$expectedTypes = [$expectedType, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||
|
||||
|
||||
if ((int)$accountId > 0) {
|
||||
// find any account with this ID:
|
||||
$result = $this->repository->findNull($accountId);
|
||||
if (null !== $result && ($result->accountType->type === $expectedType || $result->accountType->type === AccountType::ASSET)) {
|
||||
if (null !== $result && (in_array($result->accountType->type, $expectedTypes, true) || $result->accountType->type === AccountType::ASSET)) {
|
||||
Log::debug(sprintf('Found account "%s" (%s) based on given ID %d. Return it!', $result->name, $result->accountType->type, $accountId));
|
||||
|
||||
return $result;
|
||||
}
|
||||
if (null !== $result && $result->accountType->type !== $expectedType) {
|
||||
if (null !== $result && !in_array($result->accountType->type, $expectedTypes, true)) {
|
||||
Log::warning(
|
||||
sprintf(
|
||||
'Found account "%s" (%s) based on given ID %d, but need a %s. Return nothing.', $result->name, $result->accountType->type, $accountId,
|
||||
@@ -90,7 +94,7 @@ class OpposingAccountMapper
|
||||
}
|
||||
|
||||
// first search for $expectedType, then find asset:
|
||||
$searchTypes = [$expectedType, AccountType::ASSET];
|
||||
$searchTypes = [$expectedType, AccountType::ASSET, AccountType::DEBT, AccountType::MORTGAGE, AccountType::LOAN];
|
||||
foreach ($searchTypes as $type) {
|
||||
// find by (respectively):
|
||||
// IBAN, accountNumber, name,
|
||||
|
@@ -174,35 +174,33 @@ class StageImportDataHandler
|
||||
}
|
||||
|
||||
$entry = [
|
||||
'type' => $type,
|
||||
'date' => $transaction->getMadeOn()->format('Y-m-d'),
|
||||
'tags' => $tags,
|
||||
'user' => $this->importJob->user_id,
|
||||
'notes' => $notes,
|
||||
|
||||
// all custom fields:
|
||||
'external_id' => (string)$transaction->getId(),
|
||||
|
||||
// journal data:
|
||||
'description' => $transaction->getDescription(),
|
||||
'piggy_bank_id' => null,
|
||||
'piggy_bank_name' => null,
|
||||
'bill_id' => null,
|
||||
'bill_name' => null,
|
||||
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
|
||||
|
||||
// transaction data:
|
||||
'transactions' => [
|
||||
[
|
||||
'currency_id' => null,
|
||||
'currency_code' => $currencyCode,
|
||||
'description' => null,
|
||||
'amount' => $amount,
|
||||
'budget_id' => null,
|
||||
'budget_name' => null,
|
||||
'category_id' => null,
|
||||
'category_name' => $transaction->getCategory(),
|
||||
'source_id' => $source->id,
|
||||
'date' => $transaction->getMadeOn()->format('Y-m-d'),
|
||||
'tags' => $tags,
|
||||
'user' => $this->importJob->user_id,
|
||||
'notes' => $notes,
|
||||
|
||||
// all custom fields:
|
||||
'external_id' => (string)$transaction->getId(),
|
||||
|
||||
// journal data:
|
||||
'description' => $transaction->getDescription(),
|
||||
'piggy_bank_id' => null,
|
||||
'piggy_bank_name' => null,
|
||||
'bill_id' => null,
|
||||
'bill_name' => null,
|
||||
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
|
||||
'type' => $type,
|
||||
'currency_id' => null,
|
||||
'currency_code' => $currencyCode,
|
||||
'amount' => $amount,
|
||||
'budget_id' => null,
|
||||
'budget_name' => null,
|
||||
'category_id' => null,
|
||||
'category_name' => $transaction->getCategory(),
|
||||
'source_id' => $source->id,
|
||||
'source_name' => null,
|
||||
'destination_id' => $destination->id,
|
||||
'destination_name' => null,
|
||||
|
@@ -25,7 +25,6 @@ namespace FireflyIII\Support;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Navigation.
|
||||
@@ -307,16 +306,15 @@ class Navigation
|
||||
$displayFormat = (string)trans('config.year');
|
||||
}
|
||||
|
||||
|
||||
$begin = clone $start;
|
||||
$entries = [];
|
||||
while ($begin < $end) {
|
||||
$formatted = $begin->format($format);
|
||||
$displayed = $begin->formatLocalized($displayFormat);
|
||||
$entries[$formatted] = $displayed;
|
||||
|
||||
$begin->$increment();
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user