mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup and realign.
This commit is contained in:
parent
f7eef25fed
commit
5908c0ce8c
@ -34,7 +34,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
|
@ -54,6 +54,7 @@ class ConfigurationController extends Controller
|
||||
$admin = auth()->user();
|
||||
|
||||
if (!$this->repository->hasRole($admin, 'owner')) {
|
||||
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
|
||||
throw new FireflyException('No access to method.'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,7 @@ class ScanAttachments extends Command
|
||||
$attachment->save();
|
||||
$this->line(sprintf('Fixed attachment #%d', $attachment->id));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ class UpgradeFireflyInstructions extends Command
|
||||
if ('install' === (string)$this->argument('task')) {
|
||||
$this->installInstructions();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ class UseEncryption extends Command
|
||||
$this->handleObjects('Category', 'name', 'encrypted');
|
||||
$this->handleObjects('PiggyBank', 'name', 'encrypted');
|
||||
$this->handleObjects('TransactionJournal', 'description', 'encrypted');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,10 @@ class RequestedNewPassword extends Event
|
||||
|
||||
/** @var string The users IP address */
|
||||
public $ipAddress;
|
||||
/** @var User The user */
|
||||
public $user;
|
||||
/** @var string The token */
|
||||
public $token;
|
||||
/** @var User The user */
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a users tries to reset his or her password.
|
||||
|
@ -28,7 +28,6 @@ use Crypt;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Storage;
|
||||
@ -108,7 +107,7 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
|
||||
if ($this->uploadDisk->exists($file)) {
|
||||
try {
|
||||
$decrypted = Crypt::decrypt($this->uploadDisk->get($file));
|
||||
} catch (FileNotFoundException|DecryptException $e) {
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Catchable error: could not decrypt attachment #' . $attachment->id . ' because: ' . $e->getMessage());
|
||||
|
||||
return false;
|
||||
|
@ -87,6 +87,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage()));
|
||||
$result = 'Could not render report view.';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,8 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
try {
|
||||
$result = view(
|
||||
'reports.tag.month', compact(
|
||||
'accountIds', 'tagTags', 'reportType', 'accountSummary', 'tagSummary', 'averageExpenses', 'averageIncome', 'topIncome', 'topExpenses'
|
||||
'accountIds', 'tagTags', 'reportType', 'accountSummary', 'tagSummary', 'averageExpenses', 'averageIncome', 'topIncome',
|
||||
'topExpenses'
|
||||
)
|
||||
)->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render();
|
||||
} catch (Throwable $e) {
|
||||
|
@ -27,14 +27,12 @@ namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Events\RequestedVersionCheckStatus;
|
||||
|
||||
use FireflyIII\Helpers\Update\UpdateTrait;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
|
||||
|
||||
use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class VersionCheckEventHandler
|
||||
*/
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Attachments;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
@ -80,7 +79,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
|
||||
try {
|
||||
$content = Crypt::decrypt($this->uploadDisk->get(sprintf('at-%d.data', $attachment->id)));
|
||||
} catch (DecryptException|FileNotFoundException $e) {
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
|
||||
$content = '';
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
{
|
||||
$set = $balance->getBalanceLines();
|
||||
$newSet = new Collection;
|
||||
/** @var BalanceLine $entry */
|
||||
foreach ($set as $entry) {
|
||||
if (null !== $entry->getBudget()->id) {
|
||||
$sum = '0';
|
||||
|
@ -55,6 +55,7 @@ class LinkController extends Controller
|
||||
|
||||
/**
|
||||
* Make a new link form.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\BillFormRequest;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\TransactionMatcher;
|
||||
use FireflyIII\Transformers\BillTransformer;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -51,8 +50,6 @@ class BillController extends Controller
|
||||
private $attachments;
|
||||
/** @var BillRepositoryInterface Bill repository */
|
||||
private $billRepository;
|
||||
/** @var RuleGroupRepositoryInterface Rule group repository */
|
||||
private $ruleGroupRepos;
|
||||
|
||||
/**
|
||||
* BillController constructor.
|
||||
@ -72,7 +69,6 @@ class BillController extends Controller
|
||||
app('view')->share('mainTitleIcon', 'fa-calendar-o');
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
$this->billRepository = app(BillRepositoryInterface::class);
|
||||
$this->ruleGroupRepos = app(RuleGroupRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -129,6 +129,7 @@ class AccountController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withBudgetInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getJournals();
|
||||
@ -192,6 +193,7 @@ class AccountController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getJournals();
|
||||
@ -283,6 +285,7 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
// grab all journals:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
$transactions = $collector->getJournals();
|
||||
|
@ -102,6 +102,7 @@ class BillController extends Controller
|
||||
}
|
||||
|
||||
$results = $collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->getJournals();
|
||||
/** @var Collection $results */
|
||||
$results = $results->sortBy(
|
||||
function (Transaction $transaction) {
|
||||
return $transaction->date->format('U');
|
||||
|
@ -325,12 +325,12 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* Shows a budget list with spent/left/overspent.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function frontpage(): \Symfony\Component\HttpFoundation\Response
|
||||
public function frontpage(): JsonResponse
|
||||
{
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
|
@ -168,6 +168,7 @@ class Controller extends BaseController
|
||||
|
||||
/**
|
||||
* Get user's language.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getLanguage(): string
|
||||
|
@ -78,7 +78,7 @@ class ExportController extends Controller
|
||||
}
|
||||
$content = $repository->getContent($job);
|
||||
|
||||
$job->change('export_downloaded');
|
||||
$repository->changeStatus($job, 'export_downloaded');
|
||||
/** @var LaravelResponse $response */
|
||||
$response = response($content, 200);
|
||||
$response
|
||||
|
@ -108,7 +108,9 @@ class HomeController extends Controller
|
||||
}
|
||||
$subTitle = (string)trans('firefly.welcomeBack');
|
||||
$transactions = [];
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
||||
$frontPage = app('preferences')->get(
|
||||
'frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()
|
||||
);
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
|
@ -80,6 +80,7 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
* Generate popup view.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
|
@ -340,6 +340,7 @@ class ProfileController extends Controller
|
||||
|
||||
session()->flash('success', (string)trans('firefly.saved_preferences'));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
@ -371,6 +372,7 @@ class ProfileController extends Controller
|
||||
|
||||
/**
|
||||
* Regenerate access token.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function regenerate()
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\RuleManagement;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -42,8 +41,6 @@ use Throwable;
|
||||
class CreateController extends Controller
|
||||
{
|
||||
use RuleManagement;
|
||||
/** @var BillRepositoryInterface Bill repository */
|
||||
private $billRepos;
|
||||
/** @var RuleRepositoryInterface Rule repository */
|
||||
private $ruleRepos;
|
||||
|
||||
@ -59,7 +56,6 @@ class CreateController extends Controller
|
||||
app('view')->share('title', (string)trans('firefly.rules'));
|
||||
app('view')->share('mainTitleIcon', 'fa-random');
|
||||
|
||||
$this->billRepos = app(BillRepositoryInterface::class);
|
||||
$this->ruleRepos = app(RuleRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
|
@ -34,6 +34,7 @@ use phpseclib\Crypt\RSA;
|
||||
|
||||
/**
|
||||
* Class InstallController
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class InstallController extends Controller
|
||||
|
@ -136,6 +136,7 @@ class LinkController extends Controller
|
||||
|
||||
/**
|
||||
* Switch link from A <> B to B <> A.
|
||||
*
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
|
@ -45,7 +45,7 @@ class TrustProxies extends Middleware
|
||||
{
|
||||
$trustedProxies = (string)env('TRUSTED_PROXIES', null);
|
||||
$this->proxies = explode(',', $trustedProxies);
|
||||
if ($trustedProxies === '**') {
|
||||
if ('**' === $trustedProxies) {
|
||||
$this->proxies = '**';
|
||||
}
|
||||
parent::__construct($config);
|
||||
|
@ -70,7 +70,7 @@ class AccountFormRequest extends Request
|
||||
|
||||
// if the account type is "liabilities" there are actually four types of liability
|
||||
// that could have been selected.
|
||||
if ($data['accountType'] === 'liabilities') {
|
||||
if ('liabilities' === $data['accountType']) {
|
||||
$data['accountType'] = null;
|
||||
$data['account_type_id'] = $this->integer('liability_type_id');
|
||||
// also reverse the opening balance:
|
||||
|
@ -64,6 +64,7 @@ class Request extends FormRequest
|
||||
if (null === $res) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (float)$res;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@ class RuleFormRequest extends Request
|
||||
'rule_triggers' => $this->getRuleTriggerData(),
|
||||
'rule_actions' => $this->getRuleActionData(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ class OpposingAccountIbans implements MapperInterface
|
||||
{
|
||||
/**
|
||||
* Get map of opposing accounts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap(): array
|
||||
|
@ -22,8 +22,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Prerequisites;
|
||||
|
||||
use bunq\Exception\BunqException;
|
||||
use bunq\Util\BunqEnumApiEnvironmentType;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Bunq\ApiContext;
|
||||
use FireflyIII\Services\IP\IPRetrievalInterface;
|
||||
@ -134,7 +134,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
try {
|
||||
$json = $apiContext->toJson();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (BunqException $e) {
|
||||
} catch (Exception $e) {
|
||||
$messages = new MessageBag();
|
||||
$messages->add('bunq_error', $e->getMessage());
|
||||
|
||||
|
@ -86,10 +86,11 @@ class YnabRoutine implements RoutineInterface
|
||||
if (\count($budgets) > 1) {
|
||||
$this->repository->setStage($this->importJob, 'select_budgets');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (\count($budgets) === 1) {
|
||||
if (1 === \count($budgets)) {
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
$this->repository->setStage($this->importJob, 'get_accounts');
|
||||
}
|
||||
@ -106,6 +107,7 @@ class YnabRoutine implements RoutineInterface
|
||||
|
||||
$this->repository->setStage($this->importJob, 'select_accounts');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
}
|
||||
if ('go-for-import' === $this->importJob->stage) {
|
||||
@ -117,6 +119,7 @@ class YnabRoutine implements RoutineInterface
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
function (Rule $rule) use ($journal) {
|
||||
Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
|
||||
$processor = Processor::make($rule);
|
||||
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
|
||||
$processor->handleTransactionJournal($journal);
|
||||
if ($rule->stop_processing) {
|
||||
return;
|
||||
|
@ -110,9 +110,9 @@ class Bill extends Model
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Attachment::class, 'attachable');
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Models;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@ -91,9 +92,9 @@ class ImportJob extends Model
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Attachment::class, 'attachable');
|
||||
}
|
||||
|
@ -237,6 +237,7 @@ class Transaction extends Model
|
||||
|
||||
/**
|
||||
* Check for transactions BEFORE the specified date.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Builder $query
|
||||
|
@ -150,9 +150,9 @@ class TransactionJournal extends Model
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Attachment::class, 'attachable');
|
||||
}
|
||||
|
@ -45,9 +45,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
*/
|
||||
class TransactionJournalLink extends Model
|
||||
{
|
||||
/** @var string The table to store the data in */
|
||||
protected $table = 'journal_links';
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
@ -58,6 +55,8 @@ class TransactionJournalLink extends Model
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
/** @var string The table to store the data in */
|
||||
protected $table = 'journal_links';
|
||||
|
||||
/**
|
||||
* Route binder. Converts the key in the URL to the specified object (or throw 404).
|
||||
|
@ -26,6 +26,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Passport\Passport;
|
||||
use URL;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class AppServiceProvider.
|
||||
|
@ -303,6 +303,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
if (null === $note) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
@ -450,6 +451,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
|
@ -50,6 +50,7 @@ interface AttachmentRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param int $attachmentId
|
||||
*
|
||||
* @return Attachment|null
|
||||
*/
|
||||
public function findWithoutUser(int $attachmentId): ?Attachment;
|
||||
|
@ -48,7 +48,8 @@ class ExportJobRepository implements ExportJobRepositoryInterface
|
||||
public function changeStatus(ExportJob $job, string $status): bool
|
||||
{
|
||||
Log::debug(sprintf('Change status of job #%d to "%s"', $job->id, $status));
|
||||
$job->change($status);
|
||||
$job->status = $status;
|
||||
$job->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ interface ExportJobRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return ExportJob|null
|
||||
*/
|
||||
public function findByKey(string $key): ?ExportJob;
|
||||
|
@ -184,6 +184,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
$newConfig = array_merge($currentConfig, $configuration);
|
||||
$job->configuration = $newConfig;
|
||||
$job->save();
|
||||
|
||||
//Log::debug(sprintf('Set config of job "%s" to: ', $job->key), $newConfig);
|
||||
|
||||
return $job;
|
||||
|
@ -54,6 +54,7 @@ interface ImportJobRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function findByKey(string $key): ?ImportJob;
|
||||
|
@ -707,6 +707,8 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(TransactionJournal $journal, array $data): TransactionJournal
|
||||
{
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Repositories\Journal;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
|
@ -60,7 +60,7 @@ class UpdateRequest implements GithubRequest
|
||||
}
|
||||
try {
|
||||
$releaseXml = new SimpleXMLElement($res->getBody()->getContents(), LIBXML_NOCDATA);
|
||||
} catch (RunTimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from github updat result: %s', $e->getMessage()));
|
||||
$releaseXml = new SimpleXMLElement('');
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RunTimeException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class IpifyOrg
|
||||
@ -58,7 +58,7 @@ class IpifyOrg implements IPRetrievalInterface
|
||||
}
|
||||
try {
|
||||
$body = (string)$res->getBody()->getContents();
|
||||
} catch (RunTimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from ipify.org result: %s', $e->getMessage()));
|
||||
$body = null;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionTypeFactory;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
|
||||
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
|
||||
|
@ -67,7 +67,7 @@ class PwndVerifierV2 implements Verifier
|
||||
}
|
||||
try {
|
||||
$strpos = stripos($res->getBody()->getContents(), $rest);
|
||||
} catch (RunTimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage()));
|
||||
$strpos = false;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
||||
/**
|
||||
*
|
||||
* Class Attempt
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
|
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Login
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
|
@ -27,6 +27,7 @@ use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NewCustomerRequest
|
||||
*/
|
||||
|
@ -211,7 +211,7 @@ abstract class SpectreRequest
|
||||
$statusCode = $res->getStatusCode();
|
||||
try {
|
||||
$returnBody = $res->getBody()->getContents();
|
||||
} catch (RunTimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::GET result: %s', $e->getMessage()));
|
||||
$returnBody = '';
|
||||
}
|
||||
@ -261,7 +261,7 @@ abstract class SpectreRequest
|
||||
|
||||
try {
|
||||
$body = $res->getBody()->getContents();
|
||||
} catch (RunTimeException $e) {
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
|
||||
$body = '';
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Amount
|
||||
$space = ' ';
|
||||
|
||||
// require space between symbol and amount?
|
||||
if ($sepBySpace === false) {
|
||||
if (false === $sepBySpace) {
|
||||
$space = ''; // no
|
||||
}
|
||||
|
||||
@ -134,8 +134,8 @@ class Amount
|
||||
// some complicated switches to format the amount correctly:
|
||||
$precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes'];
|
||||
$separated = $amount < 0 ? $info['n_sep_by_space'] : $info['p_sep_by_space'];
|
||||
$space = $separated === true ? ' ' : '';
|
||||
$result = $precedes === false ? $formatted . $space . $format->symbol : $format->symbol . $space . $formatted;
|
||||
$space = true === $separated ? ' ' : '';
|
||||
$result = false === $precedes ? $formatted . $space . $format->symbol : $format->symbol . $space . $formatted;
|
||||
|
||||
if (true === $coloured) {
|
||||
if ($amount > 0) {
|
||||
|
@ -59,7 +59,7 @@ class SelectBudgetHandler implements YnabJobConfigurationInterface
|
||||
Log::debug('Now in SelectBudgetHandler::configComplete');
|
||||
$configuration = $this->repository->getConfiguration($this->importJob);
|
||||
$selectedBudget = $configuration['selected_budget'] ?? '';
|
||||
if ($selectedBudget !== '') {
|
||||
if ('' !== $selectedBudget) {
|
||||
Log::debug(sprintf('Selected budget is %s, config is complete. Return true.', $selectedBudget));
|
||||
$this->repository->setStage($this->importJob, 'get_accounts');
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Import\JobConfiguration\Ynab;
|
||||
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
|
@ -147,6 +147,7 @@ class ImportableConverter
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ class ImportDataHandler
|
||||
$destination = $this->mapper->map($possibleDestinationId, $amount, $destinationData);
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
[$source, $destination] = [$destination, $source];
|
||||
$type = $type === 'transfer' ? 'transfer' : 'deposit';
|
||||
$type = 'transfer' === $type ? 'transfer' : 'deposit';
|
||||
Log::debug(sprintf('Amount is %s, so switch source/dest and make this a %s', $amount, $type));
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class StageGetBudgetsHandler
|
||||
$configuration['budgets'] = $request->budgets;
|
||||
$this->repository->setConfiguration($this->importJob, $configuration);
|
||||
Log::debug(sprintf('Found %d budgets', \count($request->budgets)));
|
||||
if (\count($request->budgets) === 0) {
|
||||
if (0 === \count($request->budgets)) {
|
||||
throw new FireflyException('It seems this user has zero budgets or an error prevented Firefly III from reading them.');
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ class Preferences
|
||||
if (\is_array($lastActivity)) {
|
||||
$lastActivity = implode(',', $lastActivity);
|
||||
}
|
||||
|
||||
return md5($lastActivity);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class General extends Twig_Extension
|
||||
$this->balance(),
|
||||
$this->formatFilesize(),
|
||||
$this->mimeIcon(),
|
||||
$this->markdown()
|
||||
$this->markdown(),
|
||||
];
|
||||
}
|
||||
|
||||
@ -249,6 +249,7 @@ class General extends Twig_Extension
|
||||
if ($repository->hasRole(auth()->user(), $role)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
@ -69,7 +69,6 @@ class Translation extends Twig_Extension
|
||||
'journalLinkTranslation',
|
||||
function (string $direction, string $original) {
|
||||
$key = sprintf('firefly.%s_%s', $original, $direction);
|
||||
return $key;
|
||||
$translation = trans($key);
|
||||
|
||||
if ($key === $translation) {
|
||||
|
@ -86,7 +86,7 @@ final class Processor
|
||||
Log::debug(sprintf('Push trigger %d', $trigger->id));
|
||||
$self->triggers->push(TriggerFactory::getTrigger($trigger));
|
||||
}
|
||||
if ($includeActions === true) {
|
||||
if (true === $includeActions) {
|
||||
$self->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
|
||||
|
@ -195,15 +195,15 @@ class TransactionMatcher
|
||||
$allTriggers = $this->rule->ruleTriggers()->whereIn('trigger_type', $valid)->get();
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($allTriggers as $trigger) {
|
||||
if ($trigger->trigger_type === 'amount_less') {
|
||||
if ('amount_less' === $trigger->trigger_type) {
|
||||
$this->maxAmount = $trigger->trigger_value;
|
||||
Log::debug(sprintf('Set max amount to be %s', $trigger->trigger_value));
|
||||
}
|
||||
if ($trigger->trigger_type === 'amount_more') {
|
||||
if ('amount_more' === $trigger->trigger_type) {
|
||||
$this->minAmount = $trigger->trigger_value;
|
||||
Log::debug(sprintf('Set min amount to be %s', $trigger->trigger_value));
|
||||
}
|
||||
if ($trigger->trigger_type === 'amount_exactly') {
|
||||
if ('amount_exactly' === $trigger->trigger_type) {
|
||||
$this->exactAmount = $trigger->trigger_value;
|
||||
Log::debug(sprintf('Set exact amount to be %s', $trigger->trigger_value));
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class AccountTransformer extends TransformerAbstract
|
||||
|
||||
$type = $account->accountType->type;
|
||||
$role = $this->repository->getMetaValue($account, 'accountRole');
|
||||
if ($type !== AccountType::ASSET || (string)$role === '') {
|
||||
if ($type !== AccountType::ASSET || '' === (string)$role) {
|
||||
$role = null;
|
||||
}
|
||||
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
|
||||
@ -167,13 +167,13 @@ class AccountTransformer extends TransformerAbstract
|
||||
$date = $this->parameters->get('date');
|
||||
}
|
||||
|
||||
if ($currencyId === 0) {
|
||||
if (0 === $currencyId) {
|
||||
$currencyId = null;
|
||||
}
|
||||
|
||||
$monthlyPaymentDate = null;
|
||||
$creditCardType = null;
|
||||
if ($role === 'ccAsset' && $type === AccountType::ASSET) {
|
||||
if ('ccAsset' === $role && $type === AccountType::ASSET) {
|
||||
$creditCardType = $this->repository->getMetaValue($account, 'ccType');
|
||||
$monthlyPaymentDate = $this->repository->getMetaValue($account, 'ccMonthlyPaymentDate');
|
||||
}
|
||||
@ -194,7 +194,7 @@ class AccountTransformer extends TransformerAbstract
|
||||
'updated_at' => $account->updated_at->toAtomString(),
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
'name' => $account->name,
|
||||
'active' => (int)$account->active === 1,
|
||||
'active' => 1 === (int)$account->active,
|
||||
'type' => $type,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $currencyCode,
|
||||
|
@ -118,7 +118,7 @@ class BudgetTransformer extends TransformerAbstract
|
||||
'id' => (int)$budget->id,
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'created_at' => $budget->created_at->toAtomString(),
|
||||
'active' => (int)$budget->active === 1,
|
||||
'active' => 1 === (int)$budget->active,
|
||||
'name' => $budget->name,
|
||||
'links' => [
|
||||
[
|
||||
|
@ -29,6 +29,9 @@ use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class CurrencyExchangeRateTransformer
|
||||
*/
|
||||
class CurrencyExchangeRateTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
@ -79,6 +82,11 @@ class CurrencyExchangeRateTransformer extends TransformerAbstract
|
||||
return $this->item($rate->toCurrency, new CurrencyTransformer($this->parameters), 'transaction_currencies');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyExchangeRate $rate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(CurrencyExchangeRate $rate): array
|
||||
{
|
||||
$data = [
|
||||
|
@ -95,6 +95,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
@ -130,6 +131,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
$currency = $repository->findNull($currencyId);
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$decimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ class PiggyBankTransformer extends TransformerAbstract
|
||||
'start_date' => $startDate,
|
||||
'target_date' => $targetDate,
|
||||
'order' => (int)$piggyBank->order,
|
||||
'active' => (int)$piggyBank->active === 1,
|
||||
'active' => 1 === (int)$piggyBank->active,
|
||||
'notes' => null,
|
||||
'links' => [
|
||||
[
|
||||
|
@ -28,6 +28,9 @@ use FireflyIII\Models\Preference;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class PreferenceTransformer
|
||||
*/
|
||||
class PreferenceTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
@ -45,6 +48,11 @@ class PreferenceTransformer extends TransformerAbstract
|
||||
/** @var ParameterBag */
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* PreferenceTransformer constructor.
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
public function __construct(ParameterBag $parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
@ -121,7 +121,7 @@ class TagTransformer extends TransformerAbstract
|
||||
'tag' => $tag->tag,
|
||||
'tag_mode' => $tag->tagMode,
|
||||
'date' => $date,
|
||||
'description' => $tag->description === '' ? null : $tag->description,
|
||||
'description' => '' === $tag->description ? null : $tag->description,
|
||||
'latitude' => (float)$tag->latitude,
|
||||
'longitude' => (float)$tag->longitude,
|
||||
'zoom_level' => (int)$tag->zoomLevel,
|
||||
|
@ -193,7 +193,7 @@ class UserTransformer extends TransformerAbstract
|
||||
'updated_at' => $user->updated_at->toAtomString(),
|
||||
'created_at' => $user->created_at->toAtomString(),
|
||||
'email' => $user->email,
|
||||
'blocked' => (int)$user->blocked === 1,
|
||||
'blocked' => 1 === (int)$user->blocked,
|
||||
'blocked_code' => $user->blocked_code,
|
||||
'role' => $role,
|
||||
'links' => [
|
||||
|
@ -216,7 +216,7 @@ class User extends Authenticatable
|
||||
{
|
||||
$bytes = random_bytes(16);
|
||||
|
||||
return (string)bin2hex($bytes);
|
||||
return bin2hex($bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,7 +243,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param string $attribute
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@ -412,7 +414,7 @@ class FireflyValidator extends Validator
|
||||
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$accountId = (int)($this->data['id'] ?? 0.0);
|
||||
if ($accountId === 0) {
|
||||
if (0 === $accountId) {
|
||||
$accountId = (int)($parameters[0] ?? 0.0);
|
||||
}
|
||||
|
||||
@ -421,7 +423,7 @@ class FireflyValidator extends Validator
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
->where('account_meta.name', 'accountNumber');
|
||||
|
||||
if ((int)$accountId > 0) {
|
||||
if ($accountId > 0) {
|
||||
// exclude current account from check.
|
||||
$query->where('account_meta.account_id', '!=', $accountId);
|
||||
}
|
||||
@ -513,66 +515,6 @@ class FireflyValidator extends Validator
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleActionName(int $index): string
|
||||
{
|
||||
$name = $this->data['rule-action'][$index] ?? 'invalid';
|
||||
if (!isset($this->data['rule-action'][$index])) {
|
||||
$name = $this->data['rule-actions'][$index]['name'] ?? 'invalid';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleActionValue(int $index): string
|
||||
{
|
||||
$value = $this->data['rule-action-value'][$index] ?? '';
|
||||
if (!isset($this->data['rule-action-value'][$index])) {
|
||||
$value = $this->data['rule-actions'][$index]['value'] ?? '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleTriggerName(int $index): string
|
||||
{
|
||||
$name = $this->data['rule-trigger'][$index] ?? 'invalid';
|
||||
if (!isset($this->data['rule-trigger'][$index])) {
|
||||
$name = $this->data['rule-triggers'][$index]['name'] ?? 'invalid';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRuleTriggerValue(int $index): string
|
||||
{
|
||||
$value = $this->data['rule-trigger-value'][$index] ?? '';
|
||||
if (!isset($this->data['rule-trigger-value'][$index])) {
|
||||
$value = $this->data['rule-triggers'][$index]['value'] ?? '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
@ -627,6 +569,7 @@ class FireflyValidator extends Validator
|
||||
$ignore = $existingAccount->id;
|
||||
$value = $this->tryDecrypt($value);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
@ -650,6 +593,7 @@ class FireflyValidator extends Validator
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$value = $this->tryDecrypt($value);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
@ -37,6 +37,39 @@ use Log;
|
||||
*/
|
||||
trait RecurrenceValidation
|
||||
{
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (0 === \count($repetitions)) {
|
||||
$validator->errors()->add('description', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the recurrence has valid repetition information. It either doesn't stop,
|
||||
* or stops after X times or at X date. Not both of them.,
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRecurrenceRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['nr_of_repetitions'] ?? null;
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*/
|
||||
@ -73,39 +106,6 @@ trait RecurrenceValidation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (\count($repetitions) === 0) {
|
||||
$validator->errors()->add('description', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the recurrence has valid repetition information. It either doesn't stop,
|
||||
* or stops after X times or at X date. Not both of them.,
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRecurrenceRepetition(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['nr_of_repetitions'] ?? null;
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the repetition type is daily, the moment should be empty.
|
||||
*
|
||||
@ -145,7 +145,7 @@ trait RecurrenceValidation
|
||||
protected function validateNdom(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
$parameters = explode(',', $moment);
|
||||
if (\count($parameters) !== 2) {
|
||||
if (2 !== \count($parameters)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
|
@ -338,13 +338,13 @@ trait TransactionValidation
|
||||
if ($accountId < 1 && '' === $accountName) {
|
||||
return null;
|
||||
}
|
||||
if ($accountId !== 0) {
|
||||
if (0 !== $accountId) {
|
||||
// ID belongs to user and is $type account:
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($admin);
|
||||
$set = $repository->getAccountsById([$accountId]);
|
||||
if ($set->count() === 1) {
|
||||
if (1 === $set->count()) {
|
||||
/** @var Account $first */
|
||||
$first = $set->first();
|
||||
if ($first->accountType->type !== $type) {
|
||||
|
@ -806,7 +806,6 @@ Route::group(
|
||||
Route::post('update/{rule}', ['uses' => 'Rule\EditController@update', 'as' => 'update']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -127,6 +127,7 @@ class BillControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* Store with minimum amount more than maximum amount
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
*/
|
||||
|
@ -97,7 +97,8 @@ class CurrencyControllerTest extends TestCase
|
||||
$response = $this->get('/api/v1/currencies');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson([
|
||||
$response->assertJson(
|
||||
[
|
||||
'meta' => [
|
||||
'pagination' => [
|
||||
'total' => $collection->count(),
|
||||
|
@ -103,40 +103,6 @@ class CurrencyExchangeRateControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
@ -170,4 +136,38 @@ class CurrencyExchangeRateControllerTest extends TestCase
|
||||
$response->assertSee('Unknown destination currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -749,12 +749,12 @@ class RecurrenceControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
@ -776,6 +776,19 @@ class RecurrenceControllerTest extends TestCase
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
|
||||
// entries used by the transformer
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Note text');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
// entries used by the transformer (the fake entry has a category + a budget):
|
||||
$factory->shouldReceive('findOrCreate')->andReturn(null);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
@ -792,12 +805,13 @@ class RecurrenceControllerTest extends TestCase
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
'destination_id' => $assetAccount->id,
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'weekly',
|
||||
'moment' => '8',
|
||||
'type' => 'daily',
|
||||
'moment' => '',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
@ -811,8 +825,8 @@ class RecurrenceControllerTest extends TestCase
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'repetitions.0.moment' => [
|
||||
'Invalid repetition moment for this type of repetition.',
|
||||
'transactions.0.destination_id' => [
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
],
|
||||
]
|
||||
@ -967,6 +981,79 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$factory = $this->mock(CategoryFactory::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$factory->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
$firstDate->addDays(2);
|
||||
$data = [
|
||||
'type' => 'withdrawal',
|
||||
'title' => 'Hello',
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'apply_rules' => 1,
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'ndom',
|
||||
'moment' => '9',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'repetitions.0.moment' => [
|
||||
'Invalid repetition moment for this type of repetition.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
@ -1046,7 +1133,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
@ -1088,8 +1175,8 @@ class RecurrenceControllerTest extends TestCase
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'ndom',
|
||||
'moment' => '9',
|
||||
'type' => 'weekly',
|
||||
'moment' => '8',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
@ -1113,93 +1200,6 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$factory = $this->mock(CategoryFactory::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$factory->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once()
|
||||
->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
|
||||
// entries used by the transformer
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Note text');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
// entries used by the transformer (the fake entry has a category + a budget):
|
||||
$factory->shouldReceive('findOrCreate')->andReturn(null);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
$firstDate->addDays(2);
|
||||
$data = [
|
||||
'type' => 'withdrawal',
|
||||
'title' => 'Hello',
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'apply_rules' => 1,
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description',
|
||||
'source_id' => '1',
|
||||
'destination_id' => $assetAccount->id,
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'daily',
|
||||
'moment' => '',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
|
||||
$response->assertExactJson(
|
||||
[
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'transactions.0.destination_id' => [
|
||||
'This value is invalid for this field.',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertStatus(422);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit without a source account.
|
||||
*
|
||||
|
@ -27,7 +27,6 @@ namespace Tests\Feature\Controllers\Account;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
|
@ -30,8 +30,9 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class DeleteControllerTest
|
||||
@ -46,6 +47,7 @@ class DeleteControllerTest extends TestCase
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\DeleteController
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
|
@ -26,16 +26,16 @@ namespace Tests\Feature\Controllers\Account;
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class EditControllerTest
|
||||
@ -50,6 +50,7 @@ class EditControllerTest extends TestCase
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
*/
|
||||
|
@ -32,8 +32,8 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ConfigurationControllerTest
|
||||
|
@ -27,7 +27,6 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@ -314,6 +313,38 @@ class BillControllerTest extends TestCase
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BillController::store
|
||||
* @covers \FireflyIII\Http\Requests\BillFormRequest
|
||||
* @covers \FireflyIII\Http\Requests\Request
|
||||
*/
|
||||
public function testStoreError(): void
|
||||
{
|
||||
// mock stuff
|
||||
$attachHelper = $this->mock(AttachmentHelperInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('store')->andReturn(null);
|
||||
|
||||
$data = [
|
||||
'name' => 'New Bill ' . random_int(1000, 9999),
|
||||
'amount_min' => '100',
|
||||
'transaction_currency_id' => 1,
|
||||
'skip' => 0,
|
||||
'strict' => 1,
|
||||
'amount_max' => '100',
|
||||
'date' => '2016-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('bills.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertRedirect(route('bills.create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BillController::store
|
||||
* @covers \FireflyIII\Http\Requests\BillFormRequest
|
||||
@ -349,38 +380,6 @@ class BillControllerTest extends TestCase
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BillController::store
|
||||
* @covers \FireflyIII\Http\Requests\BillFormRequest
|
||||
* @covers \FireflyIII\Http\Requests\Request
|
||||
*/
|
||||
public function testStoreError(): void
|
||||
{
|
||||
// mock stuff
|
||||
$attachHelper = $this->mock(AttachmentHelperInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('store')->andReturn(null);
|
||||
|
||||
$data = [
|
||||
'name' => 'New Bill ' . random_int(1000, 9999),
|
||||
'amount_min' => '100',
|
||||
'transaction_currency_id' => 1,
|
||||
'skip' => 0,
|
||||
'strict' => 1,
|
||||
'amount_max' => '100',
|
||||
'date' => '2016-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('bills.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertRedirect(route('bills.create'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BillController::update
|
||||
* @covers \FireflyIII\Http\Requests\BillFormRequest
|
||||
|
@ -24,13 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Category;
|
||||
|
||||
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@ -38,7 +34,10 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ShowControllerTest
|
||||
|
@ -29,8 +29,9 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class CurrencyControllerTest
|
||||
*
|
||||
|
@ -22,11 +22,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use Mockery;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
@ -34,6 +33,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -167,7 +167,6 @@ class IndexControllerTest extends TestCase
|
||||
$ynabPrerequisites->shouldReceive('setUser')->times(2);
|
||||
|
||||
|
||||
|
||||
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
|
||||
|
||||
|
@ -107,6 +107,28 @@ class JavascriptControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @dataProvider dateRangeProvider
|
||||
*/
|
||||
public function testVariablesCustom(string $range): void
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$this->session(['is_custom_range' => true]);
|
||||
$response = $this->get(route('javascript.variables'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
|
||||
@ -132,27 +154,4 @@ class JavascriptControllerTest extends TestCase
|
||||
$response = $this->get(route('javascript.variables'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::variables
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
* @dataProvider dateRangeProvider
|
||||
*/
|
||||
public function testVariablesCustom(string $range): void
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$this->session(['is_custom_range' => true]);
|
||||
$response = $this->get(route('javascript.variables'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
|
@ -108,23 +108,6 @@ class AutoCompleteControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testCurrencyNames(): void
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$currency = TransactionCurrency::find(1);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.currency-names'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson(['Euro']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
@ -159,6 +142,22 @@ class AutoCompleteControllerTest extends TestCase
|
||||
$response->assertExactJson([$category->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testCurrencyNames(): void
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$currency = TransactionCurrency::find(1);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.currency-names'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson(['Euro']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
|
@ -171,17 +171,20 @@ class BoxControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorthVirtual(): void
|
||||
public function testNetWorthFuture(): void
|
||||
{
|
||||
$account = $this->user()->accounts()->first();
|
||||
$account->virtual_balance = '1000';
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
|
||||
$start = new Carbon;
|
||||
$start->addMonths(6)->startOfMonth();
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
$this->session(['start' => $start, 'end' => $end]);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
$response->assertStatus(200);
|
||||
@ -207,20 +210,17 @@ class BoxControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorthFuture(): void
|
||||
public function testNetWorthVirtual(): void
|
||||
{
|
||||
$account = $this->user()->accounts()->first();
|
||||
$account->virtual_balance = '1000';
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
|
||||
$start = new Carbon;
|
||||
$start->addMonths(6)->startOfMonth();
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
$this->session(['start' => $start, 'end' => $end]);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
$response->assertStatus(200);
|
||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace tests\Feature\Controllers\Rule;
|
||||
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
|
@ -75,32 +75,6 @@ class BulkControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal, null);
|
||||
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(4)->get()->pluck('id')->toArray();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.bulk.edit', $transfers));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Bulk edit a number of transactions');
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController::edit
|
||||
*/
|
||||
@ -136,6 +110,32 @@ class BulkControllerTest extends TestCase
|
||||
$response->assertSee('multiple destination accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal, null);
|
||||
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(4)->get()->pluck('id')->toArray();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.bulk.edit', $transfers));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Bulk edit a number of transactions');
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController::update
|
||||
* @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user