diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index 7fad01c15e..0f952e6af3 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -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)); diff --git a/app/Export/ExpandedProcessor.php b/app/Export/ExpandedProcessor.php index f20c25e0a7..27fdc83822 100644 --- a/app/Export/ExpandedProcessor.php +++ b/app/Export/ExpandedProcessor.php @@ -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); diff --git a/app/Factory/TransactionCurrencyFactory.php b/app/Factory/TransactionCurrencyFactory.php index b2d75737c2..7f7b4548af 100644 --- a/app/Factory/TransactionCurrencyFactory.php +++ b/app/Factory/TransactionCurrencyFactory.php @@ -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())); } diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.php index 072983d8c4..46b371772e 100644 --- a/app/Handlers/Events/VersionCheckEventHandler.php +++ b/app/Handlers/Events/VersionCheckEventHandler.php @@ -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); diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index e68300bedb..d840a2a812 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -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; diff --git a/app/Helpers/Help/Help.php b/app/Helpers/Help/Help.php index 818517d6f3..787d4710fe 100644 --- a/app/Helpers/Help/Help.php +++ b/app/Helpers/Help/Help.php @@ -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)); diff --git a/app/Helpers/Update/UpdateTrait.php b/app/Helpers/Update/UpdateTrait.php index e7fe2d936e..775c44e186 100644 --- a/app/Helpers/Update/UpdateTrait.php +++ b/app/Helpers/Update/UpdateTrait.php @@ -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 = ''; diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index e43276c4dd..99c3ab623c 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -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); } diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 13eedc3304..a5273323c4 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -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 diff --git a/app/Http/Controllers/Admin/UpdateController.php b/app/Http/Controllers/Admin/UpdateController.php index 3c672fd9aa..18aa985518 100644 --- a/app/Http/Controllers/Admin/UpdateController.php +++ b/app/Http/Controllers/Admin/UpdateController.php @@ -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 diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 0bee14bc8b..5e3e12f362 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -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'); diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index e79ea0b59a..f23cd4f159 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -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); diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index bf19fbac6d..0b48280422 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -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); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 10923b03a5..124cc00da6 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -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); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index af596ecd2e..958c51f017 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -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); diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php index 91033e1eb2..830d63ab31 100644 --- a/app/Http/Controllers/HelpController.php +++ b/app/Http/Controllers/HelpController.php @@ -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); diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php index fc054d5590..d9432135bf 100644 --- a/app/Http/Controllers/JavascriptController.php +++ b/app/Http/Controllers/JavascriptController.php @@ -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); diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index c8947f213e..f059036100 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -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; diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index dc5878c97a..dc36328675 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -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 } diff --git a/app/Http/Controllers/Json/RecurrenceController.php b/app/Http/Controllers/Json/RecurrenceController.php index e5cd05697e..b983022876 100644 --- a/app/Http/Controllers/Json/RecurrenceController.php +++ b/app/Http/Controllers/Json/RecurrenceController.php @@ -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]), diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php index dd29bb353e..4aceec0e57 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -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) { diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.php index ccb574c8df..d246c1b02d 100644 --- a/app/Http/Middleware/Installer.php +++ b/app/Http/Middleware/Installer.php @@ -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(); diff --git a/app/Http/Requests/ExportFormRequest.php b/app/Http/Requests/ExportFormRequest.php index 2a12faac28..942aca6870 100644 --- a/app/Http/Requests/ExportFormRequest.php +++ b/app/Http/Requests/ExportFormRequest.php @@ -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'); diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php index 0ddd7bb8c2..47c389922e 100644 --- a/app/Http/Requests/RecurrenceFormRequest.php +++ b/app/Http/Requests/RecurrenceFormRequest.php @@ -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'; } diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 488d1ab2ed..f03a05093d 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -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; } /** diff --git a/app/Http/Requests/SelectTransactionsRequest.php b/app/Http/Requests/SelectTransactionsRequest.php index 311efa751b..9207a51159 100644 --- a/app/Http/Requests/SelectTransactionsRequest.php +++ b/app/Http/Requests/SelectTransactionsRequest.php @@ -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'); diff --git a/app/Import/JobConfiguration/BunqJobConfiguration.php b/app/Import/JobConfiguration/BunqJobConfiguration.php index 31ec787ba5..6f3b4a85cb 100644 --- a/app/Import/JobConfiguration/BunqJobConfiguration.php +++ b/app/Import/JobConfiguration/BunqJobConfiguration.php @@ -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; diff --git a/app/Import/JobConfiguration/FileJobConfiguration.php b/app/Import/JobConfiguration/FileJobConfiguration.php index e240dd974e..b41e8e3156 100644 --- a/app/Import/JobConfiguration/FileJobConfiguration.php +++ b/app/Import/JobConfiguration/FileJobConfiguration.php @@ -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( diff --git a/app/Import/Storage/ImportArrayStorage.php b/app/Import/Storage/ImportArrayStorage.php index 1b04ca8f12..19868ec17e 100644 --- a/app/Import/Storage/ImportArrayStorage.php +++ b/app/Import/Storage/ImportArrayStorage.php @@ -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)); diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 81c08e85e2..390916ce24 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -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); } diff --git a/app/Repositories/ExportJob/ExportJobRepository.php b/app/Repositories/ExportJob/ExportJobRepository.php index 49c12086ff..c8d50516a5 100644 --- a/app/Repositories/ExportJob/ExportJobRepository.php +++ b/app/Repositories/ExportJob/ExportJobRepository.php @@ -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; diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php index ba6626e271..120e612f40 100644 --- a/app/Repositories/ImportJob/ImportJobRepository.php +++ b/app/Repositories/ImportJob/ImportJobRepository.php @@ -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; } /** diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 68ca7ca9b4..64715c42af 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -477,7 +477,6 @@ class JournalRepository implements JournalRepositoryInterface $value = $entry->data; - // return when array: if (\is_array($value)) { $return = implode(',', $value); $cache->store($return); diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php index 38df49b788..61ccbd4a79 100644 --- a/app/Repositories/Recurring/RecurringRepository.php +++ b/app/Repositories/Recurring/RecurringRepository.php @@ -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); } diff --git a/app/Rules/ValidRecurrenceRepetitionValue.php b/app/Rules/ValidRecurrenceRepetitionValue.php index 825321ae75..da24867046 100644 --- a/app/Rules/ValidRecurrenceRepetitionValue.php +++ b/app/Rules/ValidRecurrenceRepetitionValue.php @@ -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); } diff --git a/app/Services/Bunq/ApiContext.php b/app/Services/Bunq/ApiContext.php index 43cd2a8b7a..b09aa1ea80 100644 --- a/app/Services/Bunq/ApiContext.php +++ b/app/Services/Bunq/ApiContext.php @@ -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); diff --git a/app/Services/IP/IpifyOrg.php b/app/Services/IP/IpifyOrg.php index 0c0f8a3404..2349f65dce 100644 --- a/app/Services/IP/IpifyOrg.php +++ b/app/Services/IP/IpifyOrg.php @@ -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'); diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index 8844d64db0..46c91191a9 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -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 diff --git a/app/Services/Internal/Support/TransactionServiceTrait.php b/app/Services/Internal/Support/TransactionServiceTrait.php index a784dd240a..7be855dbbf 100644 --- a/app/Services/Internal/Support/TransactionServiceTrait.php +++ b/app/Services/Internal/Support/TransactionServiceTrait.php @@ -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. diff --git a/app/Services/Spectre/Request/SpectreRequest.php b/app/Services/Spectre/Request/SpectreRequest.php index 1fafadf23c..a215373a91 100644 --- a/app/Services/Spectre/Request/SpectreRequest.php +++ b/app/Services/Spectre/Request/SpectreRequest.php @@ -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(); diff --git a/app/Support/Binder/ImportProvider.php b/app/Support/Binder/ImportProvider.php index 1d3df1bf8e..149e38cb84 100644 --- a/app/Support/Binder/ImportProvider.php +++ b/app/Support/Binder/ImportProvider.php @@ -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 } diff --git a/app/Support/Facades/FireflyConfig.php b/app/Support/Facades/FireflyConfig.php index 01aade0d24..92c941e4eb 100644 --- a/app/Support/Facades/FireflyConfig.php +++ b/app/Support/Facades/FireflyConfig.php @@ -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 { diff --git a/app/Support/Facades/Preferences.php b/app/Support/Facades/Preferences.php index b5d6eacafb..3686144b5f 100644 --- a/app/Support/Facades/Preferences.php +++ b/app/Support/Facades/Preferences.php @@ -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() diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index 17a0fe41a5..9e7ecf23fd 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -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)) { diff --git a/app/Support/Import/JobConfiguration/File/ConfigureRolesHandler.php b/app/Support/Import/JobConfiguration/File/ConfigureRolesHandler.php index fd633abd55..e93af258cf 100644 --- a/app/Support/Import/JobConfiguration/File/ConfigureRolesHandler.php +++ b/app/Support/Import/JobConfiguration/File/ConfigureRolesHandler.php @@ -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) diff --git a/tests/Feature/Controllers/Popup/ReportControllerTest.php b/tests/Feature/Controllers/Popup/ReportControllerTest.php index d981b23dc8..ccbde5228c 100644 --- a/tests/Feature/Controllers/Popup/ReportControllerTest.php +++ b/tests/Feature/Controllers/Popup/ReportControllerTest.php @@ -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); } /** diff --git a/tests/Feature/Controllers/Transaction/MassControllerTest.php b/tests/Feature/Controllers/Transaction/MassControllerTest.php index 202be2a26e..f722727516 100644 --- a/tests/Feature/Controllers/Transaction/MassControllerTest.php +++ b/tests/Feature/Controllers/Transaction/MassControllerTest.php @@ -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(); diff --git a/tests/Feature/Controllers/Transaction/SingleControllerTest.php b/tests/Feature/Controllers/Transaction/SingleControllerTest.php index 2fc9ef1c1f..d785a5a5a2 100644 --- a/tests/Feature/Controllers/Transaction/SingleControllerTest.php +++ b/tests/Feature/Controllers/Transaction/SingleControllerTest.php @@ -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'); diff --git a/tests/Feature/Controllers/TransactionControllerTest.php b/tests/Feature/Controllers/TransactionControllerTest.php index a9dedac278..73cb4f7d6b 100644 --- a/tests/Feature/Controllers/TransactionControllerTest.php +++ b/tests/Feature/Controllers/TransactionControllerTest.php @@ -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])); diff --git a/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php b/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php index 1f4399ba6f..528b5bbc2d 100644 --- a/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php +++ b/tests/Unit/Handlers/Events/VersionCheckEventHandlerTest.php @@ -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); diff --git a/tests/Unit/Helpers/MetaPieChartTest.php b/tests/Unit/Helpers/MetaPieChartTest.php index 791e12406d..527ed3ee3b 100644 --- a/tests/Unit/Helpers/MetaPieChartTest.php +++ b/tests/Unit/Helpers/MetaPieChartTest.php @@ -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); diff --git a/tests/Unit/Import/Specifics/RabobankDescriptionTest.php b/tests/Unit/Import/Specifics/RabobankDescriptionTest.php deleted file mode 100644 index f969cd5f66..0000000000 --- a/tests/Unit/Import/Specifics/RabobankDescriptionTest.php +++ /dev/null @@ -1,75 +0,0 @@ -. - */ - -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); - } - -} diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php index e96de4909b..ad52b8cbe5 100644 --- a/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php +++ b/tests/Unit/TransactionRules/Triggers/FromAccountContainsTest.php @@ -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); } } diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php index 5fb022732f..e945255556 100644 --- a/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php +++ b/tests/Unit/TransactionRules/Triggers/FromAccountEndsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php index c746a39b85..280c3459df 100644 --- a/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php +++ b/tests/Unit/TransactionRules/Triggers/FromAccountIsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php index 467f57c438..3527b1547d 100644 --- a/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php +++ b/tests/Unit/TransactionRules/Triggers/FromAccountStartsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php index a441ac7b20..9974e65e03 100644 --- a/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php +++ b/tests/Unit/TransactionRules/Triggers/ToAccountContainsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php index 91d46c04a9..bf78a467ed 100644 --- a/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php +++ b/tests/Unit/TransactionRules/Triggers/ToAccountEndsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php index a2ac324a0e..4a8ff271d1 100644 --- a/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php +++ b/tests/Unit/TransactionRules/Triggers/ToAccountIsTest.php @@ -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); diff --git a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php b/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php index 2eeb5b1fc7..9ed3017438 100644 --- a/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php +++ b/tests/Unit/TransactionRules/Triggers/ToAccountStartsTest.php @@ -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);