Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Warn about expensive code in test environment.
James Cole2710a30a7cc9
diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex ded6728df5..35956e4376 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -202,6 +202,9 @@ class Amount*/public function getAllCurrencies(): Collection{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }return TransactionCurrency::orderBy('code', 'ASC')->get();}@@ -210,6 +213,9 @@ class Amount*/public function getCurrencies(): Collection{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();}@@ -218,6 +224,9 @@ class Amount*/public function getCurrencyCode(): string{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$cache = new CacheProperties;$cache->addProperty('getCurrencyCode');if ($cache->has()) {@@ -241,6 +250,9 @@ class Amount*/public function getCurrencySymbol(): string{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$cache = new CacheProperties;$cache->addProperty('getCurrencySymbol');if ($cache->has()) {@@ -261,6 +273,9 @@ class Amount*/public function getDefaultCurrency(): TransactionCurrency{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }/** @var User $user */$user = auth()->user();@@ -276,6 +291,9 @@ class Amount*/public function getDefaultCurrencyByUser(User $user): TransactionCurrency{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$cache = new CacheProperties;$cache->addProperty('getDefaultCurrency');$cache->addProperty($user->id);diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.phpindex 78890ae61f..feb4b65f39 100644--- a/app/Support/ExpandedForm.php+++ b/app/Support/ExpandedForm.php@@ -53,8 +53,8 @@ class ExpandedForm{/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -93,8 +93,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -140,11 +140,10 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string- * @throws FireflyException*/public function amount(string $name, $value = null, array $options = null): string{@@ -153,8 +152,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -185,7 +184,7 @@ class ExpandedForm/*** @param string $name- * @param array $options+ * @param array $options** @return string*@@ -227,8 +226,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -267,8 +266,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string* @throws FireflyException@@ -280,8 +279,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string* @throws FireflyException@@ -293,9 +292,9 @@ class ExpandedForm/*** @param string $name- * @param int $value- * @param mixed $checked- * @param array $options+ * @param int $value+ * @param mixed $checked+ * @param array $options** @return string*@@ -331,8 +330,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -354,8 +353,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -379,8 +378,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -404,7 +403,7 @@ class ExpandedForm/*** @param string $name- * @param array $options+ * @param array $options** @return string*@@ -427,8 +426,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -453,8 +452,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -478,8 +477,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -580,8 +579,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -611,8 +610,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -656,7 +655,7 @@ class ExpandedForm/*** @param string $name- * @param array $options+ * @param array $options** @return string*@@ -681,8 +680,8 @@ class ExpandedForm* Function to render a percentage.** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -707,8 +706,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -732,8 +731,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*/@@ -754,8 +753,8 @@ class ExpandedForm}/**- * @param string $name- * @param null $value+ * @param string $name+ * @param null $value* @param array|null $options** @return HtmlString@@ -785,9 +784,9 @@ class ExpandedForm/** @noinspection MoreThanThreeArgumentsInspection *//*** @param string $name- * @param array $list- * @param mixed $selected- * @param array $options+ * @param array $list+ * @param mixed $selected+ * @param array $options** @return string*/@@ -811,8 +810,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -834,8 +833,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -859,8 +858,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -883,8 +882,8 @@ class ExpandedForm/*** @param string $name- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string*@@ -916,8 +915,8 @@ class ExpandedForm/*** @param string $name* @param string $view- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string* @SuppressWarnings(PHPMD.CyclomaticComplexity)@@ -969,8 +968,8 @@ class ExpandedForm/*** @param string $name* @param string $view- * @param mixed $value- * @param array $options+ * @param mixed $value+ * @param array $options** @return string* @SuppressWarnings(PHPMD.CyclomaticComplexity)diff --git a/app/Support/Facades/Preferences.php b/app/Support/Facades/Preferences.phpindex 3686144b5f..92887c269e 100644--- a/app/Support/Facades/Preferences.php+++ b/app/Support/Facades/Preferences.php@@ -26,7 +26,7 @@ use FireflyIII\Models\Preference;use FireflyIII\User;use Illuminate\Support\Collection;use Illuminate\Support\Facades\Facade;-+use Log;/*** @codeCoverageIgnore* Class Preferences.@@ -44,6 +44,11 @@ use Illuminate\Support\Facades\Facade;*/class Preferences extends Facade{+ public function __construct()+ {+ Log::warning('Hi there');+ }+/*** Get the registered name of the component.*diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.phpindex debd591f77..1cf6aa184d 100644--- a/app/Support/FireflyConfig.php+++ b/app/Support/FireflyConfig.php@@ -32,11 +32,15 @@ use Log;*/class FireflyConfig{+/*** @param string $name*/public function delete(string $name): void{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$fullName = 'ff-config-' . $name;if (Cache::has($fullName)) {Cache::forget($fullName);@@ -51,12 +55,15 @@ class FireflyConfig/*** @param string $name- * @param mixed $default+ * @param mixed $default** @return \FireflyIII\Models\Configuration|null*/public function get(string $name, $default = null): ?Configuration{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$fullName = 'ff-config-' . $name;if (Cache::has($fullName)) {return Cache::get($fullName);@@ -79,12 +86,15 @@ class FireflyConfig/*** @param string $name- * @param mixed $default+ * @param mixed $default** @return \FireflyIII\Models\Configuration|null*/public function getFresh(string $name, $default = null): ?Configuration{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);if ($config) {@@ -106,6 +116,10 @@ class FireflyConfig*/public function put(string $name, $value): Configuration{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }+return $this->set($name, $value);}@@ -117,6 +131,9 @@ class FireflyConfig*/public function set(string $name, $value): Configuration{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }Log::debug('Set new value for ', ['name' => $name]);/** @var Configuration $config */$config = Configuration::whereName($name)->first();diff --git a/app/Support/Http/Controllers/ModelInformation.php b/app/Support/Http/Controllers/ModelInformation.phpindex f45c7a8448..53a835365f 100644--- a/app/Support/Http/Controllers/ModelInformation.php+++ b/app/Support/Http/Controllers/ModelInformation.php@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Http\Controllers;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\Account;+use FireflyIII\Models\AccountType;use FireflyIII\Models\Bill;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\TransactionType;@@ -74,8 +75,8 @@ trait ModelInformation* Get the destination account. Is complex.** @param TransactionJournal $journal- * @param TransactionType $destinationType- * @param array $data+ * @param TransactionType $destinationType+ * @param array $data** @return Account*@@ -115,9 +116,9 @@ trait ModelInformation}$data = ['name' => $data['destination_account_expense'],- 'account_type' => 'expense',+ 'account_type' => 'expense','account_type_id' => null,- 'virtual_balance' => 0,+ 'virtual_balance' => 0,'active' => true,'iban' => null,];@@ -137,8 +138,8 @@ trait ModelInformation* Get the source account.** @param TransactionJournal $journal- * @param TransactionType $destinationType- * @param array $data+ * @param TransactionType $destinationType+ * @param array $data** @return Account*@@ -171,8 +172,8 @@ trait ModelInformation$data = ['name' => $data['source_account_revenue'],- 'account_type' => 'revenue',- 'virtual_balance' => 0,+ 'account_type' => 'revenue',+ 'virtual_balance' => 0,'active' => true,'account_type_id' => null,'iban' => null,@@ -238,6 +239,43 @@ trait ModelInformationreturn $result;}+ /**+ * @codeCoverageIgnore+ * @return array+ */+ protected function getRoles(): array+ {+ $roles = [];+ foreach (config('firefly.accountRoles') as $role) {+ $roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));+ }++ return $roles;+ }++ /**+ * @codeCoverageIgnore+ * @return array+ */+ protected function getLiabilityTypes(): array+ {+ /** @var AccountRepositoryInterface $repository */+ $repository = app(AccountRepositoryInterface::class);+ // types of liability:+ $debt = $repository->getAccountTypeByType(AccountType::DEBT);+ $loan = $repository->getAccountTypeByType(AccountType::LOAN);+ $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);+ /** @noinspection NullPointerExceptionInspection */+ $liabilityTypes = [+ $debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),+ $loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),+ $mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),+ ];+ asort($liabilityTypes);++ return $liabilityTypes;+ }+/*** Is transaction opening balance?*diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.phpindex f3bf4e0719..5ff7318427 100644--- a/app/Support/Http/Controllers/PeriodOverview.php+++ b/app/Support/Http/Controllers/PeriodOverview.php@@ -25,7 +25,6 @@ namespace FireflyIII\Support\Http\Controllers;use Carbon\Carbon;use FireflyIII\Helpers\Collector\GroupCollectorInterface;-use FireflyIII\Helpers\Collector\GroupSumCollectorInterface;use FireflyIII\Models\Account;use FireflyIII\Models\Category;use FireflyIII\Models\Tag;@@ -135,34 +134,6 @@ trait PeriodOverviewreturn $entries;}- /**- * @param array $journals- *- * @return array- */- private function groupByCurrency(array $journals): array- {- $return = [];- /** @var array $journal */- foreach ($journals as $journal) {- $currencyId = (int)$journal['currency_id'];- if (!isset($return[$currencyId])) {- $currency = new TransactionCurrency;- $currency->symbol = $journal['currency_symbol'];- $currency->decimal_places = $journal['currency_decimal_places'];- $currency->name = $journal['currency_name'];- $return[$currencyId] = [- 'amount' => '0',- 'currency' => $currency,- //'currency' => 'x',//$currency,- ];- }- $return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);- }-- return $return;- }-/*** Overview for single category. Has been refactored recently.*@@ -469,16 +440,11 @@ trait PeriodOverview$entries = new Collection;foreach ($dates as $currentDate) {-- /** @var GroupSumCollectorInterface $sumCollector */- $sumCollector = app(GroupSumCollectorInterface::class);- $sumCollector->setTypes($types)->setRange($currentDate['start'], $currentDate['end']);- $amounts = $sumCollector->getSum();-/** @var GroupCollectorInterface $collector */$collector = app(GroupCollectorInterface::class);$collector->setTypes($types)->setRange($currentDate['start'], $currentDate['end']);- $amounts = $collector->getSum();+ $journals = $collector->getExtractedJournals();+ $amounts = $this->getJournalsSum($journals);$spent = [];$earned = [];@@ -553,4 +519,80 @@ trait PeriodOverviewreturn $return;}+ /**+ * @param array $journals+ *+ * @return array+ */+ private function groupByCurrency(array $journals): array+ {+ $return = [];+ /** @var array $journal */+ foreach ($journals as $journal) {+ $currencyId = (int)$journal['currency_id'];+ if (!isset($return[$currencyId])) {+ $currency = new TransactionCurrency;+ $currency->symbol = $journal['currency_symbol'];+ $currency->decimal_places = $journal['currency_decimal_places'];+ $currency->name = $journal['currency_name'];+ $return[$currencyId] = [+ 'amount' => '0',+ 'currency' => $currency,+ //'currency' => 'x',//$currency,+ ];+ }+ $return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);+ }++ 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;+ }+}diff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex 09106f4c9a..98806823b6 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -36,13 +36,16 @@ use Session;class Preferences{/**- * @param User $user+ * @param User $user* @param string $search** @return Collection*/public function beginsWith(User $user, string $search): Collection{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$set = Preference::where('user_id', $user->id)->where('name', 'LIKE', $search . '%')->get();return $set;@@ -55,6 +58,9 @@ class Preferences*/public function delete(string $name): bool{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$fullName = sprintf('preference%s%s', auth()->user()->id, $name);if (Cache::has($fullName)) {Cache::forget($fullName);@@ -76,17 +82,24 @@ class Preferences*/public function findByName(string $name): Collection{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }+return Preference::where('name', $name)->get();}/*** @param string $name- * @param mixed $default+ * @param mixed $default** @return \FireflyIII\Models\Preference|null*/public function get(string $name, $default = null): ?Preference{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }/** @var User $user */$user = auth()->user();if (null === $user) {@@ -98,12 +111,15 @@ class Preferences/*** @param \FireflyIII\User $user- * @param array $list+ * @param array $list** @return array*/public function getArrayForUser(User $user, array $list): array{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$result = [];$preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']);/** @var Preference $preference */@@ -121,13 +137,16 @@ class Preferences/*** @param \FireflyIII\User $user- * @param string $name- * @param null|string $default+ * @param string $name+ * @param null|string $default** @return \FireflyIII\Models\Preference|null*/public function getForUser(User $user, string $name, $default = null): ?Preference{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$fullName = sprintf('preference%s%s', $user->id, $name);if (Cache::has($fullName)) {return Cache::get($fullName);@@ -162,6 +181,9 @@ class Preferences*/public function lastActivity(): string{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$lastActivity = microtime();$preference = $this->get('lastActivity', microtime());@@ -186,7 +208,7 @@ class Preferences/*** @param string $name- * @param mixed $value+ * @param mixed $value** @return \FireflyIII\Models\Preference*/@@ -207,8 +229,8 @@ class Preferences/*** @param \FireflyIII\User $user- * @param string $name- * @param mixed $value+ * @param string $name+ * @param mixed $value** @return Preference*/diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex f30dd9d752..b4e4fcd98a 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -28,6 +28,7 @@ use FireflyIII\Models\Account;use FireflyIII\Models\Transaction;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;+use Log;use stdClass;/**@@ -44,6 +45,9 @@ class Steam*/public function balance(Account $account, Carbon $date): string{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }// abuse chart properties:$cache = new CacheProperties;$cache->addProperty($account->id);@@ -93,6 +97,9 @@ class Steam*/public function balanceIgnoreVirtual(Account $account, Carbon $date): string{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }// abuse chart properties:$cache = new CacheProperties;$cache->addProperty($account->id);@@ -139,6 +146,9 @@ class Steam*/public function balanceInRange(Account $account, Carbon $start, Carbon $end): array{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }// abuse chart properties:$cache = new CacheProperties;$cache->addProperty($account->id);@@ -225,7 +235,9 @@ class Steam*/public function balancePerCurrency(Account $account, Carbon $date): array{-+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }// abuse chart properties:$cache = new CacheProperties;$cache->addProperty($account->id);@@ -259,6 +271,9 @@ class Steam*/public function balancesByAccounts(Collection $accounts, Carbon $date): array{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$ids = $accounts->pluck('id')->toArray();// cache this property.$cache = new CacheProperties;@@ -291,6 +306,9 @@ class Steam*/public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$ids = $accounts->pluck('id')->toArray();// cache this property.$cache = new CacheProperties;@@ -383,6 +401,9 @@ class Steam*/public function getLastActivities(array $accounts): array{+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$list = [];$set = auth()->user()->transactions()diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.phpindex 9992740d8e..507b9d2b7b 100644--- a/app/Support/Twig/AmountFormat.php+++ b/app/Support/Twig/AmountFormat.php@@ -26,6 +26,7 @@ use FireflyIII\Models\Account as AccountModel;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;+use Log;use Twig_Extension;use Twig_SimpleFilter;use Twig_SimpleFunction;@@ -83,7 +84,12 @@ class AmountFormat extends Twig_Extension{return new Twig_SimpleFunction('formatAmountByAccount',- function (AccountModel $account, string $amount, bool $coloured = null): string {+ static function (AccountModel $account, string $amount, bool $coloured = null): string {++ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }+$coloured = $coloured ?? true;/** @var AccountRepositoryInterface $accountRepos */$accountRepos = app(AccountRepositoryInterface::class);diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.phpindex dd4f5b590d..7d5772219c 100644--- a/app/Support/Twig/General.php+++ b/app/Support/Twig/General.php@@ -27,6 +27,7 @@ use FireflyIII\Models\Account;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\User\UserRepositoryInterface;use League\CommonMark\CommonMarkConverter;+use Log;use Route;use Twig_Extension;use Twig_SimpleFilter;@@ -145,13 +146,17 @@ class General extends Twig_Extension{return new Twig_SimpleFilter('balance',- function (?Account $account): string {+ static function (?Account $account): string {if (null === $account) {return 'NULL';}/** @var Carbon $date */$date = session('end', Carbon::now()->endOfMonth());+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }+return app('steam')->balance($account, $date);});@@ -207,6 +212,10 @@ class General extends Twig_Extensionreturn new Twig_SimpleFunction('accountGetMetaField',static function (Account $account, string $field): string {+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }+/** @var AccountRepositoryInterface $repository */$repository = app(AccountRepositoryInterface::class);$result = $repository->getMetaValue($account, $field);@@ -228,7 +237,10 @@ class General extends Twig_Extension{return new Twig_SimpleFunction('hasRole',- function (string $role): bool {+ static function (string $role): bool {+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$repository = app(UserRepositoryInterface::class);if ($repository->hasRole(auth()->user(), $role)) {return true;diff --git a/app/Support/Twig/Rule.php b/app/Support/Twig/Rule.phpindex 83a403bc0f..c40c8097bd 100644--- a/app/Support/Twig/Rule.php+++ b/app/Support/Twig/Rule.php@@ -38,7 +38,7 @@ class Rule extends Twig_Extension{return new Twig_SimpleFunction('allRuleActions',- function () {+ static function () {// array of valid values for actions$ruleActions = array_keys(Config::get('firefly.rule-actions'));$possibleActions = [];@@ -60,7 +60,7 @@ class Rule extends Twig_Extension{return new Twig_SimpleFunction('allJournalTriggers',- function () {+ static function () {return ['store-journal' => (string)trans('firefly.rule_trigger_store_journal'),'update-journal' => (string)trans('firefly.rule_trigger_update_journal'),@@ -76,7 +76,7 @@ class Rule extends Twig_Extension{return new Twig_SimpleFunction('allRuleTriggers',- function () {+ static function () {$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));$possibleTriggers = [];foreach ($ruleTriggers as $key) {diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.phpindex 0ca99e9cf0..5bdd2e1a2a 100644--- a/app/Support/Twig/TransactionGroupTwig.php+++ b/app/Support/Twig/TransactionGroupTwig.php@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Twig\Extension;use Carbon\Carbon;use DB;use FireflyIII\Models\TransactionType;+use Log;use Twig_Extension;use Twig_SimpleFunction;@@ -94,7 +95,9 @@ class TransactionGroupTwig extends Twig_Extensionreturn new Twig_SimpleFunction('journalGetMetaDate',static function (int $journalId, string $metaField) {-+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$entry = DB::table('journal_meta')->where('name', $metaField)->where('transaction_journal_id', $journalId)@@ -117,7 +120,9 @@ class TransactionGroupTwig extends Twig_Extensionreturn new Twig_SimpleFunction('journalGetMetaField',static function (int $journalId, string $metaField) {-+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$entry = DB::table('journal_meta')->where('name', $metaField)->where('transaction_journal_id', $journalId)@@ -140,6 +145,9 @@ class TransactionGroupTwig extends Twig_Extensionreturn new Twig_SimpleFunction('journalHasMeta',static function (int $journalId, string $metaField) {+ if ('testing' === config('app.env')) {+ Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));+ }$count = DB::table('journal_meta')->where('name', $metaField)->where('transaction_journal_id', $journalId)diff --git a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.phpindex dce996a9c5..2c43cf0a6f 100644--- a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php+++ b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php@@ -23,7 +23,7 @@ declare(strict_types=1);namespace Tests\Api\V1\Controllers;-+use Preferences;use Amount;use FireflyIII\Factory\TransactionCurrencyFactory;use FireflyIII\Models\AvailableBudget;@@ -61,6 +61,7 @@ class AvailableBudgetControllerTest extends TestCase*/public function testStore(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));$repository = $this->mock(BudgetRepositoryInterface::class);$transformer = $this->mock(AvailableBudgetTransformer::class);$factory = $this->mock(TransactionCurrencyFactory::class);@@ -101,6 +102,7 @@ class AvailableBudgetControllerTest extends TestCase*/public function testStoreNoCurrencyAtAll(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock stuff:$repository = $this->mock(BudgetRepositoryInterface::class);$transformer = $this->mock(AvailableBudgetTransformer::class);@@ -142,6 +144,7 @@ class AvailableBudgetControllerTest extends TestCase*/public function testStoreNoCurrencyId(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));/** @var AvailableBudget $availableBudget */$availableBudget = $this->user()->availableBudgets()->first();@@ -188,11 +191,15 @@ class AvailableBudgetControllerTest extends TestCase*/public function testUpdate(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock repositories$repository = $this->mock(BudgetRepositoryInterface::class);$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);$transformer = $this->mock(AvailableBudgetTransformer::class);$factory = $this->mock(TransactionCurrencyFactory::class);+ $euro = $this->getEuro();+ // mock facades:+ Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);// mock transformer$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();diff --git a/tests/Api/V1/Controllers/Chart/AccountControllerTest.php b/tests/Api/V1/Controllers/Chart/AccountControllerTest.phpindex 088f14dce1..ab7c178551 100644--- a/tests/Api/V1/Controllers/Chart/AccountControllerTest.php+++ b/tests/Api/V1/Controllers/Chart/AccountControllerTest.php@@ -55,6 +55,7 @@ class AccountControllerTest extends TestCase*/public function testOverview(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock repositories$repository = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);@@ -93,6 +94,7 @@ class AccountControllerTest extends TestCase*/public function testRevenueOverview(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock repositories$repository = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);@@ -134,6 +136,7 @@ class AccountControllerTest extends TestCase*/public function testExpenseOverview(): void{+ Log::info(sprintf('Now in test %s.', __METHOD__));// mock repositories$repository = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);diff --git a/tests/Api/V1/Controllers/CurrencyControllerTest.php b/tests/Api/V1/Controllers/CurrencyControllerTest.phpindex 58ab66abf4..e1fb52d23e 100644--- a/tests/Api/V1/Controllers/CurrencyControllerTest.php+++ b/tests/Api/V1/Controllers/CurrencyControllerTest.php@@ -34,7 +34,7 @@ use Laravel\Passport\Passport;use Log;use Preferences;use Tests\TestCase;-+use Amount;/*** Class CurrencyControllerTest* @SuppressWarnings(PHPMD.CouplingBetweenObjects)@@ -65,7 +65,7 @@ class CurrencyControllerTest extends TestCase$currency = TransactionCurrency::first();$repository = $this->mock(CurrencyRepositoryInterface::class);$transformer = $this->mock(CurrencyTransformer::class);- $userRepository = $this->mock(UserRepositoryInterface::class);+ $this->mock(UserRepositoryInterface::class);// mock transformer$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();@@ -74,6 +74,9 @@ class CurrencyControllerTest extends TestCase$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);+ // mock facades.+ Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);+// mock calls:$repository->shouldReceive('setUser')->once();$repository->shouldReceive('store')->andReturn($currency);