Expand test coverage.

This commit is contained in:
James Cole
2019-07-26 17:48:24 +02:00
parent 6ff4a0b45c
commit d94d34ca63
57 changed files with 2243 additions and 1597 deletions

View File

@@ -111,6 +111,7 @@ class ImportArrayStorage
$count = 0;
foreach ($array as $index => $group) {
foreach ($group['transactions'] as $transaction) {
if (strtolower(TransactionType::TRANSFER) === strtolower($transaction['type'])) {
$count++;
@@ -213,7 +214,7 @@ class ImportArrayStorage
$collection = new Collection;
foreach ($array as $index => $group) {
Log::debug(sprintf('Now store #%d', ($index + 1)));
Log::debug(sprintf('Now store #%d', $index + 1));
$result = $this->storeGroup($index, $group);
if (null !== $result) {
$collection->push($result);
@@ -250,6 +251,7 @@ class ImportArrayStorage
// store the group
try {
$newGroup = $this->groupRepos->store($group);
// @codeCoverageIgnoreStart
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
@@ -257,6 +259,7 @@ class ImportArrayStorage
return null;
}
// @codeCoverageIgnoreEnd
Log::debug(sprintf('Stored as group #%d', $newGroup->id));
// add to collection of transfers, if necessary:
@@ -280,6 +283,7 @@ class ImportArrayStorage
*/
private function duplicateDetected(int $index, array $group): bool
{
Log::debug(sprintf('Now in duplicateDetected(%d)', $index));
$transactions = $group['transactions'] ?? [];
foreach ($transactions as $transaction) {
$hash = $this->getHash($transaction);
@@ -387,7 +391,7 @@ class ImportArrayStorage
*/
private function transferExists(array $transaction): bool
{
Log::debug('Check if transaction is a double transfer.');
Log::debug('transferExists() Check if transaction is a double transfer.');
// how many hits do we need?
Log::debug(sprintf('System has %d existing transfers', count($this->transfers)));
@@ -395,9 +399,11 @@ class ImportArrayStorage
// check if is a transfer
if (strtolower(TransactionType::TRANSFER) !== strtolower($transaction['type'])) {
// @codeCoverageIgnoreStart
Log::debug(sprintf('Is a %s, not a transfer so no.', $transaction['type']));
return false;
// @codeCoverageIgnoreEnd
}
@@ -411,7 +417,8 @@ class ImportArrayStorage
}
// get the description:
$description = '' === (string)$transaction['description'] ? $transaction['description'] : $transaction['description'];
//$description = '' === (string)$transaction['description'] ? $transaction['description'] : $transaction['description'];
$description = (string)$transaction['description'];
// get the source and destination ID's:
$transactionSourceIDs = [(int)$transaction['source_id'], (int)$transaction['destination_id']];
@@ -467,7 +474,7 @@ class ImportArrayStorage
++$hits;
Log::debug(sprintf('Source IDs are the same! (%d)', $hits));
}
if ($transactionSourceIDs !== $transactionSourceIDs) {
if ($transactionSourceIDs !== $transferSourceIDs) {
Log::debug('Source IDs are not the same.');
}
unset($transferSourceIDs);
@@ -566,12 +573,14 @@ class ImportArrayStorage
$tagId = $tag->id;
foreach ($journalIds as $journalId) {
Log::debug(sprintf('Linking journal #%d to tag #%d...', $journalId, $tagId));
// @codeCoverageIgnoreStart
try {
DB::table('tag_transaction_journal')->insert(['transaction_journal_id' => $journalId, 'tag_id' => $tagId]);
} catch (QueryException $e) {
Log::error(sprintf('Could not link journal #%d to tag #%d because: %s', $journalId, $tagId, $e->getMessage()));
Log::error($e->getTraceAsString());
}
// @codeCoverageIgnoreEnd
}
Log::info(sprintf('Linked %d journals to tag #%d ("%s")', $collection->count(), $tag->id, $tag->tag));
@@ -582,6 +591,8 @@ class ImportArrayStorage
/**
* Applies the users rules to the created journals.
*
* TODO this piece of code must be replaced with the rule engine for consistent processing.
* TODO double for-each is terrible.
* @param Collection $collection
*
*/
@@ -589,19 +600,21 @@ class ImportArrayStorage
{
$rules = $this->getRules();
if ($rules->count() > 0) {
foreach ($collection as $journal) {
/** @var TransactionGroup $group */
foreach ($collection as $group) {
$rules->each(
function (Rule $rule) use ($journal) {
Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
$journal->refresh();
if ($rule->stop_processing) {
return false;
static function (Rule $rule) use ($group) {
Log::debug(sprintf('Going to apply rule #%d to group %d.', $rule->id, $group->id));
foreach ($group->transactionJournals as $journal) {
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
$journal->refresh();
if ($rule->stop_processing) {
return false; // @codeCoverageIgnore
}
}
return true;
}
);