mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various bugfixes and code clean up.
This commit is contained in:
parent
2ad8e7f343
commit
0312ba8ad7
@ -63,6 +63,7 @@ class Import extends Command
|
||||
{
|
||||
Log::debug('Start start-import command');
|
||||
$jobKey = (string)$this->argument('key');
|
||||
/** @var ImportJob $job */
|
||||
$job = ImportJob::where('key', $jobKey)->first();
|
||||
if (null === $job) {
|
||||
$this->errorLine(sprintf('No job found with key "%s"', $jobKey));
|
||||
|
@ -31,6 +31,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Export\Collector\AttachmentCollector;
|
||||
use FireflyIII\Export\Collector\UploadCollector;
|
||||
use FireflyIII\Export\Entry\Entry;
|
||||
use FireflyIII\Export\Exporter\ExporterInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
@ -220,6 +221,7 @@ class ExpandedProcessor implements ProcessorInterface
|
||||
public function exportJournals(): bool
|
||||
{
|
||||
$exporterClass = config('firefly.export_formats.' . $this->exportFormat);
|
||||
/** @var ExporterInterface $exporter */
|
||||
$exporter = app($exporterClass);
|
||||
$exporter->setJob($this->job);
|
||||
$exporter->setEntries($this->exportEntries);
|
||||
|
@ -43,7 +43,6 @@ class TransactionCurrencyFactory
|
||||
*/
|
||||
public function create(array $data): ?TransactionCurrency
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$result = TransactionCurrency::create(
|
||||
@ -55,6 +54,7 @@ class TransactionCurrencyFactory
|
||||
]
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
$result = null;
|
||||
Log::error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ class VersionCheckEventHandler
|
||||
|
||||
$latestRelease = $this->getLatestRelease();
|
||||
$versionCheck = $this->versionCheck($latestRelease);
|
||||
$resultString = $this->parseResult($latestRelease, $versionCheck);
|
||||
$resultString = $this->parseResult($versionCheck, $latestRelease);
|
||||
if (0 !== $versionCheck && '' !== $resultString) {
|
||||
// flash info
|
||||
session()->flash('info', $resultString);
|
||||
|
@ -77,11 +77,12 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
*/
|
||||
public function getAttachmentContent(Attachment $attachment): string
|
||||
{
|
||||
$content = '';
|
||||
|
||||
try {
|
||||
$content = Crypt::decrypt($this->uploadDisk->get(sprintf('at-%d.data', $attachment->id)));
|
||||
} catch (DecryptException|FileNotFoundException $e) {
|
||||
Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
|
||||
$content = '';
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
@ -76,7 +76,8 @@ class Help implements HelpInterface
|
||||
$statusCode = $res->getStatusCode();
|
||||
$content = trim($res->getBody()->getContents());
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
Log::error($e);
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Status code is %d', $statusCode));
|
||||
|
@ -66,12 +66,12 @@ trait UpdateTrait
|
||||
/**
|
||||
* Parses the version check result in a human readable sentence.
|
||||
*
|
||||
* @param Release|null $release
|
||||
* @param int $versionCheck
|
||||
* @param Release|null $release
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function parseResult(Release $release = null, int $versionCheck): string
|
||||
public function parseResult(int $versionCheck, Release $release = null): string
|
||||
{
|
||||
$current = (string)config('firefly.version');
|
||||
$return = '';
|
||||
|
@ -144,10 +144,13 @@ class ReconcileController extends Controller
|
||||
|
||||
// get start and end
|
||||
if (null === $start && null === $end) {
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
|
||||
/** @var Carbon $end */
|
||||
$end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range));
|
||||
}
|
||||
if (null === $end) {
|
||||
/** @var Carbon $end */
|
||||
$end = app('navigation')->endOfPeriod($start, $range);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,9 @@ class ShowController extends Controller
|
||||
if (AccountType::INITIAL_BALANCE === $account->accountType->type) {
|
||||
return $this->redirectToOriginalAccount($account);
|
||||
}
|
||||
/** @var Carbon $start */
|
||||
$start = $start ?? session('start');
|
||||
/** @var Carbon $end */
|
||||
$end = $end ?? session('end');
|
||||
if ($end < $start) {
|
||||
throw new FireflyException('End is after start!'); // @codeCoverageIgnore
|
||||
|
@ -101,7 +101,7 @@ class UpdateController extends Controller
|
||||
{
|
||||
$latestRelease = $this->getLatestRelease();
|
||||
$versionCheck = $this->versionCheck($latestRelease);
|
||||
$resultString = $this->parseResult($latestRelease, $versionCheck);
|
||||
$resultString = $this->parseResult($versionCheck, $latestRelease);
|
||||
|
||||
if (0 !== $versionCheck && '' !== $resultString) {
|
||||
// flash info
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\BillFormRequest;
|
||||
@ -277,7 +278,9 @@ class BillController extends Controller
|
||||
// add info about rules:
|
||||
$rules = $this->billRepository->getRulesForBill($bill);
|
||||
$subTitle = $bill->name;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
$year = $start->year;
|
||||
$page = (int)$request->get('page');
|
||||
|
@ -77,6 +77,7 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index(Request $request, string $moment = null)
|
||||
{
|
||||
/** @var string $range */
|
||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', new Carbon);
|
||||
|
@ -195,6 +195,7 @@ class ShowController extends Controller
|
||||
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation();
|
||||
$transactions = $collector->getPaginatedJournals();
|
||||
$transactions->setPath(route('budgets.show', [$budget->id, $budgetLimit->id]));
|
||||
/** @var Carbon $start */
|
||||
$start = session('first', Carbon::create()->startOfYear());
|
||||
$end = new Carbon;
|
||||
$limits = $this->getLimits($budget, $start, $end);
|
||||
|
@ -74,7 +74,9 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function expenseAccounts(AccountRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
|
@ -276,7 +276,7 @@ class DebugController extends Controller
|
||||
{
|
||||
$packages = [];
|
||||
$file = \dirname(__DIR__, 3) . '/vendor/composer/installed.json';
|
||||
if (!(false === $file) && file_exists($file)) {
|
||||
if (file_exists($file)) {
|
||||
// file exists!
|
||||
$content = file_get_contents($file);
|
||||
$json = json_decode($content, true);
|
||||
|
@ -59,6 +59,7 @@ class HelpController extends Controller
|
||||
*/
|
||||
public function show(string $route): JsonResponse
|
||||
{
|
||||
/** @var string $language */
|
||||
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$html = $this->getHelpText($route, $language);
|
||||
|
||||
|
@ -149,8 +149,11 @@ class JavascriptController extends Controller
|
||||
private function getDateRangeConfig(): array
|
||||
{
|
||||
$viewRange = app('preferences')->get('viewRange', '1M')->data;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
/** @var Carbon $first */
|
||||
$first = session('first');
|
||||
$title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
|
||||
$isCustom = true === session('is_custom_range', false);
|
||||
|
@ -54,7 +54,9 @@ class BoxController extends Controller
|
||||
*/
|
||||
public function available(BudgetRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$today = new Carbon;
|
||||
$cache = new CacheProperties;
|
||||
@ -111,7 +113,9 @@ class BoxController extends Controller
|
||||
public function balance(CurrencyRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
// Cache result, return cache if present.
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
@ -195,7 +199,9 @@ class BoxController extends Controller
|
||||
*/
|
||||
public function bills(BillRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
|
||||
$cache = new CacheProperties;
|
||||
|
@ -161,7 +161,7 @@ class ReconcileController extends Controller
|
||||
|
||||
$currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');
|
||||
$currency = $this->currencyRepos->findNull($currencyId);
|
||||
if (0 === $currency) {
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@ class RecurrenceController extends Controller
|
||||
if ($date > $today || 'true' === (string)$request->get('past')) {
|
||||
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
|
||||
$monthly = sprintf('monthly,%s', $date->day);
|
||||
$dayOfWeek = trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso);
|
||||
$yearly = sprintf('yearly,%s', $date->format('Y-m-d'));
|
||||
$yearlyDate = $date->formatLocalized(trans('config.month_and_day_no_year'));
|
||||
$yearlyDate = $date->formatLocalized((string)trans('config.month_and_day_no_year'));
|
||||
$result = [
|
||||
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => 0 === strpos($preSelected, 'daily')],
|
||||
$weekly => ['label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
|
@ -95,19 +95,16 @@ class IndexController extends Controller
|
||||
/**
|
||||
* Show a single recurring transaction.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function show(Request $request, Recurrence $recurrence)
|
||||
public function show(Recurrence $recurrence)
|
||||
{
|
||||
$transformer = new RecurrenceTransformer(new ParameterBag);
|
||||
$array = $transformer->transform($recurrence);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$transactions = $this->recurring->getTransactions($recurrence, $page, $pageSize);
|
||||
$transactions = $this->recurring->getTransactions($recurrence);
|
||||
|
||||
// transform dates back to Carbon objects:
|
||||
foreach ($array['recurrence_repetitions'] as $index => $repetition) {
|
||||
|
@ -61,8 +61,6 @@ class Installer
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
// Log::debug(sprintf('URL is %s, will run installer middleware', $url));
|
||||
|
||||
// no tables present?
|
||||
try {
|
||||
DB::table('users')->count();
|
||||
|
@ -47,6 +47,7 @@ class ExportFormRequest extends Request
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var Carbon $sessionFirst */
|
||||
$sessionFirst = clone session('first');
|
||||
$first = $sessionFirst->subDay()->format('Y-m-d');
|
||||
$today = Carbon::create()->addDay()->format('Y-m-d');
|
||||
|
@ -190,7 +190,7 @@ class RecurrenceFormRequest extends Request
|
||||
$rules['repetitions'] = 'required|numeric|between:0,254';
|
||||
}
|
||||
// if foreign amount, currency must be different.
|
||||
if (0.0 !== $this->float('foreign_amount')) {
|
||||
if (null !== $this->float('foreign_amount')) {
|
||||
$rules['foreign_currency_id'] = 'exists:transaction_currencies,id|different:transaction_currency_id';
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,15 @@ class Request extends FormRequest
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return float
|
||||
* @return float|null
|
||||
*/
|
||||
public function float(string $field): float
|
||||
public function float(string $field): ?float
|
||||
{
|
||||
return (float)$this->get($field);
|
||||
$res = $this->get($field);
|
||||
if(null === $res) {
|
||||
return null;
|
||||
}
|
||||
return (float)$res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,7 @@ class SelectTransactionsRequest extends Request
|
||||
public function rules(): array
|
||||
{
|
||||
// fixed
|
||||
/** @var Carbon $sessionFirst */
|
||||
$sessionFirst = clone session('first');
|
||||
$first = $sessionFirst->subDay()->format('Y-m-d');
|
||||
$today = Carbon::create()->addDay()->format('Y-m-d');
|
||||
|
@ -113,7 +113,7 @@ class BunqJobConfiguration implements JobConfigurationInterface
|
||||
Log::debug(sprintf('Now in BunqJobConfiguration::getHandler() with stage "%s"', $this->importJob->stage));
|
||||
$handler = null;
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new';
|
||||
case 'new':
|
||||
$handler = app(NewBunqJobHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
break;
|
||||
|
@ -101,13 +101,10 @@ class FileJobConfiguration implements JobConfigurationInterface
|
||||
return 'import.file.new';
|
||||
case 'configure-upload':
|
||||
return 'import.file.configure-upload';
|
||||
break;
|
||||
case 'roles':
|
||||
return 'import.file.roles';
|
||||
break;
|
||||
case 'map':
|
||||
return 'import.file.map';
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
|
@ -185,7 +185,9 @@ class ImportArrayStorage
|
||||
unset($transaction['importHashV2']);
|
||||
$json = json_encode($transaction);
|
||||
if (false === $json) {
|
||||
throw new FireflyException('Could not encode import array. Please see the logs.', $transaction); // @codeCoverageIgnore
|
||||
/** @noinspection ForgottenDebugOutputInspection */
|
||||
Log::error('Could not encode import array.', print_r($transaction, true));
|
||||
throw new FireflyException('Could not encode import array. Please see the logs.'); // @codeCoverageIgnore
|
||||
}
|
||||
$hash = hash('sha256', $json, false);
|
||||
Log::debug(sprintf('The hash is: %s', $hash));
|
||||
|
@ -161,7 +161,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
$set = $set->sortBy(
|
||||
function (Bill $bill) {
|
||||
$int = 1 === $bill->active ? 0 : 1;
|
||||
$int = $bill->active ? 0 : 1;
|
||||
|
||||
return $int . strtolower($bill->name);
|
||||
}
|
||||
|
@ -144,11 +144,12 @@ class ExportJobRepository implements ExportJobRepositoryInterface
|
||||
{
|
||||
$disk = Storage::disk('export');
|
||||
$file = $job->key . '.zip';
|
||||
$content = '';
|
||||
|
||||
try {
|
||||
$content = $disk->get($file);
|
||||
} catch (FileNotFoundException $e) {
|
||||
Log::warning(sprintf('File not found: %s', $e->getMessage()));
|
||||
$content = '';
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
@ -150,12 +150,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
*/
|
||||
public function getConfiguration(ImportJob $job): array
|
||||
{
|
||||
$config = $job->configuration;
|
||||
if (\is_array($config)) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
return [];
|
||||
return $job->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +477,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
|
||||
$value = $entry->data;
|
||||
|
||||
// return when array:
|
||||
if (\is_array($value)) {
|
||||
$return = implode(',', $value);
|
||||
$cache->store($return);
|
||||
|
@ -379,7 +379,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||
$diffInYears = $today->diffInYears($repDate);
|
||||
$repDate->addYears($diffInYears); // technically not necessary.
|
||||
$string = $repDate->formatLocalized(trans('config.month_and_day_no_year'));
|
||||
$string = $repDate->formatLocalized((string)trans('config.month_and_day_no_year'));
|
||||
|
||||
return (string)trans('firefly.recurring_yearly', ['date' => $string], $language);
|
||||
}
|
||||
|
@ -67,18 +67,18 @@ class ValidRecurrenceRepetitionValue implements Rule
|
||||
return $this->validateMonthly($value);
|
||||
}
|
||||
|
||||
//ndom,3,7
|
||||
// Value is like: ndom,3,7
|
||||
// nth x-day of the month.
|
||||
if (0 === strpos($value, 'ndom')) {
|
||||
return $this->validateNdom($value);
|
||||
}
|
||||
|
||||
//weekly,7
|
||||
// Value is like: weekly,7
|
||||
if (0 === strpos($value, 'weekly')) {
|
||||
return $this->validateWeekly($value);
|
||||
}
|
||||
|
||||
//yearly,2018-01-01
|
||||
// Value is like: yearly,2018-01-01
|
||||
if (0 === strpos($value, 'yearly')) {
|
||||
return $this->validateYearly($value);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ use bunq\Util\BunqEnumApiEnvironmentType;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Log;
|
||||
use Tests\Object\FakeApiContext;
|
||||
|
||||
/**
|
||||
* Special class to hide away bunq's static initialisation methods.
|
||||
@ -46,10 +47,10 @@ class ApiContext
|
||||
* @param string|null $proxyUrl
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return BunqApiContext
|
||||
* @return BunqApiContext|FakeApiContext
|
||||
*/
|
||||
public function create(BunqEnumApiEnvironmentType $environmentType, string $apiKey, string $description, array $permittedIps, string $proxyUrl = null
|
||||
): BunqApiContext {
|
||||
) {
|
||||
$permittedIps = $permittedIps ?? [];
|
||||
try {
|
||||
$context = BunqApiContext::create($environmentType, $apiKey, $description, $permittedIps, $proxyUrl);
|
||||
|
@ -41,7 +41,6 @@ class IpifyOrg implements IPRetrievalInterface
|
||||
*/
|
||||
public function getIP(): ?string
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('GET', 'https://api.ipify.org');
|
||||
|
@ -28,6 +28,7 @@ use FireflyIII\Factory\BudgetFactory;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
use FireflyIII\Factory\PiggyBankFactory;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\RecurrenceMeta;
|
||||
@ -44,6 +45,15 @@ use Log;
|
||||
*/
|
||||
trait RecurringTransactionTrait
|
||||
{
|
||||
/**
|
||||
* @param null|string $expectedType
|
||||
* @param int|null $accountId
|
||||
* @param null|string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $repetitions
|
||||
|
@ -124,7 +124,6 @@ trait TransactionServiceTrait
|
||||
|
||||
// alternatively, return by name. Validator should catch invalid names.
|
||||
return $repository->findByName($accountName, [AccountType::ASSET]);
|
||||
break;
|
||||
case AccountType::EXPENSE:
|
||||
if ($accountId > 0) {
|
||||
// must be able to find it based on ID. Validator should catch invalid ID's.
|
||||
@ -140,7 +139,6 @@ trait TransactionServiceTrait
|
||||
|
||||
// return cash account:
|
||||
return $repository->getCashAccount();
|
||||
break;
|
||||
case AccountType::REVENUE:
|
||||
if ($accountId > 0) {
|
||||
// must be able to find it based on ID. Validator should catch invalid ID's.
|
||||
|
@ -250,7 +250,7 @@ abstract class SpectreRequest
|
||||
$client = new Client;
|
||||
$res = $client->request('POST', $fullUri, ['headers' => $headers, 'body' => $body]);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Guzzle Exception: %s', $e->getMessage()));
|
||||
}
|
||||
$body = $res->getBody()->getContents();
|
||||
$statusCode = $res->getStatusCode();
|
||||
|
@ -66,22 +66,18 @@ class ImportProvider implements BinderInterface
|
||||
$isDemoUser = $repository->hasRole($user, 'demo');
|
||||
$isDebug = (bool)config('app.debug');
|
||||
foreach ($providerNames as $providerName) {
|
||||
//Log::debug(sprintf('Now with provider %s', $providerName));
|
||||
// only consider enabled providers
|
||||
$enabled = (bool)config(sprintf('import.enabled.%s', $providerName));
|
||||
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $providerName));
|
||||
$allowedForUser = (bool)config(sprintf('import.allowed_for_user.%s', $providerName));
|
||||
if (false === $enabled) {
|
||||
//Log::debug('Provider is not enabled. NEXT!');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (true === $isDemoUser && false === $allowedForDemo) {
|
||||
//Log::debug('User is demo and this provider is not allowed for demo user. NEXT!');
|
||||
continue;
|
||||
}
|
||||
if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) {
|
||||
//Log::debug('User is not demo and this provider is not allowed for such users. NEXT!');
|
||||
continue; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,11 @@ use Illuminate\Support\Facades\Facade;
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class FireflyConfig.
|
||||
* @method ?Configuration get($name, $default = null)
|
||||
* @method null|Configuration get($name, $default = null)
|
||||
* @method Configuration set(string $name, $value)
|
||||
* @method delete(string $name)
|
||||
* @method Configuration|null getFresh(string $name, $default = null)
|
||||
* @method Configuration put(string $name, $value)
|
||||
*/
|
||||
class FireflyConfig extends Facade
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ use Illuminate\Support\Facades\Facade;
|
||||
* @method Collection beginsWith(User $user, string $search)
|
||||
* @method bool delete(string $name)
|
||||
* @method Collection findByName(string $name)
|
||||
* @method Preference get(string $name, $value)
|
||||
* @method Preference get(string $name, $value = null)
|
||||
* @method array getArrayForUser(User $user, array $list)
|
||||
* @method Preference|null getForUser(User $user, string $name, $default = null)
|
||||
* @method string lastActivity()
|
||||
|
@ -55,7 +55,7 @@ class FireflyConfig
|
||||
*
|
||||
* @return \FireflyIII\Models\Configuration|null
|
||||
*/
|
||||
public function get(string $name, $default = null): ?Configuration
|
||||
public function get(string $name, $default = null): ?Configuration
|
||||
{
|
||||
$fullName = 'ff-config-' . $name;
|
||||
if (Cache::has($fullName)) {
|
||||
|
@ -63,7 +63,6 @@ class ConfigureRolesHandler implements FileConfigurationInterface
|
||||
{
|
||||
/** @var array $roles */
|
||||
$roles = $config['column-roles'];
|
||||
$count = $config['column-count'];
|
||||
$assigned = 0;
|
||||
|
||||
// check if data actually contains amount column (foreign amount does not count)
|
||||
|
@ -74,7 +74,7 @@ class ReportControllerTest extends TestCase
|
||||
];
|
||||
$uri = route('popup.general') . '?' . http_build_query($arguments);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(500);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,6 +58,8 @@ class MassControllerTest extends TestCase
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
|
||||
|
||||
|
||||
$withdrawals = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
|
||||
|
@ -845,6 +845,11 @@ class SingleControllerTest extends TestCase
|
||||
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getMetaField')->andReturn('');
|
||||
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
|
||||
|
||||
|
||||
$linkRepos->shouldReceive('get')->andReturn(new Collection);
|
||||
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);
|
||||
$attRepos->shouldReceive('saveAttachmentsForModel');
|
||||
|
@ -351,6 +351,9 @@ class TransactionControllerTest extends TestCase
|
||||
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getMetaField')->andReturn('');
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.show', [1]));
|
||||
|
@ -57,7 +57,6 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$repos->shouldReceive('hasRole')->andReturn(true)->once();
|
||||
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
|
||||
@ -91,7 +90,6 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$version = config('firefly.version');
|
||||
$first = new Release(['id' => '1', 'title' => $version . '.1', 'updated' => '2017-05-01', 'content' => '']);
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
|
||||
@ -139,7 +137,6 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
$repos->shouldReceive('hasRole')->andReturn(true)->once();
|
||||
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
|
||||
@ -164,7 +161,6 @@ class VersionCheckEventHandlerTest extends TestCase
|
||||
|
||||
|
||||
// report on config variables:
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($updateConfig);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn($checkConfig);
|
||||
|
||||
|
@ -79,8 +79,8 @@ class MetaPieChartTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
|
||||
|
||||
$helper = new MetaPieChart();
|
||||
$helper->setUser($this->user());
|
||||
@ -135,8 +135,8 @@ class MetaPieChartTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
|
||||
|
||||
$helper = new MetaPieChart();
|
||||
$helper->setCollectOtherObjects(true);
|
||||
@ -190,8 +190,8 @@ class MetaPieChartTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
|
||||
|
||||
$helper = new MetaPieChart();
|
||||
$helper->setUser($this->user());
|
||||
@ -245,8 +245,8 @@ class MetaPieChartTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('find')->withArgs([2])->andReturn($accounts[2]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($accounts[1]);
|
||||
$accountRepos->shouldReceive('findNull')->withArgs([2])->andReturn($accounts[2]);
|
||||
|
||||
$helper = new MetaPieChart();
|
||||
$helper->setCollectOtherObjects(true);
|
||||
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* RabobankDescriptionTest.php
|
||||
* Copyright (c) 2018 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 Tests\Unit\Import\Specifics;
|
||||
|
||||
|
||||
use FireflyIII\Import\Specifics\RabobankDescription;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RabobankDescriptionTest
|
||||
*/
|
||||
class RabobankDescriptionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Default behaviour
|
||||
* @covers \FireflyIII\Import\Specifics\RabobankDescription
|
||||
*/
|
||||
public function testRunBasic(): void
|
||||
{
|
||||
$row = ['','','','','','','','','','',''];
|
||||
|
||||
$parser = new RabobankDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals($row, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* No opposite name or iban
|
||||
* @covers \FireflyIII\Import\Specifics\RabobankDescription
|
||||
*/
|
||||
public function testRunUseDescription(): void
|
||||
{
|
||||
$row = ['','','','','','','','','','','Hello'];
|
||||
|
||||
$parser = new RabobankDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals('Hello', $result[6]);
|
||||
$this->assertEquals('', $result[10]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Has opposite name or iban
|
||||
* @covers \FireflyIII\Import\Specifics\RabobankDescription
|
||||
*/
|
||||
public function testRunUseFilledIn(): void
|
||||
{
|
||||
$row = ['','','','','','ABC','','','','',''];
|
||||
|
||||
$parser = new RabobankDescription;
|
||||
$result = $parser->run($row);
|
||||
$this->assertEquals($row, $result);
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountContains;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -38,13 +39,12 @@ class FromAccountContainsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$count = 0;
|
||||
while ($count === 0) {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$count = $journal->transactions()->where('amount', '<', 0)->count();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
$account = $transaction->account;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountContains::makeFromStrings($account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -57,7 +57,12 @@ class FromAccountContainsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -70,8 +75,8 @@ class FromAccountContainsTest extends TestCase
|
||||
public function testWillMatchEverythingEmpty(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = '';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$value = '';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
@ -81,8 +86,8 @@ class FromAccountContainsTest extends TestCase
|
||||
public function testWillMatchEverythingNotNull(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = 'x';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$value = 'x';
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
@ -92,8 +97,8 @@ class FromAccountContainsTest extends TestCase
|
||||
public function testWillMatchEverythingNull(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$value = null;
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$value = null;
|
||||
$result = FromAccountContains::willMatchEverything($value);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -38,13 +39,11 @@ class FromAccountEndsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$count = 0;
|
||||
while ($count === 0) {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$count = $journal->transactions()->where('amount', '<', 0)->count();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
$account = $transaction->account;
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -57,13 +56,12 @@ class FromAccountEndsTest extends TestCase
|
||||
public function testTriggeredLonger(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$count = 0;
|
||||
while ($count === 0) {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$count = $journal->transactions()->where('amount', '<', 0)->count();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
$account = $transaction->account;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -76,7 +74,12 @@ class FromAccountEndsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountEnds::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
/**
|
||||
@ -38,20 +39,12 @@ class FromAccountIsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
|
||||
$trigger = FromAccountIs::makeFromStrings($account->name, false);
|
||||
@ -65,7 +58,12 @@ class FromAccountIsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -48,26 +49,12 @@ class FromAccountStartsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
Log::debug('In testTriggered()');
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
$name = $account->name ?? '';
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this while the following is untrue:
|
||||
// 1) account is not null,
|
||||
// 2) journal has two transactions
|
||||
// 3) loops is less than 30
|
||||
// 4) $name is longer than 3
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -80,26 +67,12 @@ class FromAccountStartsTest extends TestCase
|
||||
public function testTriggeredLonger(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
Log::debug('In testTriggeredLonger()');
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
$name = $account->name ?? '';
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this while the following is untrue:
|
||||
// 1) account is not null,
|
||||
// 2) journal has two transactions
|
||||
// 3) loops is less than 30
|
||||
// 4) $name is longer than 3
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -112,7 +85,12 @@ class FromAccountStartsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalSourceAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\ToAccountContains;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -39,14 +40,11 @@ class ToAccountContainsTest extends TestCase
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$count = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
|
||||
$trigger = ToAccountContains::makeFromStrings($account->name, false);
|
||||
@ -60,14 +58,12 @@ class ToAccountContainsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$count = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
|
||||
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -39,26 +40,12 @@ class ToAccountEndsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
$name = $account->name ?? '';
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this while the following is untrue:
|
||||
// 1) account is not null,
|
||||
// 2) journal has two transactions
|
||||
// 3) loops is less than 30
|
||||
// 4) $name is longer than 3
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -71,25 +58,12 @@ class ToAccountEndsTest extends TestCase
|
||||
public function testTriggeredLonger(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
$name = $account->name ?? '';
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this while the following is untrue:
|
||||
// 1) account is not null,
|
||||
// 2) journal has two transactions
|
||||
// 3) loops is less than 30
|
||||
// 4) $name is longer than 3
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -102,25 +76,12 @@ class ToAccountEndsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
$name = $account->name ?? '';
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this while the following is untrue:
|
||||
// 1) account is not null,
|
||||
// 2) journal has two transactions
|
||||
// 3) loops is less than 30
|
||||
// 4) $name is longer than 3
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 1234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
@ -39,20 +40,12 @@ class ToAccountIsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
|
||||
|
||||
@ -67,20 +60,12 @@ class ToAccountIsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -39,22 +40,12 @@ class ToAccountStartsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
Log::debug('Now in testTriggered');
|
||||
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null === $account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
|
||||
@ -68,23 +59,12 @@ class ToAccountStartsTest extends TestCase
|
||||
public function testTriggeredLonger(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
Log::debug('Now in testTriggeredLonger');
|
||||
|
||||
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null === $account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@ -97,7 +77,12 @@ class ToAccountStartsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$account = $this->user()->accounts()->inRandomOrder()->first();
|
||||
$collection = new Collection([$account]);
|
||||
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
|
||||
|
||||
$trigger = ToAccountStarts::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
Loading…
Reference in New Issue
Block a user