Improve test coverage.

This commit is contained in:
James Cole
2019-07-31 16:53:09 +02:00
parent 5524941c90
commit 9b574ce7ad
155 changed files with 1890 additions and 2263 deletions

View File

@@ -33,6 +33,7 @@ use Preferences as Prefs;
/**
* Class Amount.
* @codeCoverageIgnore
*/
class Amount
{

View File

@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
/**
* Class CacheProperties.
* @codeCoverageIgnore
*/
class CacheProperties
{

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
/**
* Class ChartColour.
* @codeCoverageIgnore
*/
class ChartColour
{

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Cronjobs;
/**
* Class AbstractCronjob
* @codeCoverageIgnore
*/
abstract class AbstractCronjob
{

View File

@@ -99,13 +99,7 @@ class RecurringCronjob extends AbstractCronjob
Log::info(sprintf('It has been %s since the recurring transactions cron-job has fired. It will fire now!', $diffForHumans));
}
try {
$this->fireRecurring();
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not run recurring transaction cron job: %s', $e->getMessage()));
}
$this->fireRecurring();
app('preferences')->mark();
@@ -114,12 +108,13 @@ class RecurringCronjob extends AbstractCronjob
/**
*
* @throws FireflyException
*/
private function fireRecurring(): void
{
Log::info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d')));
$job = new CreateRecurringTransactions($this->date);
/** @var CreateRecurringTransactions $job */
$job = app(CreateRecurringTransactions::class);
$job->setDate($this->date);
$job->setForce($this->force);
$job->handle();
app('fireflyconfig')->set('last_rt_job', (int)$this->date->format('U'));

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
/**
* Class Domain.
* @codeCoverageIgnore
*/
class Domain
{

View File

@@ -48,6 +48,7 @@ use Throwable;
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @codeCoverageIgnore
*/
class ExpandedForm
{

View File

@@ -27,7 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
use Illuminate\Support\Facades\Crypt;
/**
*
* @codeCoverageIgnore
* Class FinTS
*/
class FinTS

View File

@@ -29,6 +29,7 @@ use Log;
/**
* Class FireflyConfig.
* @codeCoverageIgnore
*/
class FireflyConfig
{

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\AccountType;
/**
* Trait AccountFilter
* @codeCoverageIgnore
*/
trait AccountFilter
{
@@ -78,10 +79,8 @@ trait AccountFilter
'credit-card' => [AccountType::CREDITCARD],
'creditcard' => [AccountType::CREDITCARD],
'cc' => [AccountType::CREDITCARD],
];
$return = $types[$type] ?? $types['all'];
return $return; // @codeCoverageIgnore
return $types[$type] ?? $types['all'];
}
}

View File

@@ -26,6 +26,7 @@ use Illuminate\Support\Collection;
/**
* Trait ApiSupport
* @codeCoverageIgnore
*/
trait ApiSupport
{

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionType;
/**
* Trait TransactionFilter
* @codeCoverageIgnore
*/
trait TransactionFilter
{
@@ -58,9 +59,8 @@ trait TransactionFilter
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER,],
];
$return = $types[$type] ?? $types['default'];
return $types[$type] ?? $types['default'];
return $return;
}
}

View File

@@ -32,7 +32,7 @@ use Log;
/**
* Trait GetSpectreCustomerTrait
*
* @codeCoverageIgnore
*/
trait GetSpectreCustomerTrait
{

View File

@@ -31,7 +31,7 @@ use Log;
/**
* Trait GetSpectreTokenTrait
*
* @codeCoverageIgnore
*/
trait GetSpectreTokenTrait
{

View File

@@ -119,7 +119,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
Log::debug(sprintf('IBAN for bunq account #%d is "%s"', $bunqId, $bunqIban));
if (null !== $bunqIban) {
$ibanToAsset[$bunqIban] = $accountId;
$ibanToAsset[$bunqIban] = $accountId; // @codeCoverageIgnore
}
$final[$bunqId] = $accountId;
}

View File

@@ -312,7 +312,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
asort($columnConfig[$columnIndex]['values']);
// if the count of this array is zero, there is nothing to map.
if (0 === count($columnConfig[$columnIndex]['values'])) {
unset($columnConfig[$columnIndex]);
unset($columnConfig[$columnIndex]); // @codeCoverageIgnore
}
}

View File

@@ -34,8 +34,8 @@ use FireflyIII\Support\FinTS\FinTS;
use Illuminate\Support\MessageBag;
/**
*
* Class ChooseAccountHandler
* @codeCoverageIgnore
*/
class ChooseAccountHandler implements FinTSConfigurationInterface
{

View File

@@ -32,8 +32,8 @@ use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\MessageBag;
/**
*
* Class NewFinTSJobHandler
* @codeCoverageIgnore
*/
class NewFinTSJobHandler implements FinTSConfigurationInterface
{
@@ -62,7 +62,6 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface
$this->repository->setConfiguration($this->importJob, $config);
$incomplete = false;
foreach ($config as $value) {
$incomplete = '' === $value or $incomplete;

View File

@@ -33,6 +33,7 @@ use Log;
/**
* Class ImportTransaction
* @codeCoverageIgnore
*/
class ImportTransaction
{
@@ -179,7 +180,7 @@ class ImportTransaction
'date-process' => 'date_process',
'date-due' => 'date_due',
];
if (in_array($role, array_keys($replaceOldRoles))) {
if (array_key_exists($role, $replaceOldRoles)) {
$role = $replaceOldRoles[$role];
}

View File

@@ -114,9 +114,9 @@ class OpposingAccountMapper
$creation = [
'name' => $data['name'] ?? '(no name)',
'iban' => $data['iban'] ?? null,
'accountNumber' => $data['number'] ?? null,
'account_number' => $data['number'] ?? null,
'account_type_id' => null,
'account_type' => $expectedType,
'account_type' => $expectedType,
'active' => true,
'BIC' => $data['bic'] ?? null,
];

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
/**
* Class AuditLogger
* @codeCoverageIgnore
*/
class AuditLogger
{

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
/**
* Class AuditProcessor
* @codeCoverageIgnore
*/
class AuditProcessor
{

View File

@@ -26,6 +26,10 @@ namespace FireflyIII\Support;
use ArrayObject;
/**
* Class NullArrayObject
* @codeCoverageIgnore
*/
class NullArrayObject extends ArrayObject
{
public $default = null;

View File

@@ -32,6 +32,7 @@ use Session;
/**
* Class Preferences.
* @codeCoverageIgnore
*/
class Preferences
{

View File

@@ -1,203 +0,0 @@
<?php
/**
* Modifier.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Search;
use Carbon\Carbon;
use Exception;
use FireflyIII\Models\Transaction;
use Log;
/**
* Class Modifier
*/
class Modifier
{
/**
* @param Transaction $transaction
* @param string $amount
* @param int $expected
*
* @return bool
*/
public static function amountCompare(Transaction $transaction, string $amount, int $expected): bool
{
$amount = app('steam')->positive($amount);
$transactionAmount = app('steam')->positive($transaction->transaction_amount);
$compare = bccomp($amount, $transactionAmount);
Log::debug(sprintf('%s vs %s is %d', $amount, $transactionAmount, $compare));
return $compare === $expected;
}
/**
* @param array $modifier
* @param Transaction $transaction
*
* @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public static function apply(array $modifier, Transaction $transaction): bool
{
$res = true;
switch ($modifier['type']) {
case 'source':
$name = $transaction->account_name;
$res = self::stringCompare($name, $modifier['value']);
Log::debug(sprintf('Source is %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'destination':
$name = $transaction->opposing_account_name;
$res = self::stringCompare($name, $modifier['value']);
Log::debug(sprintf('Destination is %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'category':
$res = self::category($transaction, $modifier['value']);
Log::debug(sprintf('Category is %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'budget':
$res = self::budget($transaction, $modifier['value']);
Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'bill':
$name = $transaction->bill_name;
$res = self::stringCompare($name, $modifier['value']);
Log::debug(sprintf('Bill is %s? %s', $modifier['value'], var_export($res, true)));
break;
}
return $res;
}
/**
* @param Carbon $date
* @param string $compare
*
* @return bool
*/
public static function dateAfter(Carbon $date, string $compare): bool
{
try {
$compareDate = new Carbon($compare);
} catch (Exception $e) {
Log::debug(sprintf('Not interesting in Modifier:dateAfter(): %s', $e->getMessage()));
return false;
}
return $date->greaterThanOrEqualTo($compareDate);
}
/**
* @param Carbon $date
* @param string $compare
*
* @return bool
*/
public static function dateBefore(Carbon $date, string $compare): bool
{
try {
$compareDate = new Carbon($compare);
} catch (Exception $e) {
Log::debug(sprintf('Not interesting in modifier:dateBefore(): %s', $e->getMessage()));
return false;
}
return $date->lessThanOrEqualTo($compareDate);
}
/**
* @param Carbon $date
* @param string $compare
*
* @return bool
*/
public static function sameDate(Carbon $date, string $compare): bool
{
try {
$compareDate = new Carbon($compare);
} catch (Exception $e) {
Log::debug(sprintf('Not interesting in Modifier:sameDate(): %s', $e->getMessage()));
return false;
}
return $compareDate->isSameDay($date);
}
/**
* @param string $haystack
* @param string $needle
*
* @return bool
*/
public static function stringCompare(string $haystack, string $needle): bool
{
$res = !(false === stripos($haystack, $needle));
Log::debug(sprintf('"%s" is in "%s"? %s', $needle, $haystack, var_export($res, true)));
return $res;
}
/**
* @param Transaction $transaction
* @param string $search
*
* @return bool
*/
private static function budget(Transaction $transaction, string $search): bool
{
$journalBudget = '';
if (null !== $transaction->transaction_journal_budget_name) {
$journalBudget = $transaction->transaction_journal_budget_name;
}
$transactionBudget = '';
if (null !== $transaction->transaction_budget_name) {
$journalBudget = $transaction->transaction_budget_name;
}
return self::stringCompare($journalBudget, $search) || self::stringCompare($transactionBudget, $search);
}
/**
* @param Transaction $transaction
* @param string $search
*
* @return bool
*/
private static function category(Transaction $transaction, string $search): bool
{
$journalCategory = '';
if (null !== $transaction->transaction_journal_category_name) {
$journalCategory = $transaction->transaction_journal_category_name;
}
$transactionCategory = '';
if (null !== $transaction->transaction_category_name) {
$journalCategory = $transaction->transaction_category_name;
}
return self::stringCompare($journalCategory, $search) || self::stringCompare($transactionCategory, $search);
}
}

View File

@@ -33,6 +33,7 @@ use stdClass;
/**
* Class Steam.
* @codeCoverageIgnore
*/
class Steam
{