Warn about expensive code in test environment.

This commit is contained in:
James Cole 2019-06-22 10:25:57 +02:00
parent 0f70cc5780
commit 2710a30a7c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
15 changed files with 328 additions and 127 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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.
*

View File

@ -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();

View File

@ -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 ModelInformation
return $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?
*

View File

@ -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 PeriodOverview
return $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 PeriodOverview
return $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;
}
}

View File

@ -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
*/

View File

@ -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()

View File

@ -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);

View File

@ -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_Extension
return 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;

View File

@ -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) {

View File

@ -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_Extension
return 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_Extension
return 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_Extension
return 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)

View File

@ -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();

View File

@ -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);

View File

@ -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);