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:
@@ -33,6 +33,7 @@ use Preferences as Prefs;
|
||||
|
||||
/**
|
||||
* Class Amount.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Amount
|
||||
{
|
||||
|
@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class CacheProperties.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CacheProperties
|
||||
{
|
||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
|
||||
|
||||
/**
|
||||
* Class ChartColour.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ChartColour
|
||||
{
|
||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Cronjobs;
|
||||
|
||||
/**
|
||||
* Class AbstractCronjob
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
abstract class AbstractCronjob
|
||||
{
|
||||
|
@@ -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'));
|
||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
|
||||
|
||||
/**
|
||||
* Class Domain.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Domain
|
||||
{
|
||||
|
@@ -48,6 +48,7 @@ use Throwable;
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ExpandedForm
|
||||
{
|
||||
|
@@ -27,7 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
/**
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* Class FinTS
|
||||
*/
|
||||
class FinTS
|
||||
|
@@ -29,6 +29,7 @@ use Log;
|
||||
|
||||
/**
|
||||
* Class FireflyConfig.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FireflyConfig
|
||||
{
|
||||
|
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Trait ApiSupport
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
trait ApiSupport
|
||||
{
|
||||
|
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ use Log;
|
||||
|
||||
/**
|
||||
* Trait GetSpectreCustomerTrait
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
trait GetSpectreCustomerTrait
|
||||
{
|
||||
|
@@ -31,7 +31,7 @@ use Log;
|
||||
|
||||
/**
|
||||
* Trait GetSpectreTokenTrait
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
trait GetSpectreTokenTrait
|
||||
{
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -34,8 +34,8 @@ use FireflyIII\Support\FinTS\FinTS;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ChooseAccountHandler
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ChooseAccountHandler implements FinTSConfigurationInterface
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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];
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
];
|
||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
|
||||
|
||||
/**
|
||||
* Class AuditLogger
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AuditLogger
|
||||
{
|
||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
|
||||
|
||||
/**
|
||||
* Class AuditProcessor
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AuditProcessor
|
||||
{
|
||||
|
@@ -26,6 +26,10 @@ namespace FireflyIII\Support;
|
||||
|
||||
use ArrayObject;
|
||||
|
||||
/**
|
||||
* Class NullArrayObject
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class NullArrayObject extends ArrayObject
|
||||
{
|
||||
public $default = null;
|
||||
|
@@ -32,6 +32,7 @@ use Session;
|
||||
|
||||
/**
|
||||
* Class Preferences.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Preferences
|
||||
{
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -33,6 +33,7 @@ use stdClass;
|
||||
|
||||
/**
|
||||
* Class Steam.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Steam
|
||||
{
|
||||
|
Reference in New Issue
Block a user