mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Expand test coverage.
This commit is contained in:
@@ -204,32 +204,6 @@ trait GetConfigurationData
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if forbidden functions are set.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasForbiddenFunctions(): bool // validate system config
|
||||
{
|
||||
$list = ['proc_close'];
|
||||
$forbidden = explode(',', ini_get('disable_functions'));
|
||||
$trimmed = array_map(
|
||||
function (string $value) {
|
||||
return trim($value);
|
||||
}, $forbidden
|
||||
);
|
||||
foreach ($list as $entry) {
|
||||
if (in_array($entry, $trimmed, true)) {
|
||||
Log::error('Method "%s" is FORBIDDEN, so the console command cannot be executed.');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -71,130 +71,6 @@ trait ModelInformation
|
||||
return [$result];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination account. Is complex.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionType $destinationType
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function getDestinationAccount(TransactionJournal $journal, TransactionType $destinationType, array $data
|
||||
): Account // helper for conversion. Get info from obj.
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
/** @var JournalRepositoryInterface $journalRepos */
|
||||
$journalRepos = app(JournalRepositoryInterface::class);
|
||||
$sourceAccount = $journalRepos->getJournalSourceAccounts($journal)->first();
|
||||
$destinationAccount = $journalRepos->getJournalDestinationAccounts($journal)->first();
|
||||
$sourceType = $journal->transactionType;
|
||||
$joined = $sourceType->type . '-' . $destinationType->type;
|
||||
switch ($joined) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
|
||||
// one
|
||||
$destination = $sourceAccount;
|
||||
break;
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
|
||||
// two
|
||||
$destination = $accountRepository->findNull((int)$data['destination_account_asset']);
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
|
||||
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
|
||||
// three and five
|
||||
if ('' === $data['destination_account_expense'] || null === $data['destination_account_expense']) {
|
||||
// destination is a cash account.
|
||||
return $accountRepository->getCashAccount();
|
||||
}
|
||||
$data = [
|
||||
'name' => $data['destination_account_expense'],
|
||||
'account_type' => 'expense',
|
||||
'account_type_id' => null,
|
||||
'virtual_balance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
];
|
||||
$destination = $accountRepository->store($data);
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
|
||||
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
|
||||
// four and six
|
||||
$destination = $destinationAccount;
|
||||
break;
|
||||
}
|
||||
|
||||
return $destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source account.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionType $destinationType
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
protected function getSourceAccount(TransactionJournal $journal, TransactionType $destinationType, array $data
|
||||
): Account // helper for conversion. Get info from obj.
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
/** @var JournalRepositoryInterface $journalRepos */
|
||||
$journalRepos = app(JournalRepositoryInterface::class);
|
||||
$sourceAccount = $journalRepos->getJournalSourceAccounts($journal)->first();
|
||||
$destinationAccount = $journalRepos->getJournalDestinationAccounts($journal)->first();
|
||||
$sourceType = $journal->transactionType;
|
||||
$joined = $sourceType->type . '-' . $destinationType->type;
|
||||
switch ($joined) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
|
||||
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
|
||||
|
||||
if ('' === $data['source_account_revenue'] || null === $data['source_account_revenue']) {
|
||||
// destination is a cash account.
|
||||
return $accountRepository->getCashAccount();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $data['source_account_revenue'],
|
||||
'account_type' => 'revenue',
|
||||
'virtual_balance' => 0,
|
||||
'active' => true,
|
||||
'account_type_id' => null,
|
||||
'iban' => null,
|
||||
];
|
||||
$source = $accountRepository->store($data);
|
||||
break;
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
|
||||
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
|
||||
$source = $sourceAccount;
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
|
||||
$source = $destinationAccount;
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
|
||||
$source = $accountRepository->findNull((int)$data['source_account_asset']);
|
||||
break;
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fake triggers to match the bill's properties
|
||||
*
|
||||
@@ -275,16 +151,4 @@ trait ModelInformation
|
||||
|
||||
return $liabilityTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is transaction opening balance?
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isOpeningBalance(TransactionJournal $journal): bool
|
||||
{
|
||||
return TransactionType::OPENING_BALANCE === $journal->transactionType->type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,45 +489,6 @@ trait PeriodOverview
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the sum per currency.
|
||||
*
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function sumPerCurrency(Collection $collection): array // helper for transactions (math, calculations)
|
||||
{
|
||||
$return = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
|
||||
// save currency information:
|
||||
if (!isset($return[$currencyId])) {
|
||||
$currencySymbol = $transaction->transaction_currency_symbol;
|
||||
$decimalPlaces = $transaction->transaction_currency_dp;
|
||||
$currencyCode = $transaction->transaction_currency_code;
|
||||
$return[$currencyId] = [
|
||||
'currency' => [
|
||||
'id' => $currencyId,
|
||||
'code' => $currencyCode,
|
||||
'symbol' => $currencySymbol,
|
||||
'dp' => $decimalPlaces,
|
||||
],
|
||||
'sum' => '0',
|
||||
'count' => 0,
|
||||
];
|
||||
}
|
||||
// save amount:
|
||||
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], $transaction->transaction_amount);
|
||||
++$return[$currencyId]['count'];
|
||||
}
|
||||
asort($return);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
* @param Account $account
|
||||
@@ -552,6 +513,7 @@ trait PeriodOverview
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
@@ -591,6 +553,7 @@ trait PeriodOverview
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
@@ -635,53 +598,4 @@ trait PeriodOverview
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @return array
|
||||
*/
|
||||
private function getJournalsSum(array $journals): array
|
||||
{
|
||||
$return = [
|
||||
'count' => 0,
|
||||
'sums' => [],
|
||||
];
|
||||
if (0 === count($journals)) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
foreach ($journals as $row) {
|
||||
$return['count']++;
|
||||
$currencyId = (int)$row['currency_id'];
|
||||
if (!isset($return['sums'][$currencyId])) {
|
||||
$return['sums'][$currencyId] = [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $row['currency_code'],
|
||||
'currency_symbol' => $row['currency_symbol'],
|
||||
'currency_name' => $row['currency_name'],
|
||||
'currency_decimal_places' => (int)$row['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
// add amounts:
|
||||
$return['sums'][$currencyId]['sum'] = bcadd($return['sums'][$currencyId]['sum'], (string)$row['amount']);
|
||||
|
||||
// same but for foreign amounts:
|
||||
if (null !== $row['foreign_currency_id'] && 0 !== $row['foreign_currency_id']) {
|
||||
$foreignCurrencyId = (int)$row['foreign_currency_id'];
|
||||
$return['sums'][$foreignCurrencyId] = [
|
||||
'sum' => '0',
|
||||
'currency_id' => $foreignCurrencyId,
|
||||
'currency_code' => $row['foreign_currency_code'],
|
||||
'currency_symbol' => $row['foreign_currency_symbol'],
|
||||
'currency_name' => $row['foreign_currency_name'],
|
||||
'currency_decimal_places' => (int)$row['foreign_currency_decimal_places'],
|
||||
];
|
||||
$return['sums'][$foreignCurrencyId]['sum'] = bcadd($return['sums'][$foreignCurrencyId]['sum'], (string)$row['foreign_amount']);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\RuleTrigger;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
@@ -64,6 +63,7 @@ trait RenderPartialViews
|
||||
$set->push($exp);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = view('reports.options.account', compact('set'))->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -71,6 +71,8 @@ trait RenderPartialViews
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -94,7 +96,6 @@ trait RenderPartialViews
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$budget = $budgetRepository->findNull((int)$attributes['budgetId']);
|
||||
$account = $accountRepository->findNull((int)$attributes['accountId']);
|
||||
|
||||
@@ -114,12 +115,14 @@ trait RenderPartialViews
|
||||
// row with tag info.
|
||||
return 'Firefly cannot handle this type of info-button (BalanceLine::TagRole)';
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $view;
|
||||
}
|
||||
@@ -134,6 +137,7 @@ trait RenderPartialViews
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$budgets = $repository->getBudgets();
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = view('reports.options.budget', compact('budgets'))->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -141,6 +145,8 @@ trait RenderPartialViews
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -164,12 +170,14 @@ trait RenderPartialViews
|
||||
$budget = new Budget;
|
||||
}
|
||||
$journals = $popupHelper->byBudget($budget, $attributes);
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $view;
|
||||
}
|
||||
@@ -195,12 +203,14 @@ trait RenderPartialViews
|
||||
}
|
||||
|
||||
$journals = $popupHelper->byCategory($category, $attributes);
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $view;
|
||||
}
|
||||
@@ -215,6 +225,7 @@ trait RenderPartialViews
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$categories = $repository->getCategories();
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = view('reports.options.category', compact('categories'))->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -222,6 +233,8 @@ trait RenderPartialViews
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -247,12 +260,14 @@ trait RenderPartialViews
|
||||
}
|
||||
|
||||
$journals = $popupHelper->byExpenses($account, $attributes);
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $view;
|
||||
}
|
||||
@@ -357,12 +372,14 @@ trait RenderPartialViews
|
||||
}
|
||||
|
||||
$journals = $popupHelper->byIncome($account, $attributes);
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render: %s', $e->getMessage()));
|
||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $view;
|
||||
}
|
||||
@@ -374,6 +391,7 @@ trait RenderPartialViews
|
||||
*/
|
||||
protected function noReportOptions(): string // render a view
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = view('reports.options.no-options')->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -381,6 +399,8 @@ trait RenderPartialViews
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -394,6 +414,8 @@ trait RenderPartialViews
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$tags = $repository->get();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = view('reports.options.tag', compact('tags'))->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -401,6 +423,8 @@ trait RenderPartialViews
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ trait RequestInformation
|
||||
return $content;
|
||||
}
|
||||
|
||||
return '<p>' . trans('firefly.route_has_no_help') . '</p>';
|
||||
return '<p>' . trans('firefly.route_has_no_help') . '</p>'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +181,7 @@ trait RequestInformation
|
||||
//Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %s', $key, var_export($shownDemo, true)));
|
||||
}
|
||||
if (!is_bool($shownDemo)) {
|
||||
$shownDemo = true;
|
||||
$shownDemo = true; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $shownDemo;
|
||||
@@ -291,6 +291,7 @@ trait RequestInformation
|
||||
* @param array $data
|
||||
*
|
||||
* @return ValidatorContract
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function validator(array $data): ValidatorContract
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ trait RuleManagement
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousActions(Request $request): array
|
||||
{
|
||||
@@ -123,6 +123,7 @@ trait RuleManagement
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
{
|
||||
|
||||
@@ -95,6 +95,7 @@ trait UserNavigation
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function redirectToAccount(TransactionJournal $journal)
|
||||
{
|
||||
@@ -118,6 +119,7 @@ trait UserNavigation
|
||||
* @param Account $account
|
||||
*
|
||||
* @return RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function redirectToOriginalAccount(Account $account)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user