diff --git a/.env.example b/.env.example
index 43489c81a4..c675305fa5 100644
--- a/.env.example
+++ b/.env.example
@@ -8,8 +8,8 @@ APP_DEBUG=false
# This should be your email address
SITE_OWNER=mail@example.com
-# The encryption key for your database and sessions. Keep this very secure.
-# If you generate a new one all existing data must be considered LOST.
+# The encryption key for your sessions. Keep this very secure.
+# If you generate a new one existing data must be considered LOST.
# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it
APP_KEY=SomeRandomStringOf32CharsExactly
@@ -103,8 +103,8 @@ MAPBOX_API_KEY=
# Firefly III currently supports two provider for live Currency Exchange Rates:
# "fixer" is the default (for backward compatibility), and "ratesapi" is the new one.
# RatesApi.IO (see https://ratesapi.io) is a FREE and OPEN SOURCE live currency exchange rates,
-# built compatible with Fixer.IO, based on data published by European Central Bank, and don't require API key.
-CER_PROVIDER=fixer
+# built compatible with Fixer.IO, based on data published by European Central Bank, and doesn't require API key.
+CER_PROVIDER=ratesapi
# If you have select "fixer" as default currency exchange rates,
# set a Fixer IO API key here (see https://fixer.io) to enable live currency exchange rates.
# Please note that this WILL ONLY WORK FOR PAID fixer.io accounts because they severely limited
diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php
index acf1a0749f..dcbb85111d 100644
--- a/app/Factory/TransactionJournalFactory.php
+++ b/app/Factory/TransactionJournalFactory.php
@@ -245,11 +245,13 @@ class TransactionJournalFactory
/** create or get source and destination accounts */
$sourceAccount = $this->getAccount($type->type, 'source', (int)$row['source_id'], $row['source_name']);
$destinationAccount = $this->getAccount($type->type, 'destination', (int)$row['destination_id'], $row['destination_name']);
+ // @codeCoverageIgnoreStart
} catch (FireflyException $e) {
Log::error($e->getMessage());
return null;
}
+ // @codeCoverageIgnoreEnd
// TODO After 4.8.0 better handling below:
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index d827a2371d..9bc9a38fa3 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -96,7 +96,7 @@ class AccountFormRequest extends Request
'name' => 'required|min:1|uniqueAccountForUser',
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
- 'iban' => ['iban', 'nullable', new UniqueIban(null, $this->string('what'))],
+ 'iban' => ['iban', 'nullable', new UniqueIban(null, $this->string('objectType'))],
'BIC' => 'bic|nullable',
'virtual_balance' => 'numeric|nullable',
'currency_id' => 'exists:transaction_currencies,id',
diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php
index 95ebf86877..e77c04ee40 100644
--- a/app/Jobs/CreateRecurringTransactions.php
+++ b/app/Jobs/CreateRecurringTransactions.php
@@ -49,9 +49,7 @@ use Carbon\Carbon;
use FireflyIII\Events\RequestedReportOnJournals;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Factory\PiggyBankEventFactory;
-use FireflyIII\Factory\PiggyBankFactory;
use FireflyIII\Models\Recurrence;
-use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\TransactionGroup;
@@ -94,16 +92,26 @@ class CreateRecurringTransactions implements ShouldQueue
/** @var int Transaction groups created */
public $created;
+ /**
+ * @param Carbon $date
+ */
+ public function setDate(Carbon $date): void
+ {
+ $this->date = $date;
+ }
+
/**
* Create a new job instance.
* @codeCoverageIgnore
*
* @param Carbon $date
*/
- public function __construct(Carbon $date)
+ public function __construct(?Carbon $date)
{
- $date->startOfDay();
- $this->date = $date;
+ if (null !== $date) {
+ $date->startOfDay();
+ $this->date = $date;
+ }
$this->repository = app(RecurringRepositoryInterface::class);
$this->journalRepository = app(JournalRepositoryInterface::class);
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
diff --git a/app/Jobs/MailError.php b/app/Jobs/MailError.php
index 33d40834b6..aeb2546115 100644
--- a/app/Jobs/MailError.php
+++ b/app/Jobs/MailError.php
@@ -32,6 +32,7 @@ use Mail;
/**
* Class MailError.
+ * @codeCoverageIgnore
*/
class MailError extends Job implements ShouldQueue
{
diff --git a/app/Mail/AccessTokenCreatedMail.php b/app/Mail/AccessTokenCreatedMail.php
index 67690ef21b..65d702602e 100644
--- a/app/Mail/AccessTokenCreatedMail.php
+++ b/app/Mail/AccessTokenCreatedMail.php
@@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class AccessTokenCreatedMail
+ * @codeCoverageIgnore
*/
class AccessTokenCreatedMail extends Mailable
{
diff --git a/app/Mail/AdminTestMail.php b/app/Mail/AdminTestMail.php
index a87537597a..17e24ed50f 100644
--- a/app/Mail/AdminTestMail.php
+++ b/app/Mail/AdminTestMail.php
@@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
* Class AdminTestMail.
*
* Sends a test mail to administrators.
+ * @codeCoverageIgnore
*/
class AdminTestMail extends Mailable
{
diff --git a/app/Mail/ConfirmEmailChangeMail.php b/app/Mail/ConfirmEmailChangeMail.php
index 780f840975..74d8c8b75e 100644
--- a/app/Mail/ConfirmEmailChangeMail.php
+++ b/app/Mail/ConfirmEmailChangeMail.php
@@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
* Class ConfirmEmailChangeMail
*
* Sends message to new address to confirm change.
+ * @codeCoverageIgnore
*/
class ConfirmEmailChangeMail extends Mailable
{
diff --git a/app/Mail/OAuthTokenCreatedMail.php b/app/Mail/OAuthTokenCreatedMail.php
index 7b9553a543..f8729a4ce2 100644
--- a/app/Mail/OAuthTokenCreatedMail.php
+++ b/app/Mail/OAuthTokenCreatedMail.php
@@ -31,6 +31,7 @@ use Laravel\Passport\Client;
/**
* Class OAuthTokenCreatedMail
+ * @codeCoverageIgnore
*/
class OAuthTokenCreatedMail extends Mailable
{
diff --git a/app/Mail/RegisteredUser.php b/app/Mail/RegisteredUser.php
index fd6d589b8c..c66955da2b 100644
--- a/app/Mail/RegisteredUser.php
+++ b/app/Mail/RegisteredUser.php
@@ -31,6 +31,7 @@ use Illuminate\Queue\SerializesModels;
* Sends newly registered user an email message.
*
* Class RegisteredUser
+ * @codeCoverageIgnore
*/
class RegisteredUser extends Mailable
{
diff --git a/app/Mail/ReportNewJournalsMail.php b/app/Mail/ReportNewJournalsMail.php
index 2d4120144b..5c38a2173a 100644
--- a/app/Mail/ReportNewJournalsMail.php
+++ b/app/Mail/ReportNewJournalsMail.php
@@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
* Class ReportNewJournalsMail.
*
* Sends a list of newly created journals to the user.
+ * @codeCoverageIgnore
*/
class ReportNewJournalsMail extends Mailable
{
diff --git a/app/Mail/RequestedNewPassword.php b/app/Mail/RequestedNewPassword.php
index 5811a36a1f..bc102856e4 100644
--- a/app/Mail/RequestedNewPassword.php
+++ b/app/Mail/RequestedNewPassword.php
@@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Sends user link for new password.
* Class RequestedNewPassword
+ * @codeCoverageIgnore
*/
class RequestedNewPassword extends Mailable
{
diff --git a/app/Mail/UndoEmailChangeMail.php b/app/Mail/UndoEmailChangeMail.php
index 20e5b6ec4f..69deb68073 100644
--- a/app/Mail/UndoEmailChangeMail.php
+++ b/app/Mail/UndoEmailChangeMail.php
@@ -28,6 +28,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class UndoEmailChangeMail
+ * @codeCoverageIgnore
*/
class UndoEmailChangeMail extends Mailable
{
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index 20917cc563..4afe6a89c7 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -46,11 +46,11 @@ use Session;
/**
* Class EventServiceProvider.
+ * @codeCoverageIgnore
*/
class EventServiceProvider extends ServiceProvider
{
/**
- * @codeCoverageIgnore
* The event listener mappings for the application.
*
* @var array
@@ -103,7 +103,6 @@ class EventServiceProvider extends ServiceProvider
];
/**
- * @codeCoverageIgnore
* Register any events for your application.
*/
public function boot(): void
@@ -119,7 +118,7 @@ class EventServiceProvider extends ServiceProvider
{
// in case of repeated piggy banks and/or other problems.
PiggyBank::created(
- function (PiggyBank $piggyBank) {
+ static function (PiggyBank $piggyBank) {
$repetition = new PiggyBankRepetition;
$repetition->piggyBank()->associate($piggyBank);
$repetition->startdate = $piggyBank->startdate;
@@ -129,7 +128,7 @@ class EventServiceProvider extends ServiceProvider
}
);
Client::created(
- function (Client $oauthClient) {
+ static function (Client $oauthClient) {
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$user = $repository->findNull((int)$oauthClient->user_id);
diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php
index f2d46f00be..d297c39294 100644
--- a/app/Providers/FireflyServiceProvider.php
+++ b/app/Providers/FireflyServiceProvider.php
@@ -50,7 +50,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Services\Currency\ExchangeRateInterface;
use FireflyIII\Services\IP\IpifyOrg;
use FireflyIII\Services\IP\IPRetrievalInterface;
-use FireflyIII\Services\Password\PwndVerifierV2;
+use FireflyIII\Services\Password\PwndVerifierV3;
use FireflyIII\Services\Password\Verifier;
use FireflyIII\Support\Amount;
use FireflyIII\Support\ExpandedForm;
@@ -183,7 +183,7 @@ class FireflyServiceProvider extends ServiceProvider
$this->app->bind(ExchangeRateInterface::class, $class);
// password verifier thing
- $this->app->bind(Verifier::class, PwndVerifierV2::class);
+ $this->app->bind(Verifier::class, PwndVerifierV3::class);
// IP thing:
$this->app->bind(IPRetrievalInterface::class, IpifyOrg::class);
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 6baabbc137..ce863f788c 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -57,17 +57,6 @@ class AccountRepository implements AccountRepositoryInterface
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
-
- /**
- * @param array $types
- *
- * @return int
- */
- public function count(array $types): int
- {
- return $this->user->accounts()->accountTypeIn($types)->count();
- }
-
/**
* Moved here from account CRUD.
*
@@ -87,6 +76,17 @@ class AccountRepository implements AccountRepositoryInterface
return true;
}
+
+ /**
+ * @param array $types
+ *
+ * @return int
+ */
+ public function count(array $types): int
+ {
+ return $this->user->accounts()->accountTypeIn($types)->count();
+ }
+
/**
* @param string $number
* @param array $types
@@ -97,7 +97,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts()
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
- ->where('account_meta.name', 'accountNumber')
+ ->where('account_meta.name', 'account_number')
->where('account_meta.data', json_encode($number));
if (count($types) > 0) {
@@ -298,30 +298,6 @@ class AccountRepository implements AccountRepositoryInterface
return $factory->findOrCreate('Cash account', $type->type);
}
- /**
- * @param $account
- *
- * @return string
- */
- public function getInterestPerDay(Account $account): string
- {
- $interest = $this->getMetaValue($account, 'interest');
- $interestPeriod = $this->getMetaValue($account, 'interest_period');
- Log::debug(sprintf('Start with interest of %s percent', $interest));
-
- // calculate
- if ('monthly' === $interestPeriod) {
- $interest = bcdiv(bcmul($interest, '12'), '365'); // per year
- Log::debug(sprintf('Interest is now (monthly to daily) %s percent', $interest));
- }
- if ('yearly' === $interestPeriod) {
- $interest = bcdiv($interest, '365'); // per year
- Log::debug(sprintf('Interest is now (yearly to daily) %s percent', $interest));
- }
-
- return $interest;
- }
-
/**
* Return meta value for account. Null if not found.
*
@@ -444,18 +420,6 @@ class AccountRepository implements AccountRepositoryInterface
return $account;
}
- /**
- * @param Account $account
- *
- * @return bool
- */
- public function isAsset(Account $account): bool
- {
- $type = $account->accountType->type;
-
- return AccountType::ASSET === $type || AccountType::DEFAULT === $type;
- }
-
/**
* @param Account $account
*
@@ -466,47 +430,6 @@ class AccountRepository implements AccountRepositoryInterface
return in_array($account->accountType->type, [AccountType::CREDITCARD, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true);
}
- /**
- * Returns the date of the very last transaction in this account.
- *
- * @param Account $account
- *
- * @return TransactionJournal|null
- */
- public function latestJournal(Account $account): ?TransactionJournal
- {
- $first = $account->transactions()
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->orderBy('transaction_journals.date', 'DESC')
- ->orderBy('transaction_journals.order', 'ASC')
- ->where('transaction_journals.user_id', $this->user->id)
- ->orderBy('transaction_journals.id', 'DESC')
- ->first(['transaction_journals.id']);
- if (null !== $first) {
- return TransactionJournal::find((int)$first->id);
- }
-
- return null;
- }
-
- /**
- * Returns the date of the very last transaction in this account.
- *
- * @param Account $account
- *
- * @return Carbon|null
- */
- public function latestJournalDate(Account $account): ?Carbon
- {
- $result = null;
- $journal = $this->latestJournal($account);
- if (null !== $journal) {
- $result = $journal->date;
- }
-
- return $result;
- }
-
/**
* Returns the date of the very first transaction in this account.
*
@@ -581,7 +504,7 @@ class AccountRepository implements AccountRepositoryInterface
* @param array $data
*
* @return Account
- * @throws \FireflyIII\Exceptions\FireflyException
+ * @throws FireflyException
*/
public function store(array $data): Account
{
@@ -597,7 +520,7 @@ class AccountRepository implements AccountRepositoryInterface
* @param array $data
*
* @return Account
- * @throws \FireflyIII\Exceptions\FireflyException
+ * @throws FireflyException
* @throws FireflyException
* @throws FireflyException
*/
diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php
index b45aefbc9a..d9ceecb2e1 100644
--- a/app/Repositories/Account/AccountRepositoryInterface.php
+++ b/app/Repositories/Account/AccountRepositoryInterface.php
@@ -40,7 +40,9 @@ interface AccountRepositoryInterface
/**
* @param Account $account
+ *
* @return TransactionJournal|null
+ *
*/
public function getOpeningBalance(Account $account): ?TransactionJournal;
@@ -151,13 +153,6 @@ interface AccountRepositoryInterface
*/
public function getCashAccount(): Account;
- /**
- * @param $account
- *
- * @return string
- */
- public function getInterestPerDay(Account $account): string;
-
/**
* Return meta value for account. Null if not found.
*
@@ -211,12 +206,6 @@ interface AccountRepositoryInterface
*/
public function getReconciliation(Account $account): ?Account;
- /**
- * @param Account $account
- *
- * @return bool
- */
- public function isAsset(Account $account): bool;
/**
* @param Account $account
@@ -225,23 +214,6 @@ interface AccountRepositoryInterface
*/
public function isLiability(Account $account): bool;
- /**
- * Returns the date of the very first transaction in this account.
- *
- * @param Account $account
- *
- * @return TransactionJournal|null
- */
- public function latestJournal(Account $account): ?TransactionJournal;
-
- /**
- * Returns the date of the very last transaction in this account.
- *
- * @param Account $account
- *
- * @return Carbon|null
- */
- public function latestJournalDate(Account $account): ?Carbon;
/**
* Returns the date of the very first transaction in this account.
diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php
index c2d1fa45e2..f4ee5c1086 100644
--- a/app/Repositories/Account/AccountTasker.php
+++ b/app/Repositories/Account/AccountTasker.php
@@ -151,6 +151,47 @@ class AccountTasker implements AccountTaskerInterface
return $expenses;
}
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection $accounts
+ *
+ * @return array
+ */
+ public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
+ {
+ // get all expenses for the given accounts in the given period!
+ // also transfers!
+ // get all transactions:
+
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+
+ $collector->setAccounts($accounts)->setRange($start, $end);
+ $collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
+ ->withAccountInformation();
+ $income = $this->groupByDestination($collector->getExtractedJournals());
+
+ // sort the result
+ // Obtain a list of columns
+ $sum = [];
+ foreach ($income as $accountId => $row) {
+ $sum[$accountId] = (float)$row['sum'];
+ }
+
+ array_multisort($sum, SORT_DESC, $income);
+
+ return $income;
+ }
+
+ /**
+ * @param User $user
+ */
+ public function setUser(User $user): void
+ {
+ $this->user = $user;
+ }
+
/**
* @param array $array
*
@@ -208,45 +249,4 @@ class AccountTasker implements AccountTaskerInterface
return $expenses;
}
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- * @param Collection $accounts
- *
- * @return array
- */
- public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
- {
- // get all expenses for the given accounts in the given period!
- // also transfers!
- // get all transactions:
-
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
-
- $collector->setAccounts($accounts)->setRange($start, $end);
- $collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
- ->withAccountInformation();
- $income = $this->groupByDestination($collector->getExtractedJournals());
-
- // sort the result
- // Obtain a list of columns
- $sum = [];
- foreach ($income as $accountId => $row) {
- $sum[$accountId] = (float)$row['sum'];
- }
-
- array_multisort($sum, SORT_DESC, $income);
-
- return $income;
- }
-
- /**
- * @param User $user
- */
- public function setUser(User $user): void
- {
- $this->user = $user;
- }
}
diff --git a/app/Repositories/Account/AccountTaskerInterface.php b/app/Repositories/Account/AccountTaskerInterface.php
index 3c8e27a810..7364170bb8 100644
--- a/app/Repositories/Account/AccountTaskerInterface.php
+++ b/app/Repositories/Account/AccountTaskerInterface.php
@@ -33,16 +33,16 @@ interface AccountTaskerInterface
{
/**
* @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
+ * @param Carbon $start
+ * @param Carbon $end
*
* @return array
*/
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array;
/**
- * @param Carbon $start
- * @param Carbon $end
+ * @param Carbon $start
+ * @param Carbon $end
* @param Collection $accounts
*
* @return array
@@ -50,8 +50,8 @@ interface AccountTaskerInterface
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): array;
/**
- * @param Carbon $start
- * @param Carbon $end
+ * @param Carbon $start
+ * @param Carbon $end
* @param Collection $accounts
*
* @return array
diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php
index 2c3e1aee3f..7976c8c0fa 100644
--- a/app/Repositories/Attachment/AttachmentRepository.php
+++ b/app/Repositories/Attachment/AttachmentRepository.php
@@ -90,17 +90,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
return $disk->exists($attachment->fileName());
}
- /**
- * @param int $attachmentId
- *
- * @return Attachment|null
- */
- public function findWithoutUser(int $attachmentId): ?Attachment
- {
-
- return Attachment::find($attachmentId);
- }
-
/**
* @return Collection
*/
@@ -109,24 +98,6 @@ class AttachmentRepository implements AttachmentRepositoryInterface
return $this->user->attachments()->get();
}
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function getBetween(Carbon $start, Carbon $end): Collection
- {
- $query = $this->user
- ->attachments()
- ->leftJoin('transaction_journals', 'attachments.attachable_id', '=', 'transaction_journals.id')
- ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
- ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
- ->get(['attachments.*']);
-
- return $query;
- }
-
/**
* @param Attachment $attachment
*
diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.php
index b59378c58d..653640a4f0 100644
--- a/app/Repositories/Attachment/AttachmentRepositoryInterface.php
+++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php
@@ -48,26 +48,11 @@ interface AttachmentRepositoryInterface
*/
public function exists(Attachment $attachment): bool;
- /**
- * @param int $attachmentId
- *
- * @return Attachment|null
- */
- public function findWithoutUser(int $attachmentId): ?Attachment;
-
/**
* @return Collection
*/
public function get(): Collection;
- /**
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return Collection
- */
- public function getBetween(Carbon $start, Carbon $end): Collection;
-
/**
* @param Attachment $attachment
*
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index 03e51e17b5..f67ff8ba25 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -489,36 +489,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return $return;
}
- /**
- * Calculate the average amount in the budgets available in this period.
- * Grouped by day.
- *
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function getAverageAvailable(Carbon $start, Carbon $end): string
- {
- /** @var Collection $list */
- $list = $this->user->availableBudgets()
- ->where('start_date', '>=', $start->format('Y-m-d 00:00:00'))
- ->where('end_date', '<=', $end->format('Y-m-d 00:00:00'))
- ->get();
- if (0 === $list->count()) {
- return '0';
- }
- $total = '0';
- $days = 0;
- /** @var AvailableBudget $availableBudget */
- foreach ($list as $availableBudget) {
- $total = bcadd($availableBudget->amount, $total);
- $days += $availableBudget->start_date->diffInDays($availableBudget->end_date);
- }
-
- return bcdiv($total, (string)$days);
- }
-
/**
* This method is being used to generate the budget overview in the year/multi-year report. Its used
* in both the year/multi-year budget overview AND in the accompanying chart.
diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php
index b70e853116..0a59706dd8 100644
--- a/app/Repositories/Budget/BudgetRepositoryInterface.php
+++ b/app/Repositories/Budget/BudgetRepositoryInterface.php
@@ -172,17 +172,6 @@ interface BudgetRepositoryInterface
*/
public function getAvailableBudgetsByCurrency(TransactionCurrency $currency): Collection;
- /**
- * Calculate the average amount in the budgets available in this period.
- * Grouped by day.
- *
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return string
- */
- public function getAverageAvailable(Carbon $start, Carbon $end): string;
-
/**
* @param Budget $budget
* @param Carbon $start
diff --git a/app/Rules/BelongsUser.php b/app/Rules/BelongsUser.php
index 5da19bdec9..a8d085e115 100644
--- a/app/Rules/BelongsUser.php
+++ b/app/Rules/BelongsUser.php
@@ -41,6 +41,7 @@ class BelongsUser implements Rule
* Create a new rule instance.
*
* @return void
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -51,6 +52,7 @@ class BelongsUser implements Rule
* Get the validation error message.
*
* @return string
+ * @codeCoverageIgnore
*/
public function message(): string
{
diff --git a/app/Rules/IsAssetAccountId.php b/app/Rules/IsAssetAccountId.php
index 9a59f823ee..84c6b72bec 100644
--- a/app/Rules/IsAssetAccountId.php
+++ b/app/Rules/IsAssetAccountId.php
@@ -36,6 +36,7 @@ class IsAssetAccountId implements Rule
* Get the validation error message. This is not translated because only the API uses it.
*
* @return string
+ * @codeCoverageIgnore
*/
public function message(): string
{
diff --git a/app/Rules/IsBoolean.php b/app/Rules/IsBoolean.php
index b23314e657..c40e8ce1f8 100644
--- a/app/Rules/IsBoolean.php
+++ b/app/Rules/IsBoolean.php
@@ -33,7 +33,7 @@ class IsBoolean implements Rule
{
/**
* Get the validation error message.
- *
+ * @codeCoverageIgnore
* @return string
*/
public function message(): string
@@ -51,25 +51,16 @@ class IsBoolean implements Rule
*/
public function passes($attribute, $value): bool
{
- if (\is_bool($value)) {
+ if (is_bool($value)) {
return true;
}
- if (\is_int($value) && 0 === $value) {
+ if (is_int($value) && 0 === $value) {
return true;
}
- if (\is_int($value) && 1 === $value) {
+ if (is_int($value) && 1 === $value) {
return true;
}
- if (\is_string($value) && '1' === $value) {
- return true;
- }
- if (\is_string($value) && '0' === $value) {
- return true;
- }
- if (\is_string($value) && 'true' === $value) {
- return true;
- }
- if (\is_string($value) && 'false' === $value) {
+ if (is_string($value) && in_array($value, ['0', '1', 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n'])) {
return true;
}
diff --git a/app/Rules/IsDateOrTime.php b/app/Rules/IsDateOrTime.php
index be3d3b7f45..f942e8206b 100644
--- a/app/Rules/IsDateOrTime.php
+++ b/app/Rules/IsDateOrTime.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Rules;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
+use Exception;
use Illuminate\Contracts\Validation\Rule;
use Log;
@@ -39,6 +40,7 @@ class IsDateOrTime implements Rule
* Get the validation error message.
*
* @return string|array
+ * @codeCoverageIgnore
*/
public function message()
{
@@ -56,11 +58,14 @@ class IsDateOrTime implements Rule
public function passes($attribute, $value): bool
{
$value = (string)$value;
+ if ('' === $value) {
+ return false;
+ }
if (10 === strlen($value)) {
// probably a date format.
try {
Carbon::createFromFormat('Y-m-d', $value);
- } catch (InvalidDateException $e) {
+ } catch (InvalidDateException|Exception $e) {
Log::error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));
return false;
@@ -71,7 +76,7 @@ class IsDateOrTime implements Rule
// is an atom string, I hope?
try {
Carbon::parse($value);
- } catch (InvalidDateException $e) {
+ } catch (InvalidDateException|Exception $e) {
Log::error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));
return false;
diff --git a/app/Rules/IsValidAttachmentModel.php b/app/Rules/IsValidAttachmentModel.php
index 6034a8c34c..5cfec6935e 100644
--- a/app/Rules/IsValidAttachmentModel.php
+++ b/app/Rules/IsValidAttachmentModel.php
@@ -46,16 +46,19 @@ class IsValidAttachmentModel implements Rule
/**
* IsValidAttachmentModel constructor.
*
+ * @codeCoverageIgnore
+ *
* @param string $model
*/
public function __construct(string $model)
{
+ $model = $this->normalizeModel($model);
$this->model = $model;
}
/**
* Get the validation error message.
- *
+ * @codeCoverageIgnore
* @return string
*/
public function message(): string
@@ -78,9 +81,9 @@ class IsValidAttachmentModel implements Rule
if (!auth()->check()) {
return false;
}
- $model = false === strpos('FireflyIII', $this->model) ? 'FireflyIII\\Models\\' . $this->model : $this->model;
- if (Bill::class === $model) {
+
+ if (Bill::class === $this->model) {
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
/** @var User $user */
@@ -91,7 +94,7 @@ class IsValidAttachmentModel implements Rule
return null !== $bill;
}
- if (ImportJob::class === $model) {
+ if (ImportJob::class === $this->model) {
/** @var ImportJobRepositoryInterface $repository */
$repository = app(ImportJobRepositoryInterface::class);
/** @var User $user */
@@ -102,7 +105,7 @@ class IsValidAttachmentModel implements Rule
return null !== $importJob;
}
- if (Transaction::class === $model) {
+ if (Transaction::class === $this->model) {
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var User $user */
@@ -113,7 +116,7 @@ class IsValidAttachmentModel implements Rule
return null !== $transaction;
}
- if (TransactionJournal::class === $model) {
+ if (TransactionJournal::class === $this->model) {
$repository = app(JournalRepositoryInterface::class);
$user = auth()->user();
$repository->setUser($user);
@@ -121,8 +124,23 @@ class IsValidAttachmentModel implements Rule
return null !== $result;
}
- Log::error(sprintf('No model was recognized from string "%s"', $model));
+ Log::error(sprintf('No model was recognized from string "%s"', $this->model));
return false;
}
+
+ /**
+ * @param string $model
+ *
+ * @return string
+ */
+ private function normalizeModel(string $model): string
+ {
+ $search = ['FireflyIII\Models\\'];
+ $replace = '';
+ $model = str_replace($search, $replace, $model);
+
+ $model = sprintf('FireflyIII\Models\%s', $model);
+ return $model;
+ }
}
diff --git a/app/Rules/UniqueIban.php b/app/Rules/UniqueIban.php
index 28922f3cf2..c3d18d4da2 100644
--- a/app/Rules/UniqueIban.php
+++ b/app/Rules/UniqueIban.php
@@ -26,7 +26,6 @@ namespace FireflyIII\Rules;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use Illuminate\Contracts\Validation\Rule;
-use Illuminate\Support\Collection;
use Log;
/**
@@ -43,6 +42,8 @@ class UniqueIban implements Rule
/**
* Create a new rule instance.
*
+ * @codeCoverageIgnore
+ *
* @param Account|null $account
* @param string|null $expectedType
*/
@@ -55,6 +56,8 @@ class UniqueIban implements Rule
/**
* Get the validation error message.
*
+ * @codeCoverageIgnore
+ *
* @return string
*/
public function message(): string
@@ -78,13 +81,13 @@ class UniqueIban implements Rule
return true; // @codeCoverageIgnore
}
if (null === $this->expectedType) {
- return true;
+ return true; // @codeCoverageIgnore
}
$maxCounts = $this->getMaxOccurrences();
foreach ($maxCounts as $type => $max) {
$count = $this->countHits($type, $value);
-
+ Log::debug(sprintf('Count for "%s" and IBAN "%s" is %d', $type, $value, $count));
if ($count > $max) {
Log::debug(
sprintf(
@@ -108,24 +111,18 @@ class UniqueIban implements Rule
*/
private function countHits(string $type, string $iban): int
{
- $count = 0;
- /** @noinspection NullPointerExceptionInspection */
- $query = auth()->user()
- ->accounts()
- ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
- ->where('account_types.type', $type);
+ $query
+ = auth()->user()
+ ->accounts()
+ ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
+ ->where('accounts.iban', $iban)
+ ->where('account_types.type', $type);
+
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);
}
- /** @var Collection $result */
- $result = $query->get(['accounts.*']);
- foreach ($result as $account) {
- if ($account->iban === $iban) {
- $count++;
- }
- }
- return $count;
+ return $query->count();
}
/**
diff --git a/app/Rules/ValidJournals.php b/app/Rules/ValidJournals.php
index 41f47d060a..a9b449b9f1 100644
--- a/app/Rules/ValidJournals.php
+++ b/app/Rules/ValidJournals.php
@@ -31,6 +31,7 @@ use Log;
/**
* Class ValidJournals
+ * @codeCoverageIgnore
*/
class ValidJournals implements Rule
{
diff --git a/app/Rules/ValidRecurrenceRepetitionType.php b/app/Rules/ValidRecurrenceRepetitionType.php
index 6be6e5183d..c984e6b0ee 100644
--- a/app/Rules/ValidRecurrenceRepetitionType.php
+++ b/app/Rules/ValidRecurrenceRepetitionType.php
@@ -27,6 +27,7 @@ use Illuminate\Contracts\Validation\Rule;
/**
* Class ValidRecurrenceRepetitionType
+ * @codeCoverageIgnore
*/
class ValidRecurrenceRepetitionType implements Rule
{
diff --git a/app/Rules/ValidRecurrenceRepetitionValue.php b/app/Rules/ValidRecurrenceRepetitionValue.php
index 59db275abc..620e317e7f 100644
--- a/app/Rules/ValidRecurrenceRepetitionValue.php
+++ b/app/Rules/ValidRecurrenceRepetitionValue.php
@@ -31,6 +31,7 @@ use Log;
/**
* Class ValidRecurrenceRepetitionValue
+ * @codeCoverageIgnore
*/
class ValidRecurrenceRepetitionValue implements Rule
{
diff --git a/app/Rules/ValidTransactions.php b/app/Rules/ValidTransactions.php
deleted file mode 100644
index 048c16d656..0000000000
--- a/app/Rules/ValidTransactions.php
+++ /dev/null
@@ -1,87 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-
-namespace FireflyIII\Rules;
-
-use FireflyIII\Models\Transaction;
-use Illuminate\Contracts\Validation\Rule;
-use Log;
-
-/**
- * Class ValidTransactions
- */
-class ValidTransactions implements Rule
-{
- /**
- * Create a new rule instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * Get the validation error message.
- *
- * @return string
- */
- public function message(): string
- {
- return (string)trans('validation.invalid_selection');
- }
-
- /**
- * Determine if the validation rule passes.
- *
- * @param string $attribute
- * @param mixed $value
- *
- * @return bool
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function passes($attribute, $value): bool
- {
- Log::debug('In ValidTransactions::passes');
- if (!is_array($value)) {
- return true;
- }
- $userId = auth()->user()->id;
- foreach ($value as $transactionId) {
- $count = Transaction::where('transactions.id', $transactionId)
- ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
- ->where('accounts.user_id', $userId)->count();
- if (0 === $count) {
- Log::debug(sprintf('Count for transaction #%d and user #%d is zero! Return FALSE', $transactionId, $userId));
-
- return false;
- }
- }
- Log::debug('Return true!');
-
- return true;
- }
-}
diff --git a/app/Rules/ZeroOrMore.php b/app/Rules/ZeroOrMore.php
index 642a89cf36..444f5fb195 100644
--- a/app/Rules/ZeroOrMore.php
+++ b/app/Rules/ZeroOrMore.php
@@ -29,6 +29,7 @@ use Illuminate\Contracts\Validation\Rule;
/**
*
* Class ZeroOrMore
+ * @codeCoverageIgnore
*/
class ZeroOrMore implements Rule
{
diff --git a/app/Services/Bunq/ApiContext.php b/app/Services/Bunq/ApiContext.php
index 4e68bef43f..b6bff72041 100644
--- a/app/Services/Bunq/ApiContext.php
+++ b/app/Services/Bunq/ApiContext.php
@@ -35,6 +35,7 @@ use Tests\Object\FakeApiContext;
* Special class to hide away bunq's static initialisation methods.
*
* Class ApiContext
+ * @codeCoverageIgnore
*/
class ApiContext
{
diff --git a/app/Services/Bunq/MonetaryAccount.php b/app/Services/Bunq/MonetaryAccount.php
index be13f57759..9163e70039 100644
--- a/app/Services/Bunq/MonetaryAccount.php
+++ b/app/Services/Bunq/MonetaryAccount.php
@@ -31,6 +31,7 @@ use FireflyIII\Exceptions\FireflyException;
/**
* Class MonetaryAccount
+ * @codeCoverageIgnore
*/
class MonetaryAccount
{
diff --git a/app/Services/Bunq/Payment.php b/app/Services/Bunq/Payment.php
index 3ce3447b66..b01d57fbd1 100644
--- a/app/Services/Bunq/Payment.php
+++ b/app/Services/Bunq/Payment.php
@@ -31,6 +31,7 @@ use FireflyIII\Exceptions\FireflyException;
/**
* Class Payment
+ * @codeCoverageIgnore
*/
class Payment
{
diff --git a/app/Services/Currency/FixerIOv2.php b/app/Services/Currency/FixerIOv2.php
index 6c6245db9f..6ad748efd9 100644
--- a/app/Services/Currency/FixerIOv2.php
+++ b/app/Services/Currency/FixerIOv2.php
@@ -55,6 +55,7 @@ class FixerIOv2 implements ExchangeRateInterface
* @param Carbon $date
*
* @return CurrencyExchangeRate
+ * @throws Exception
*/
public function getRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): CurrencyExchangeRate
{
diff --git a/app/Services/Currency/RatesApiIOv1.php b/app/Services/Currency/RatesApiIOv1.php
index b6437e0610..369b6b1651 100644
--- a/app/Services/Currency/RatesApiIOv1.php
+++ b/app/Services/Currency/RatesApiIOv1.php
@@ -33,6 +33,7 @@ use Log;
/**
* Class RatesApiIOv1.
+ * @codeCoverageIgnore
*/
class RatesApiIOv1 implements ExchangeRateInterface
{
diff --git a/app/Services/Github/Request/UpdateRequest.php b/app/Services/Github/Request/UpdateRequest.php
index 5a390475e8..6a5fae2116 100644
--- a/app/Services/Github/Request/UpdateRequest.php
+++ b/app/Services/Github/Request/UpdateRequest.php
@@ -34,6 +34,7 @@ use SimpleXMLElement;
/**
* Class UpdateRequest
+ * @codeCoverageIgnore
*/
class UpdateRequest implements GithubRequest
{
diff --git a/app/Services/IP/IpifyOrg.php b/app/Services/IP/IpifyOrg.php
index 9394de8202..80851c9e5e 100644
--- a/app/Services/IP/IpifyOrg.php
+++ b/app/Services/IP/IpifyOrg.php
@@ -31,6 +31,7 @@ use RuntimeException;
/**
* Class IpifyOrg
+ * @codeCoverageIgnore
*/
class IpifyOrg implements IPRetrievalInterface
{
diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php
index 6714e22d63..00a2609257 100644
--- a/app/Services/Internal/Destroy/AccountDestroyService.php
+++ b/app/Services/Internal/Destroy/AccountDestroyService.php
@@ -40,6 +40,8 @@ class AccountDestroyService
{
/**
* Constructor.
+ *
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -53,18 +55,38 @@ class AccountDestroyService
* @param Account|null $moveTo
*
* @return void
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function destroy(Account $account, ?Account $moveTo): void
{
-
if (null !== $moveTo) {
- DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
-
- // also update recurring transactions:
- DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id' => $moveTo->id]);
- DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id' => $moveTo->id]);
+ $this->moveTransactions($account, $moveTo);
+ $this->updateRecurrences($account, $moveTo);
}
+ $this->destroyJournals($account);
+
+ // delete recurring transactions with this account:
+ if (null === $moveTo) {
+ $this->destroyRecurrences($account);
+ }
+
+ // delete piggy banks:
+ PiggyBank::where('account_id', $account->id)->delete();
+
+ // delete account.
+ try {
+ $account->delete();
+ } catch (Exception $e) { // @codeCoverageIgnore
+ Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore
+ }
+ }
+
+ /**
+ * @param Account $account
+ */
+ private function destroyJournals(Account $account): void
+ {
+
+ /** @var JournalDestroyService $service */
$service = app(JournalDestroyService::class);
Log::debug('Now trigger account delete response #' . $account->id);
@@ -75,37 +97,49 @@ class AccountDestroyService
$journal = $transaction->transactionJournal()->first();
if (null !== $journal) {
Log::debug('Call for deletion of journal #' . $journal->id);
- /** @var JournalDestroyService $service */
-
$service->destroy($journal);
}
}
+ }
- // delete recurring transactions with this account:
- if (null === $moveTo) {
- $recurrences = RecurrenceTransaction::
- where(
- function (Builder $q) use ($account) {
- $q->where('source_id', $account->id);
- $q->orWhere('destination_id', $account->id);
- }
- )->get(['recurrence_id'])->pluck('recurrence_id')->toArray();
-
-
- $destroyService = new RecurrenceDestroyService();
- foreach ($recurrences as $recurrenceId) {
- $destroyService->destroyById((int)$recurrenceId);
+ /**
+ * @param Account $account
+ */
+ private function destroyRecurrences(Account $account): void
+ {
+ $recurrences = RecurrenceTransaction::
+ where(
+ static function (Builder $q) use ($account) {
+ $q->where('source_id', $account->id);
+ $q->orWhere('destination_id', $account->id);
}
- }
+ )->get(['recurrence_id'])->pluck('recurrence_id')->toArray();
- // delete piggy banks:
- PiggyBank::where('account_id', $account->id)->delete();
-
- try {
- $account->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore
+ /** @var RecurrenceDestroyService $destroyService */
+ $destroyService = app(RecurrenceDestroyService::class);
+ foreach ($recurrences as $recurrenceId) {
+ $destroyService->destroyById((int)$recurrenceId);
}
}
+
+ /**
+ * @param Account $account
+ * @param Account $moveTo
+ */
+ private function moveTransactions(Account $account, Account $moveTo): void
+ {
+ DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
+ }
+
+ /**
+ * @param Account $account
+ * @param Account $moveTo
+ */
+ private function updateRecurrences(Account $account, Account $moveTo): void
+ {
+ DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id' => $moveTo->id]);
+ DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id' => $moveTo->id]);
+ }
+
}
diff --git a/app/Services/Internal/Destroy/BudgetDestroyService.php b/app/Services/Internal/Destroy/BudgetDestroyService.php
index e6cbe1d263..0f7d9eb828 100644
--- a/app/Services/Internal/Destroy/BudgetDestroyService.php
+++ b/app/Services/Internal/Destroy/BudgetDestroyService.php
@@ -30,6 +30,7 @@ use Log;
/**
* Class BudgetDestroyService
+ * @codeCoverageIgnore
*/
class BudgetDestroyService
{
diff --git a/app/Services/Internal/Destroy/CategoryDestroyService.php b/app/Services/Internal/Destroy/CategoryDestroyService.php
index 3d23360730..936a1dff78 100644
--- a/app/Services/Internal/Destroy/CategoryDestroyService.php
+++ b/app/Services/Internal/Destroy/CategoryDestroyService.php
@@ -30,6 +30,7 @@ use Log;
/**
* Class CategoryDestroyService
+ * @codeCoverageIgnore
*/
class CategoryDestroyService
{
diff --git a/app/Services/Internal/Destroy/CurrencyDestroyService.php b/app/Services/Internal/Destroy/CurrencyDestroyService.php
index f67cf9d3d8..8a6eb317b9 100644
--- a/app/Services/Internal/Destroy/CurrencyDestroyService.php
+++ b/app/Services/Internal/Destroy/CurrencyDestroyService.php
@@ -29,6 +29,7 @@ use Log;
/**
* Class CurrencyDestroyService
+ * @codeCoverageIgnore
*/
class CurrencyDestroyService
{
diff --git a/app/Services/Internal/Destroy/JournalDestroyService.php b/app/Services/Internal/Destroy/JournalDestroyService.php
index 28ebfe5fcf..7d70c6b540 100644
--- a/app/Services/Internal/Destroy/JournalDestroyService.php
+++ b/app/Services/Internal/Destroy/JournalDestroyService.php
@@ -23,9 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
+use DB;
use Exception;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Models\TransactionJournalMeta;
use Log;
@@ -58,12 +61,42 @@ class JournalDestroyService
}
// also delete journal_meta entries.
-
/** @var TransactionJournalMeta $meta */
foreach ($journal->transactionJournalMeta()->get() as $meta) {
Log::debug(sprintf('Will now delete meta-entry #%d', $meta->id));
$meta->delete();
}
+
+ // also delete attachments.
+ /** @var Attachment $attachment */
+ foreach ($journal->attachments()->get() as $attachment) {
+ $attachment->delete();
+ }
+
+ // delete all from 'budget_transaction_journal'
+ DB::table('budget_transaction_journal')
+ ->where('transaction_journal_id', $journal->id)->delete();
+
+ // delete all from 'category_transaction_journal'
+ DB::table('category_transaction_journal')
+ ->where('transaction_journal_id', $journal->id)->delete();
+
+ // delete all from 'tag_transaction_journal'
+ DB::table('tag_transaction_journal')
+ ->where('transaction_journal_id', $journal->id)->delete();
+
+ // delete all links:
+ TransactionJournalLink::where('source_id', $journal->id)->delete();
+ TransactionJournalLink::where('destination_id', $journal->id)->delete();
+
+ // delete all notes
+ $journal->notes()->delete();
+
+ // update events
+ $journal->piggyBankEvents()->update(['transaction_journal_id' => null]);
+
+
+
$journal->delete();
} catch (Exception $e) {
Log::error(sprintf('Could not delete bill: %s', $e->getMessage())); // @codeCoverageIgnore
diff --git a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
index 3b732c2071..e45ef99259 100644
--- a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
+++ b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
@@ -28,6 +28,7 @@ use FireflyIII\Models\TransactionGroup;
/**
* Class TransactionGroupDestroyService
+ * @codeCoverageIgnore
*/
class TransactionGroupDestroyService
{
diff --git a/app/Services/Internal/File/EncryptService.php b/app/Services/Internal/File/EncryptService.php
deleted file mode 100644
index 7bc8481560..0000000000
--- a/app/Services/Internal/File/EncryptService.php
+++ /dev/null
@@ -1,71 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Services\Internal\File;
-
-use Crypt;
-use FireflyIII\Exceptions\FireflyException;
-use Illuminate\Contracts\Encryption\EncryptException;
-use Illuminate\Support\Facades\Storage;
-use Log;
-
-/**
- * Class EncryptService
- */
-class EncryptService
-{
- /**
- * Constructor.
- */
- public function __construct()
- {
- if ('testing' === config('app.env')) {
- Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
- }
- }
-
- /**
- * @param string $file
- * @param string $key
- *
- * @throws FireflyException
- */
- public function encrypt(string $file, string $key): void
- {
- if (!file_exists($file)) {
- throw new FireflyException(sprintf('File "%s" does not seem to exist.', $file));
- }
- $content = file_get_contents($file);
- try {
- $content = Crypt::encrypt($content);
- } catch (EncryptException $e) {
- $message = sprintf('Could not encrypt file: %s', $e->getMessage());
- Log::error($message);
- throw new FireflyException($message);
- }
- $newName = sprintf('%s.upload', $key);
- $disk = Storage::disk('upload');
- $disk->put($newName, $content);
- }
-
-}
diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php
index 65b0c64338..2318b84f7e 100644
--- a/app/Services/Internal/Support/AccountServiceTrait.php
+++ b/app/Services/Internal/Support/AccountServiceTrait.php
@@ -105,60 +105,11 @@ trait AccountServiceTrait
}
}
-// /**
-// * @param User $user
-// * @param string $name
-// *
-// * @return Account
-// * @throws \FireflyIII\Exceptions\FireflyException
-// */
-// public function storeOpposingAccount(User $user, string $name): Account
-// {
-// $opposingAccountName = (string)trans('firefly.initial_balance_account', ['name' => $name]);
-// Log::debug('Going to create an opening balance opposing account.');
-// /** @var AccountFactory $factory */
-// $factory = app(AccountFactory::class);
-// $factory->setUser($user);
-//
-// return $factory->findOrCreate($opposingAccountName, AccountType::INITIAL_BALANCE);
-// }
-
-// /**
-// * @param Account $account
-// * @param array $data
-// *
-// * @return bool
-// * @throws \FireflyIII\Exceptions\FireflyException
-// */
-// public function updateOB(Account $account, array $data): bool
-// {
-// Log::debug(sprintf('updateIB() for account #%d', $account->id));
-//
-// $openingBalanceGroup = $this->getOBGroup($account);
-//
-// // no opening balance journal? create it:
-// if (null === $openingBalanceGroup) {
-// Log::debug('No opening balance journal yet, create group.');
-// $this->storeOBGroup($account, $data);
-//
-// return true;
-// }
-//
-// // opening balance data? update it!
-// if (null !== $openingBalanceGroup->id) {
-// Log::debug('Opening balance group found, update group.');
-// $this->updateOBGroup($account, $openingBalanceGroup, $data);
-//
-// return true;
-// }
-//
-// return true; // @codeCoverageIgnore
-// }
-
/**
* @param Account $account
* @param string $note
*
+ * @codeCoverageIgnore
* @return bool
*/
public function updateNote(Account $account, string $note): bool
@@ -186,117 +137,6 @@ trait AccountServiceTrait
return true;
}
-// /**
-// * Find existing opening balance.
-// *
-// * @param Account $account
-// *
-// * @return TransactionJournal|null
-// */
-// public function getIBJournal(Account $account): ?TransactionJournal
-// {
-// $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
-// ->where('transactions.account_id', $account->id)
-// ->transactionTypes([TransactionType::OPENING_BALANCE])
-// ->first(['transaction_journals.*']);
-// if (null === $journal) {
-// Log::debug('Could not find a opening balance journal, return NULL.');
-//
-// return null;
-// }
-// Log::debug(sprintf('Found opening balance: journal #%d.', $journal->id));
-//
-// return $journal;
-// }
-
-// /**
-// * @param Account $account
-// * @param array $data
-// *
-// * @return TransactionJournal|null
-// * @throws \FireflyIII\Exceptions\FireflyException
-// * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
-// */
-// public function storeIBJournal(Account $account, array $data): ?TransactionJournal
-// {
-// $amount = (string)$data['openingBalance'];
-// Log::debug(sprintf('Submitted amount is %s', $amount));
-//
-// if (0 === bccomp($amount, '0')) {
-// return null;
-// }
-//
-// // store journal, without transactions:
-// $name = $data['name'];
-// $currencyId = $data['currency_id'];
-// $journalData = [
-// 'type' => TransactionType::OPENING_BALANCE,
-// 'user' => $account->user->id,
-// 'transaction_currency_id' => $currencyId,
-// 'description' => (string)trans('firefly.initial_balance_description', ['account' => $account->name]),
-// 'completed' => true,
-// 'date' => $data['openingBalanceDate'],
-// 'bill_id' => null,
-// 'bill_name' => null,
-// 'piggy_bank_id' => null,
-// 'piggy_bank_name' => null,
-// 'tags' => null,
-// 'notes' => null,
-// 'transactions' => [],
-//
-// ];
-// /** @var TransactionJournalFactory $factory */
-// $factory = app(TransactionJournalFactory::class);
-// $factory->setUser($account->user);
-// $journal = $factory->create($journalData);
-// $opposing = $this->storeOpposingAccount($account->user, $name);
-// Log::notice(sprintf('Created new opening balance journal: #%d', $journal->id));
-//
-// $firstAccount = $account;
-// $secondAccount = $opposing;
-// $firstAmount = $amount;
-// $secondAmount = bcmul($amount, '-1');
-// Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));
-//
-// if (bccomp($amount, '0') === -1) {
-// Log::debug(sprintf('%s is a negative number.', $amount));
-// $firstAccount = $opposing;
-// $secondAccount = $account;
-// $firstAmount = bcmul($amount, '-1');
-// $secondAmount = $amount;
-// Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));
-// }
-// /** @var TransactionFactory $factory */
-// $factory = app(TransactionFactory::class);
-// $factory->setUser($account->user);
-// $factory->create(
-// [
-// 'account' => $firstAccount,
-// 'transaction_journal' => $journal,
-// 'amount' => $firstAmount,
-// 'currency_id' => $currencyId,
-// 'description' => null,
-// 'identifier' => 0,
-// 'foreign_amount' => null,
-// 'reconciled' => false,
-// ]
-// );
-// $factory->create(
-// [
-// 'account' => $secondAccount,
-// 'transaction_journal' => $journal,
-// 'amount' => $secondAmount,
-// 'currency_id' => $currencyId,
-// 'description' => null,
-// 'identifier' => 0,
-// 'foreign_amount' => null,
-// 'reconciled' => false,
-// ]
-// );
-//
-// return $journal;
-// }
-
/**
* Verify if array contains valid data to possibly store or update the opening balance.
*
@@ -340,52 +180,6 @@ trait AccountServiceTrait
return $currency;
}
-// /**
-// * @param Account $account
-// * @param TransactionJournal $journal
-// * @param array $data
-// *
-// * @return bool
-// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
-// */
-// protected function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
-// {
-// $date = $data['openingBalanceDate'];
-// $amount = (string)$data['openingBalance'];
-// $negativeAmount = bcmul($amount, '-1');
-// $currencyId = (int)$data['currency_id'];
-// Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount));
-// if (0 === bccomp($amount, '0')) {
-// Log::notice(sprintf('Amount "%s" is zero, delete opening balance.', $amount));
-// /** @var JournalDestroyService $service */
-// $service = app(JournalDestroyService::class);
-// $service->destroy($journal);
-//
-// return true;
-// }
-// $journal->date = $date;
-// $journal->transaction_currency_id = $currencyId;
-// $journal->save();
-// /** @var Transaction $transaction */
-// foreach ($journal->transactions()->get() as $transaction) {
-// if ((int)$account->id === (int)$transaction->account_id) {
-// Log::debug(sprintf('Will (eq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $amount));
-// $transaction->amount = $amount;
-// $transaction->transaction_currency_id = $currencyId;
-// $transaction->save();
-// }
-// if (!((int)$account->id === (int)$transaction->account_id)) {
-// Log::debug(sprintf('Will (neq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $negativeAmount));
-// $transaction->amount = $negativeAmount;
-// $transaction->transaction_currency_id = $currencyId;
-// $transaction->save();
-// }
-// }
-// Log::debug('Updated opening balance journal.');
-//
-// return true;
-// }
-
/**
* Delete TransactionGroup with opening balance in it.
*
@@ -486,7 +280,9 @@ trait AccountServiceTrait
*
* @param Account $account
* @param array $data
+ *
* @return TransactionGroup|null
+ * @codeCoverageIgnore
*/
protected function updateOBGroup(Account $account, array $data): ?TransactionGroup
{
diff --git a/app/Services/Internal/Support/BillServiceTrait.php b/app/Services/Internal/Support/BillServiceTrait.php
index b9ded1d789..eb1f9dc992 100644
--- a/app/Services/Internal/Support/BillServiceTrait.php
+++ b/app/Services/Internal/Support/BillServiceTrait.php
@@ -32,7 +32,7 @@ use Log;
/**
* Trait BillServiceTrait
- *
+ * @codeCoverageIgnore
*/
trait BillServiceTrait
{
diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php
index eedb149300..1335ddccfe 100644
--- a/app/Services/Internal/Support/JournalServiceTrait.php
+++ b/app/Services/Internal/Support/JournalServiceTrait.php
@@ -57,6 +57,7 @@ trait JournalServiceTrait
* @param string|null $amount
*
* @return string
+ * @codeCoverageIgnore
*/
protected function getForeignAmount(?string $amount): ?string
{
@@ -87,6 +88,7 @@ trait JournalServiceTrait
* @param string|null $accountName
*
* @return Account
+ * @codeCoverageIgnore
*/
protected function getAccount(string $transactionType, string $direction, ?int $accountId, ?string $accountName): Account
{
@@ -166,6 +168,7 @@ trait JournalServiceTrait
*
* @return string
* @throws FireflyException
+ * @codeCoverageIgnore
*/
protected function getAmount(string $amount): string
{
@@ -182,6 +185,8 @@ trait JournalServiceTrait
/**
* @param TransactionJournal $journal
* @param NullArrayObject $data
+ *
+ * @codeCoverageIgnore
*/
protected function storeBudget(TransactionJournal $journal, NullArrayObject $data): void
{
@@ -204,6 +209,8 @@ trait JournalServiceTrait
/**
* @param TransactionJournal $journal
* @param NullArrayObject $data
+ *
+ * @codeCoverageIgnore
*/
protected function storeCategory(TransactionJournal $journal, NullArrayObject $data): void
{
@@ -221,6 +228,8 @@ trait JournalServiceTrait
/**
* @param TransactionJournal $journal
* @param string $notes
+ *
+ * @codeCoverageIgnore
*/
protected function storeNotes(TransactionJournal $journal, ?string $notes): void
{
@@ -255,6 +264,8 @@ trait JournalServiceTrait
* @param TransactionJournal $journal
* @param array $tags
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ *
+ * @codeCoverageIgnore
*/
protected function storeTags(TransactionJournal $journal, ?array $tags): void
{
@@ -276,147 +287,4 @@ trait JournalServiceTrait
}
-
- //
- // /**
- // * Link tags to journal.
- // *
- // * @param TransactionJournal $journal
- // * @param array $data
- // * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- // */
- // public function connectTags(TransactionJournal $journal, array $data): void
- // {
- // /** @var TagFactory $factory */
- // $factory = app(TagFactory::class);
- // $factory->setUser($journal->user);
- // $set = [];
- // if (!is_array($data['tags'])) {
- // return; // @codeCoverageIgnore
- // }
- // foreach ($data['tags'] as $string) {
- // if ('' !== $string) {
- // $tag = $factory->findOrCreate($string);
- // if (null !== $tag) {
- // $set[] = $tag->id;
- // }
- // }
- // }
- // $journal->tags()->sync($set);
- // }
- //
- //
- // /**
- // * @param int|null $budgetId
- // * @param null|string $budgetName
- // *
- // * @return Budget|null
- // */
- // protected function findBudget(?int $budgetId, ?string $budgetName): ?Budget
- // {
- // /** @var BudgetFactory $factory */
- // $factory = app(BudgetFactory::class);
- // $factory->setUser($this->user);
- //
- // return $factory->find($budgetId, $budgetName);
- // }
- //
- // /**
- // * @param int|null $categoryId
- // * @param null|string $categoryName
- // *
- // * @return Category|null
- // */
- // protected function findCategory(?int $categoryId, ?string $categoryName): ?Category
- // {
- // Log::debug(sprintf('Going to find or create category #%d, with name "%s"', $categoryId, $categoryName));
- // /** @var CategoryFactory $factory */
- // $factory = app(CategoryFactory::class);
- // $factory->setUser($this->user);
- //
- // return $factory->findOrCreate($categoryId, $categoryName);
- // }
- //
- //
- // /**
- // * @param TransactionJournal $journal
- // * @param Budget|null $budget
- // */
- // protected function setBudget(TransactionJournal $journal, ?Budget $budget): void
- // {
- // if (null === $budget) {
- // $journal->budgets()->sync([]);
- //
- // return;
- // }
- // $journal->budgets()->sync([$budget->id]);
- //
- // }
- //
- //
- // /**
- // * @param TransactionJournal $journal
- // * @param Category|null $category
- // */
- // protected function setCategory(TransactionJournal $journal, ?Category $category): void
- // {
- // if (null === $category) {
- // $journal->categories()->sync([]);
- //
- // return;
- // }
- // $journal->categories()->sync([$category->id]);
- //
- // }
- //
- //
- // /**
- // * @param TransactionJournal $journal
- // * @param array $data
- // * @param string $field
- // */
- // protected function storeMeta(TransactionJournal $journal, array $data, string $field): void
- // {
- // $set = [
- // 'journal' => $journal,
- // 'name' => $field,
- // 'data' => (string)($data[$field] ?? ''),
- // ];
- //
- // Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data']));
- //
- // /** @var TransactionJournalMetaFactory $factory */
- // $factory = app(TransactionJournalMetaFactory::class);
- // $factory->updateOrCreate($set);
- // }
- //
- // /**
- // * @param TransactionJournal $journal
- // * @param string $notes
- // */
- // protected function storeNote(TransactionJournal $journal, ?string $notes): void
- // {
- // $notes = (string)$notes;
- // if ('' !== $notes) {
- // $note = $journal->notes()->first();
- // if (null === $note) {
- // $note = new Note;
- // $note->noteable()->associate($journal);
- // }
- // $note->text = $notes;
- // $note->save();
- //
- // return;
- // }
- // $note = $journal->notes()->first();
- // if (null !== $note) {
- // try {
- // $note->delete();
- // } catch (Exception $e) {
- // Log::debug(sprintf('Journal service trait could not delete note: %s', $e->getMessage()));
- // }
- // }
- //
- //
- // }
}
diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php
index 452f308213..a4225c4e51 100644
--- a/app/Services/Internal/Support/RecurringTransactionTrait.php
+++ b/app/Services/Internal/Support/RecurringTransactionTrait.php
@@ -205,6 +205,8 @@ trait RecurringTransactionTrait
/**
* @param Recurrence $recurrence
+ *
+ * @codeCoverageIgnore
*/
protected function deleteRepetitions(Recurrence $recurrence): void
{
@@ -213,6 +215,8 @@ trait RecurringTransactionTrait
/**
* @param Recurrence $recurrence
+ *
+ * @codeCoverageIgnore
*/
protected function deleteTransactions(Recurrence $recurrence): void
{
diff --git a/app/Services/Internal/Support/TransactionServiceTrait.php b/app/Services/Internal/Support/TransactionServiceTrait.php
deleted file mode 100644
index dd0e9a2e88..0000000000
--- a/app/Services/Internal/Support/TransactionServiceTrait.php
+++ /dev/null
@@ -1,171 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Services\Internal\Support;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Factory\TransactionCurrencyFactory;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use Log;
-
-/**
- * Trait TransactionServiceTrait
- *
- */
-trait TransactionServiceTrait
-{
-
-// /**
-// * @param TransactionJournal $journal
-// * @param string $direction
-// *
-// * @return string|null
-// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
-// */
-// public function accountType(TransactionJournal $journal, string $direction): ?string
-// {
-// $types = [];
-// $type = $journal->transactionType->type;
-// if (TransactionType::WITHDRAWAL === $type) {
-// $types['source'] = AccountType::ASSET;
-// $types['destination'] = AccountType::EXPENSE;
-// }
-// if (TransactionType::DEPOSIT === $type) {
-// $types['source'] = AccountType::REVENUE;
-// $types['destination'] = AccountType::ASSET;
-// }
-// if (TransactionType::TRANSFER === $type) {
-// $types['source'] = AccountType::ASSET;
-// $types['destination'] = AccountType::ASSET;
-// }
-// if (TransactionType::RECONCILIATION === $type) {
-// $types['source'] = null;
-// $types['destination'] = null;
-// }
-//
-// return $types[$direction] ?? null;
-// }
-
-// /**
-// * @param string|null $expectedType
-// * @param Account|null $account
-// * @param int|null $accountId
-// * @param string|null $accountName
-// *
-// * @return Account|null
-// * @throws FireflyException
-// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
-// */
-// public function findAccount(?string $expectedType, ?Account $account, ?int $accountId, ?string $accountName): ?Account
-// {
-// $result = null;
-//
-// if (null !== $account && $account->user_id === $this->user->id) {
-// return $account;
-// }
-//
-// $accountId = (int)$accountId;
-// $accountName = (string)$accountName;
-// $repository = app(AccountRepositoryInterface::class);
-// $repository->setUser($this->user);
-//
-// if (null === $expectedType) {
-// return $repository->findNull($accountId);
-// }
-//
-// if ($accountId > 0) {
-// // must be able to find it based on ID. Validator should catch invalid ID's.
-// return $repository->findNull($accountId);
-// }
-// if (AccountType::ASSET === $expectedType) {
-// return $repository->findByName($accountName, [AccountType::ASSET]);
-// }
-// // for revenue and expense:
-// if ('' !== $accountName) {
-// /** @var AccountFactory $factory */
-// $factory = app(AccountFactory::class);
-// $factory->setUser($this->user);
-//
-// return $factory->findOrCreate($accountName, $expectedType);
-// }
-//
-// return $repository->getCashAccount();
-// }
-
-// /**
-// * @param int|null $currencyId
-// * @param null|string $currencyCode
-// *
-// * @return TransactionCurrency|null
-// */
-// protected function findCurrency(?int $currencyId, ?string $currencyCode): ?TransactionCurrency
-// {
-// $factory = app(TransactionCurrencyFactory::class);
-//
-// return $factory->find($currencyId, $currencyCode);
-// }
-//
-// /**
-// * @param Transaction $transaction
-// * @param string|null $amount
-// */
-// protected function setForeignAmount(Transaction $transaction, ?string $amount): void
-// {
-// $amount = '' === (string)$amount ? null : $amount;
-// $transaction->foreign_amount = $amount;
-// $transaction->save();
-// }
-//
-// /**
-// * @param Transaction $transaction
-// * @param TransactionCurrency|null $currency
-// */
-// protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void
-// {
-// if (null === $currency) {
-// $transaction->foreign_currency_id = null;
-// $transaction->save();
-//
-// return;
-// }
-// // enable currency if not enabled:
-// if (false === $currency->enabled) {
-// $currency->enabled = true;
-// $currency->save();
-// }
-//
-// $transaction->foreign_currency_id = $currency->id;
-// $transaction->save();
-//
-// }
-
-
-}
diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php
index a593b1457d..812143b7fb 100644
--- a/app/Services/Internal/Update/AccountUpdateService.php
+++ b/app/Services/Internal/Update/AccountUpdateService.php
@@ -29,6 +29,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\AccountServiceTrait;
+use FireflyIII\User;
use Log;
/**
@@ -43,6 +44,8 @@ class AccountUpdateService
/** @var AccountRepositoryInterface */
protected $accountRepository;
+ /** @var User */
+ private $user;
/**
* Constructor.
*/
@@ -67,6 +70,7 @@ class AccountUpdateService
public function update(Account $account, array $data): Account
{
$this->accountRepository->setUser($account->user);
+ $this->user = $account->user;
// update the account itself:
$account->name = $data['name'];
@@ -91,10 +95,13 @@ class AccountUpdateService
// has valid initial balance (IB) data?
$type = $account->accountType;
// if it can have a virtual balance, it can also have an opening balance.
+
if (in_array($type->type, $this->canHaveVirtual, true)) {
+
if ($this->validOBData($data)) {
$this->updateOBGroup($account, $data);
}
+
if (!$this->validOBData($data)) {
$this->deleteOBGroup($account);
}
diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php
index b183434de9..b3c176e65b 100644
--- a/app/Services/Internal/Update/CategoryUpdateService.php
+++ b/app/Services/Internal/Update/CategoryUpdateService.php
@@ -28,6 +28,7 @@ use Log;
/**
* Class CategoryUpdateService
+ * @codeCoverageIgnore
*/
class CategoryUpdateService
{
diff --git a/app/Services/Internal/Update/CurrencyUpdateService.php b/app/Services/Internal/Update/CurrencyUpdateService.php
index e76409e66d..ef5fa2393e 100644
--- a/app/Services/Internal/Update/CurrencyUpdateService.php
+++ b/app/Services/Internal/Update/CurrencyUpdateService.php
@@ -28,6 +28,7 @@ use Log;
/**
* Class CurrencyUpdateService
+ * @codeCoverageIgnore
*/
class CurrencyUpdateService
{
diff --git a/app/Services/Internal/Update/GroupUpdateService.php b/app/Services/Internal/Update/GroupUpdateService.php
index e71ece0689..0bca2eb1de 100644
--- a/app/Services/Internal/Update/GroupUpdateService.php
+++ b/app/Services/Internal/Update/GroupUpdateService.php
@@ -31,6 +31,7 @@ use Log;
/**
* Class GroupUpdateService
+ * TODO test.
*/
class GroupUpdateService
{
diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php
index eb0d477ccc..13e6b570c3 100644
--- a/app/Services/Internal/Update/JournalUpdateService.php
+++ b/app/Services/Internal/Update/JournalUpdateService.php
@@ -48,6 +48,7 @@ use Log;
* Class to centralise code that updates a journal given the input by system.
*
* Class JournalUpdateService
+ * TODO test me
*/
class JournalUpdateService
{
diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php
index 6767b81e2f..ad8ca4a9a2 100644
--- a/app/Services/Internal/Update/RecurrenceUpdateService.php
+++ b/app/Services/Internal/Update/RecurrenceUpdateService.php
@@ -26,16 +26,16 @@ 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;
use FireflyIII\User;
/**
* Class RecurrenceUpdateService
+ * @codeCoverageIgnore
*/
class RecurrenceUpdateService
{
- use TransactionTypeTrait, TransactionServiceTrait, RecurringTransactionTrait;
+ use TransactionTypeTrait, RecurringTransactionTrait;
/** @var User */
private $user;
@@ -51,7 +51,6 @@ class RecurrenceUpdateService
*/
public function update(Recurrence $recurrence, array $data): Recurrence
{
- // is expected by TransactionServiceTrait
$this->user = $recurrence->user;
$transactionType = $this->findTransactionType(ucfirst($data['recurrence']['type']));
// update basic fields first:
diff --git a/app/Services/Internal/Update/TransactionUpdateService.php b/app/Services/Internal/Update/TransactionUpdateService.php
deleted file mode 100644
index 0caa542aca..0000000000
--- a/app/Services/Internal/Update/TransactionUpdateService.php
+++ /dev/null
@@ -1,179 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Services\Internal\Update;
-
-use FireflyIII\Models\Transaction;
-use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
-use FireflyIII\User;
-use Log;
-
-/**
- * Class TransactionUpdateService
- * TODO i think this is deprecated.
- */
-class TransactionUpdateService
-{
- use TransactionServiceTrait;
-
- /** @var User */
- private $user;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- if ('testing' === config('app.env')) {
- Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
- }
- }
-
-// /**
-// * @param int $transactionId
-// *
-// * @return Transaction|null
-// */
-// public function reconcile(int $transactionId): ?Transaction
-// {
-// $transaction = Transaction::find($transactionId);
-// if (null !== $transaction) {
-// $transaction->reconciled = true;
-// $transaction->save();
-//
-// return $transaction;
-// }
-//
-// return null;
-//
-// }
-
- /**
- * @param User $user
- */
- public function setUser(User $user): void
- {
- $this->user = $user;
- }
-
-// /**
-// * @param Transaction $transaction
-// * @param array $data
-// *
-// * @return Transaction
-// * @throws \FireflyIII\Exceptions\FireflyException
-// * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
-// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
-// * @SuppressWarnings(PHPMD.NPathComplexity)
-// *
-// */
-// public function update(Transaction $transaction, array $data): Transaction
-// {
-// $currency = $this->findCurrency($data['currency_id'], $data['currency_code']);
-// $journal = $transaction->transactionJournal;
-// $amount = (string)$data['amount'];
-// $account = null;
-// // update description:
-// $transaction->description = $data['description'];
-// $foreignAmount = null;
-// if ((float)$transaction->amount < 0) {
-// // this is the source transaction.
-// $type = $this->accountType($journal, 'source');
-// $account = $this->findAccount($type, $data['source_id'], $data['source_name']);
-// $amount = app('steam')->negative($amount);
-// $foreignAmount = app('steam')->negative((string)$data['foreign_amount']);
-// }
-//
-// if ((float)$transaction->amount > 0) {
-// // this is the destination transaction.
-// $type = $this->accountType($journal, 'destination');
-// $account = $this->findAccount($type, $data['destination_id'], $data['destination_name']);
-// $amount = app('steam')->positive($amount);
-// $foreignAmount = app('steam')->positive((string)$data['foreign_amount']);
-// }
-//
-// // update the actual transaction:
-// $transaction->description = $data['description'];
-// $transaction->amount = $amount;
-// $transaction->foreign_amount = null;
-// $transaction->transaction_currency_id = null === $currency ? $transaction->transaction_currency_id : $currency->id;
-// $transaction->account_id = $account->id;
-// $transaction->reconciled = $data['reconciled'];
-// $transaction->save();
-//
-// // set foreign currency
-// $foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
-// // set foreign amount:
-// if (null !== $foreign && null !== $data['foreign_amount']) {
-// $this->setForeignCurrency($transaction, $foreign);
-// $this->setForeignAmount($transaction, $foreignAmount);
-// }
-// if (null === $foreign || null === $data['foreign_amount']) {
-// $this->setForeignCurrency($transaction, null);
-// $this->setForeignAmount($transaction, null);
-// }
-//
-// // set budget:
-// $budget = $this->findBudget($data['budget_id'], $data['budget_name']);
-// $this->setBudget($transaction, $budget);
-//
-// // set category
-// $category = $this->findCategory($data['category_id'], $data['category_name']);
-// $this->setCategory($transaction, $category);
-//
-// return $transaction;
-// }
-//
-// /**
-// * Update budget for a journal.
-// *
-// * @param Transaction $transaction
-// * @param int $budgetId
-// *
-// * @return Transaction
-// */
-// public function updateBudget(Transaction $transaction, int $budgetId): Transaction
-// {
-// $budget = $this->findBudget($budgetId, null);
-// $this->setBudget($transaction, $budget);
-//
-// return $transaction;
-//
-// }
-//
-// /**
-// * Update category for a journal.
-// *
-// * @param Transaction $transaction
-// * @param string $category
-// *
-// * @return Transaction
-// */
-// public function updateCategory(Transaction $transaction, string $category): Transaction
-// {
-// $found = $this->findCategory(0, $category);
-// $this->setCategory($transaction, $found);
-//
-// return $transaction;
-// }
-}
diff --git a/app/Services/Password/PwndVerifierV2.php b/app/Services/Password/PwndVerifierV2.php
index 541274ca76..571e8277fb 100644
--- a/app/Services/Password/PwndVerifierV2.php
+++ b/app/Services/Password/PwndVerifierV2.php
@@ -30,6 +30,7 @@ use RuntimeException;
/**
* Class PwndVerifierV2.
+ * @codeCoverageIgnore
*/
class PwndVerifierV2 implements Verifier
{
diff --git a/app/Services/Password/PwndVerifierV3.php b/app/Services/Password/PwndVerifierV3.php
new file mode 100644
index 0000000000..833c86872e
--- /dev/null
+++ b/app/Services/Password/PwndVerifierV3.php
@@ -0,0 +1,92 @@
+.
+ */
+
+namespace FireflyIII\Services\Password;
+
+
+use Exception;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\GuzzleException;
+use Log;
+use RuntimeException;
+
+/**
+ * Class PwndVerifierV3
+ * @codeCoverageIgnore
+ */
+class PwndVerifierV3 implements Verifier
+{
+
+ /**
+ * Verify the given password against (some) service.
+ *
+ * @param string $password
+ *
+ * @return bool
+ */
+ public function validPassword(string $password): bool
+ {
+ Log::debug('Now in API v3.');
+ $hash = strtoupper(sha1($password));
+ $prefix = substr($hash, 0, 5);
+ $rest = substr($hash, 5);
+ $uri = sprintf('https://api.pwnedpasswords.com/%s/%s', 'range', $prefix);
+
+ Log::debug(sprintf('URI is %s', $uri));
+
+ $headers = [
+ 'User-Agent' => sprintf('Firefly III v%s', config('firefly.version')),
+ ];
+ Log::debug('Headers', $headers);
+ $opts = [
+ 'headers' => $headers,
+ 'timeout' => 5,
+ ];
+
+ Log::debug(sprintf('hash prefix is %s', $prefix));
+ Log::debug(sprintf('rest is %s', $rest));
+
+ try {
+ $client = new Client;
+ $res = $client->request('GET', $uri, $opts);
+ } catch (GuzzleException|Exception $e) {
+ Log::error(sprintf('Could not verify password security: %s', $e->getMessage()));
+ return true;
+ }
+ Log::debug(sprintf('Status code returned is %d', $res->getStatusCode()));
+ if (404 === $res->getStatusCode()) {
+ return true;
+ }
+ $body = $res->getBody()->getContents();
+ try {
+ $strpos = stripos($body, $rest);
+ } catch (RuntimeException $e) {
+ Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage()));
+ $strpos = false;
+ }
+ if (false === $strpos) {
+ Log::debug(sprintf('%s was not found in result body. Return true.', $rest));
+ return true;
+ }
+ Log::debug(sprintf('Found %s, so return FALSE.', $rest));
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/app/Services/Spectre/Request/CreateTokenRequest.php b/app/Services/Spectre/Request/CreateTokenRequest.php
index c700d7b78c..83e1aaab03 100644
--- a/app/Services/Spectre/Request/CreateTokenRequest.php
+++ b/app/Services/Spectre/Request/CreateTokenRequest.php
@@ -29,6 +29,7 @@ use FireflyIII\Services\Spectre\Object\Token;
/**
* Class CreateTokenRequest
+ * @codeCoverageIgnore
*/
class CreateTokenRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/ListAccountsRequest.php b/app/Services/Spectre/Request/ListAccountsRequest.php
index 6147f1fc3f..469ba5e313 100644
--- a/app/Services/Spectre/Request/ListAccountsRequest.php
+++ b/app/Services/Spectre/Request/ListAccountsRequest.php
@@ -30,6 +30,7 @@ use Log;
/**
* Class ListAccountsRequest
+ * @codeCoverageIgnore
*/
class ListAccountsRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/ListCustomersRequest.php b/app/Services/Spectre/Request/ListCustomersRequest.php
index fe7bbc7cf9..f17caed6a1 100644
--- a/app/Services/Spectre/Request/ListCustomersRequest.php
+++ b/app/Services/Spectre/Request/ListCustomersRequest.php
@@ -29,6 +29,7 @@ use Log;
/**
* Class ListCustomersRequest
+ * @codeCoverageIgnore
*/
class ListCustomersRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/ListLoginsRequest.php b/app/Services/Spectre/Request/ListLoginsRequest.php
index 4eafc807f2..d52308ae8e 100644
--- a/app/Services/Spectre/Request/ListLoginsRequest.php
+++ b/app/Services/Spectre/Request/ListLoginsRequest.php
@@ -31,6 +31,7 @@ use Log;
/**
* Class ListLoginsRequest
+ * @codeCoverageIgnore
*/
class ListLoginsRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/ListTransactionsRequest.php b/app/Services/Spectre/Request/ListTransactionsRequest.php
index df97789516..0fd161c751 100644
--- a/app/Services/Spectre/Request/ListTransactionsRequest.php
+++ b/app/Services/Spectre/Request/ListTransactionsRequest.php
@@ -30,6 +30,7 @@ use Log;
/**
* Class ListTransactionsRequest
+ * @codeCoverageIgnore
*/
class ListTransactionsRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/NewCustomerRequest.php b/app/Services/Spectre/Request/NewCustomerRequest.php
index 36e4946387..f6c31f9932 100644
--- a/app/Services/Spectre/Request/NewCustomerRequest.php
+++ b/app/Services/Spectre/Request/NewCustomerRequest.php
@@ -27,6 +27,7 @@ use Log;
/**
* Class NewCustomerRequest
+ * @codeCoverageIgnore
*/
class NewCustomerRequest extends SpectreRequest
{
diff --git a/app/Services/Spectre/Request/SpectreRequest.php b/app/Services/Spectre/Request/SpectreRequest.php
index d392fad037..f07a5e175e 100644
--- a/app/Services/Spectre/Request/SpectreRequest.php
+++ b/app/Services/Spectre/Request/SpectreRequest.php
@@ -32,6 +32,7 @@ use RuntimeException;
/**
* Class SpectreRequest
+ * @codeCoverageIgnore
*/
abstract class SpectreRequest
{
diff --git a/app/Services/Ynab/Request/GetAccountsRequest.php b/app/Services/Ynab/Request/GetAccountsRequest.php
index 81c4a1f5be..c4e4e83bae 100644
--- a/app/Services/Ynab/Request/GetAccountsRequest.php
+++ b/app/Services/Ynab/Request/GetAccountsRequest.php
@@ -27,6 +27,7 @@ use Log;
/**
* Class GetAccountsRequest
+ * @codeCoverageIgnore
*/
class GetAccountsRequest extends YnabRequest
{
diff --git a/app/Services/Ynab/Request/GetBudgetsRequest.php b/app/Services/Ynab/Request/GetBudgetsRequest.php
index b087467b3f..03691de2d5 100644
--- a/app/Services/Ynab/Request/GetBudgetsRequest.php
+++ b/app/Services/Ynab/Request/GetBudgetsRequest.php
@@ -27,6 +27,7 @@ use Log;
/**
* Class GetBudgetsRequest
+ * @codeCoverageIgnore
*/
class GetBudgetsRequest extends YnabRequest
{
diff --git a/app/Services/Ynab/Request/GetTransactionsRequest.php b/app/Services/Ynab/Request/GetTransactionsRequest.php
index bc6e23cd9e..cc02d9c40b 100644
--- a/app/Services/Ynab/Request/GetTransactionsRequest.php
+++ b/app/Services/Ynab/Request/GetTransactionsRequest.php
@@ -27,6 +27,7 @@ use Log;
/**
* Class GetTransactionsRequest
+ * @codeCoverageIgnore
*/
class GetTransactionsRequest extends YnabRequest
{
diff --git a/app/Services/Ynab/Request/YnabRequest.php b/app/Services/Ynab/Request/YnabRequest.php
index e2cd4ab26a..c538100db2 100644
--- a/app/Services/Ynab/Request/YnabRequest.php
+++ b/app/Services/Ynab/Request/YnabRequest.php
@@ -30,6 +30,7 @@ use RuntimeException;
/**
* Class YnabRequest
+ * @codeCoverageIgnore
*/
abstract class YnabRequest
{
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 35956e4376..fa8d176d2c 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -33,6 +33,7 @@ use Preferences as Prefs;
/**
* Class Amount.
+ * @codeCoverageIgnore
*/
class Amount
{
diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php
index c2fb3a179a..b25a4f520e 100644
--- a/app/Support/CacheProperties.php
+++ b/app/Support/CacheProperties.php
@@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
/**
* Class CacheProperties.
+ * @codeCoverageIgnore
*/
class CacheProperties
{
diff --git a/app/Support/ChartColour.php b/app/Support/ChartColour.php
index 5f0ab48904..8b1c4d1d47 100644
--- a/app/Support/ChartColour.php
+++ b/app/Support/ChartColour.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
/**
* Class ChartColour.
+ * @codeCoverageIgnore
*/
class ChartColour
{
diff --git a/app/Support/Cronjobs/AbstractCronjob.php b/app/Support/Cronjobs/AbstractCronjob.php
index bfd6904908..37d2fbd0a8 100644
--- a/app/Support/Cronjobs/AbstractCronjob.php
+++ b/app/Support/Cronjobs/AbstractCronjob.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Cronjobs;
/**
* Class AbstractCronjob
+ * @codeCoverageIgnore
*/
abstract class AbstractCronjob
{
diff --git a/app/Support/Cronjobs/RecurringCronjob.php b/app/Support/Cronjobs/RecurringCronjob.php
index f4062571c4..863a9670fc 100644
--- a/app/Support/Cronjobs/RecurringCronjob.php
+++ b/app/Support/Cronjobs/RecurringCronjob.php
@@ -99,13 +99,7 @@ class RecurringCronjob extends AbstractCronjob
Log::info(sprintf('It has been %s since the recurring transactions cron-job has fired. It will fire now!', $diffForHumans));
}
- try {
- $this->fireRecurring();
- } catch (FireflyException $e) {
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- throw new FireflyException(sprintf('Could not run recurring transaction cron job: %s', $e->getMessage()));
- }
+ $this->fireRecurring();
app('preferences')->mark();
@@ -114,12 +108,13 @@ class RecurringCronjob extends AbstractCronjob
/**
*
- * @throws FireflyException
*/
private function fireRecurring(): void
{
Log::info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d')));
- $job = new CreateRecurringTransactions($this->date);
+ /** @var CreateRecurringTransactions $job */
+ $job = app(CreateRecurringTransactions::class);
+ $job->setDate($this->date);
$job->setForce($this->force);
$job->handle();
app('fireflyconfig')->set('last_rt_job', (int)$this->date->format('U'));
diff --git a/app/Support/Domain.php b/app/Support/Domain.php
index 6ccc9a07f3..3cc6f62acd 100644
--- a/app/Support/Domain.php
+++ b/app/Support/Domain.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
/**
* Class Domain.
+ * @codeCoverageIgnore
*/
class Domain
{
diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php
index a572b398e1..603127fe04 100644
--- a/app/Support/ExpandedForm.php
+++ b/app/Support/ExpandedForm.php
@@ -48,6 +48,7 @@ use Throwable;
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
+ * @codeCoverageIgnore
*/
class ExpandedForm
{
diff --git a/app/Support/FinTS/FinTS.php b/app/Support/FinTS/FinTS.php
index 456a9f9b07..dff4c57b53 100644
--- a/app/Support/FinTS/FinTS.php
+++ b/app/Support/FinTS/FinTS.php
@@ -27,7 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
use Illuminate\Support\Facades\Crypt;
/**
- *
+ * @codeCoverageIgnore
* Class FinTS
*/
class FinTS
diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php
index 1cf6aa184d..11a51616d5 100644
--- a/app/Support/FireflyConfig.php
+++ b/app/Support/FireflyConfig.php
@@ -29,6 +29,7 @@ use Log;
/**
* Class FireflyConfig.
+ * @codeCoverageIgnore
*/
class FireflyConfig
{
diff --git a/app/Support/Http/Api/AccountFilter.php b/app/Support/Http/Api/AccountFilter.php
index f9594baf29..70fc6da847 100644
--- a/app/Support/Http/Api/AccountFilter.php
+++ b/app/Support/Http/Api/AccountFilter.php
@@ -27,6 +27,7 @@ use FireflyIII\Models\AccountType;
/**
* Trait AccountFilter
+ * @codeCoverageIgnore
*/
trait AccountFilter
{
@@ -78,10 +79,8 @@ trait AccountFilter
'credit-card' => [AccountType::CREDITCARD],
'creditcard' => [AccountType::CREDITCARD],
'cc' => [AccountType::CREDITCARD],
-
];
- $return = $types[$type] ?? $types['all'];
- return $return; // @codeCoverageIgnore
+ return $types[$type] ?? $types['all'];
}
}
diff --git a/app/Support/Http/Api/ApiSupport.php b/app/Support/Http/Api/ApiSupport.php
index fe92f28f2c..544a5fb22a 100644
--- a/app/Support/Http/Api/ApiSupport.php
+++ b/app/Support/Http/Api/ApiSupport.php
@@ -26,6 +26,7 @@ use Illuminate\Support\Collection;
/**
* Trait ApiSupport
+ * @codeCoverageIgnore
*/
trait ApiSupport
{
diff --git a/app/Support/Http/Api/TransactionFilter.php b/app/Support/Http/Api/TransactionFilter.php
index 109611c416..07147161da 100644
--- a/app/Support/Http/Api/TransactionFilter.php
+++ b/app/Support/Http/Api/TransactionFilter.php
@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionType;
/**
* Trait TransactionFilter
+ * @codeCoverageIgnore
*/
trait TransactionFilter
{
@@ -58,9 +59,8 @@ trait TransactionFilter
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER,],
];
- $return = $types[$type] ?? $types['default'];
+ return $types[$type] ?? $types['default'];
- return $return;
}
}
diff --git a/app/Support/Import/Information/GetSpectreCustomerTrait.php b/app/Support/Import/Information/GetSpectreCustomerTrait.php
index 2da8a1227e..9f065359fc 100644
--- a/app/Support/Import/Information/GetSpectreCustomerTrait.php
+++ b/app/Support/Import/Information/GetSpectreCustomerTrait.php
@@ -32,7 +32,7 @@ use Log;
/**
* Trait GetSpectreCustomerTrait
- *
+ * @codeCoverageIgnore
*/
trait GetSpectreCustomerTrait
{
diff --git a/app/Support/Import/Information/GetSpectreTokenTrait.php b/app/Support/Import/Information/GetSpectreTokenTrait.php
index dd866cc814..e29c10f19f 100644
--- a/app/Support/Import/Information/GetSpectreTokenTrait.php
+++ b/app/Support/Import/Information/GetSpectreTokenTrait.php
@@ -31,7 +31,7 @@ use Log;
/**
* Trait GetSpectreTokenTrait
- *
+ * @codeCoverageIgnore
*/
trait GetSpectreTokenTrait
{
diff --git a/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php b/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php
index b792f7b145..48bf73f351 100644
--- a/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php
+++ b/app/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandler.php
@@ -119,7 +119,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
Log::debug(sprintf('IBAN for bunq account #%d is "%s"', $bunqId, $bunqIban));
if (null !== $bunqIban) {
- $ibanToAsset[$bunqIban] = $accountId;
+ $ibanToAsset[$bunqIban] = $accountId; // @codeCoverageIgnore
}
$final[$bunqId] = $accountId;
}
diff --git a/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php b/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php
index de924873c8..9eedad889a 100644
--- a/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php
+++ b/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php
@@ -312,7 +312,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
asort($columnConfig[$columnIndex]['values']);
// if the count of this array is zero, there is nothing to map.
if (0 === count($columnConfig[$columnIndex]['values'])) {
- unset($columnConfig[$columnIndex]);
+ unset($columnConfig[$columnIndex]); // @codeCoverageIgnore
}
}
diff --git a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php
index 67ac1caaab..e657526d8d 100644
--- a/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php
+++ b/app/Support/Import/JobConfiguration/FinTS/ChooseAccountHandler.php
@@ -34,8 +34,8 @@ use FireflyIII\Support\FinTS\FinTS;
use Illuminate\Support\MessageBag;
/**
- *
* Class ChooseAccountHandler
+ * @codeCoverageIgnore
*/
class ChooseAccountHandler implements FinTSConfigurationInterface
{
diff --git a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php
index 2c688158e0..e3a1341e8a 100644
--- a/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php
+++ b/app/Support/Import/JobConfiguration/FinTS/NewFinTSJobHandler.php
@@ -32,8 +32,8 @@ use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\MessageBag;
/**
- *
* Class NewFinTSJobHandler
+ * @codeCoverageIgnore
*/
class NewFinTSJobHandler implements FinTSConfigurationInterface
{
@@ -62,7 +62,6 @@ class NewFinTSJobHandler implements FinTSConfigurationInterface
$this->repository->setConfiguration($this->importJob, $config);
-
$incomplete = false;
foreach ($config as $value) {
$incomplete = '' === $value or $incomplete;
diff --git a/app/Support/Import/Placeholder/ImportTransaction.php b/app/Support/Import/Placeholder/ImportTransaction.php
index 3d0ed44007..2ae4d3b3f6 100644
--- a/app/Support/Import/Placeholder/ImportTransaction.php
+++ b/app/Support/Import/Placeholder/ImportTransaction.php
@@ -33,6 +33,7 @@ use Log;
/**
* Class ImportTransaction
+ * @codeCoverageIgnore
*/
class ImportTransaction
{
@@ -179,7 +180,7 @@ class ImportTransaction
'date-process' => 'date_process',
'date-due' => 'date_due',
];
- if (in_array($role, array_keys($replaceOldRoles))) {
+ if (array_key_exists($role, $replaceOldRoles)) {
$role = $replaceOldRoles[$role];
}
diff --git a/app/Support/Import/Routine/File/OpposingAccountMapper.php b/app/Support/Import/Routine/File/OpposingAccountMapper.php
index 40c2acf498..497b9d2e1e 100644
--- a/app/Support/Import/Routine/File/OpposingAccountMapper.php
+++ b/app/Support/Import/Routine/File/OpposingAccountMapper.php
@@ -114,9 +114,9 @@ class OpposingAccountMapper
$creation = [
'name' => $data['name'] ?? '(no name)',
'iban' => $data['iban'] ?? null,
- 'accountNumber' => $data['number'] ?? null,
+ 'account_number' => $data['number'] ?? null,
'account_type_id' => null,
- 'account_type' => $expectedType,
+ 'account_type' => $expectedType,
'active' => true,
'BIC' => $data['bic'] ?? null,
];
diff --git a/app/Support/Logging/AuditLogger.php b/app/Support/Logging/AuditLogger.php
index 1c17d6c37c..9895f1017d 100644
--- a/app/Support/Logging/AuditLogger.php
+++ b/app/Support/Logging/AuditLogger.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
/**
* Class AuditLogger
+ * @codeCoverageIgnore
*/
class AuditLogger
{
diff --git a/app/Support/Logging/AuditProcessor.php b/app/Support/Logging/AuditProcessor.php
index 823f5e57ff..831fd6099b 100644
--- a/app/Support/Logging/AuditProcessor.php
+++ b/app/Support/Logging/AuditProcessor.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Logging;
/**
* Class AuditProcessor
+ * @codeCoverageIgnore
*/
class AuditProcessor
{
diff --git a/app/Support/NullArrayObject.php b/app/Support/NullArrayObject.php
index 5f7728a86f..a7d9fe98b1 100644
--- a/app/Support/NullArrayObject.php
+++ b/app/Support/NullArrayObject.php
@@ -26,6 +26,10 @@ namespace FireflyIII\Support;
use ArrayObject;
+/**
+ * Class NullArrayObject
+ * @codeCoverageIgnore
+ */
class NullArrayObject extends ArrayObject
{
public $default = null;
diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php
index c61aebf183..b8b65a07be 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -32,6 +32,7 @@ use Session;
/**
* Class Preferences.
+ * @codeCoverageIgnore
*/
class Preferences
{
diff --git a/app/Support/Search/Modifier.php b/app/Support/Search/Modifier.php
deleted file mode 100644
index 076d19a9e0..0000000000
--- a/app/Support/Search/Modifier.php
+++ /dev/null
@@ -1,203 +0,0 @@
-.
- */
-declare(strict_types=1);
-
-namespace FireflyIII\Support\Search;
-
-use Carbon\Carbon;
-use Exception;
-use FireflyIII\Models\Transaction;
-use Log;
-
-/**
- * Class Modifier
- */
-class Modifier
-{
- /**
- * @param Transaction $transaction
- * @param string $amount
- * @param int $expected
- *
- * @return bool
- */
- public static function amountCompare(Transaction $transaction, string $amount, int $expected): bool
- {
- $amount = app('steam')->positive($amount);
- $transactionAmount = app('steam')->positive($transaction->transaction_amount);
-
- $compare = bccomp($amount, $transactionAmount);
- Log::debug(sprintf('%s vs %s is %d', $amount, $transactionAmount, $compare));
-
- return $compare === $expected;
- }
-
- /**
- * @param array $modifier
- * @param Transaction $transaction
- *
- * @return bool
- *
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public static function apply(array $modifier, Transaction $transaction): bool
- {
- $res = true;
- switch ($modifier['type']) {
- case 'source':
- $name = $transaction->account_name;
- $res = self::stringCompare($name, $modifier['value']);
- Log::debug(sprintf('Source is %s? %s', $modifier['value'], var_export($res, true)));
- break;
- case 'destination':
- $name = $transaction->opposing_account_name;
- $res = self::stringCompare($name, $modifier['value']);
- Log::debug(sprintf('Destination is %s? %s', $modifier['value'], var_export($res, true)));
- break;
- case 'category':
- $res = self::category($transaction, $modifier['value']);
- Log::debug(sprintf('Category is %s? %s', $modifier['value'], var_export($res, true)));
- break;
- case 'budget':
- $res = self::budget($transaction, $modifier['value']);
- Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true)));
- break;
- case 'bill':
- $name = $transaction->bill_name;
- $res = self::stringCompare($name, $modifier['value']);
- Log::debug(sprintf('Bill is %s? %s', $modifier['value'], var_export($res, true)));
- break;
- }
-
- return $res;
- }
-
- /**
- * @param Carbon $date
- * @param string $compare
- *
- * @return bool
- */
- public static function dateAfter(Carbon $date, string $compare): bool
- {
- try {
- $compareDate = new Carbon($compare);
- } catch (Exception $e) {
- Log::debug(sprintf('Not interesting in Modifier:dateAfter(): %s', $e->getMessage()));
-
- return false;
- }
-
- return $date->greaterThanOrEqualTo($compareDate);
- }
-
- /**
- * @param Carbon $date
- * @param string $compare
- *
- * @return bool
- */
- public static function dateBefore(Carbon $date, string $compare): bool
- {
- try {
- $compareDate = new Carbon($compare);
- } catch (Exception $e) {
- Log::debug(sprintf('Not interesting in modifier:dateBefore(): %s', $e->getMessage()));
-
- return false;
- }
-
- return $date->lessThanOrEqualTo($compareDate);
- }
-
- /**
- * @param Carbon $date
- * @param string $compare
- *
- * @return bool
- */
- public static function sameDate(Carbon $date, string $compare): bool
- {
- try {
- $compareDate = new Carbon($compare);
- } catch (Exception $e) {
- Log::debug(sprintf('Not interesting in Modifier:sameDate(): %s', $e->getMessage()));
-
- return false;
- }
-
- return $compareDate->isSameDay($date);
- }
-
- /**
- * @param string $haystack
- * @param string $needle
- *
- * @return bool
- */
- public static function stringCompare(string $haystack, string $needle): bool
- {
- $res = !(false === stripos($haystack, $needle));
- Log::debug(sprintf('"%s" is in "%s"? %s', $needle, $haystack, var_export($res, true)));
-
- return $res;
- }
-
- /**
- * @param Transaction $transaction
- * @param string $search
- *
- * @return bool
- */
- private static function budget(Transaction $transaction, string $search): bool
- {
- $journalBudget = '';
- if (null !== $transaction->transaction_journal_budget_name) {
- $journalBudget = $transaction->transaction_journal_budget_name;
- }
- $transactionBudget = '';
- if (null !== $transaction->transaction_budget_name) {
- $journalBudget = $transaction->transaction_budget_name;
- }
-
- return self::stringCompare($journalBudget, $search) || self::stringCompare($transactionBudget, $search);
- }
-
- /**
- * @param Transaction $transaction
- * @param string $search
- *
- * @return bool
- */
- private static function category(Transaction $transaction, string $search): bool
- {
- $journalCategory = '';
- if (null !== $transaction->transaction_journal_category_name) {
- $journalCategory = $transaction->transaction_journal_category_name;
- }
- $transactionCategory = '';
- if (null !== $transaction->transaction_category_name) {
- $journalCategory = $transaction->transaction_category_name;
- }
-
- return self::stringCompare($journalCategory, $search) || self::stringCompare($transactionCategory, $search);
- }
-}
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index b4e4fcd98a..1290534d14 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -33,6 +33,7 @@ use stdClass;
/**
* Class Steam.
+ * @codeCoverageIgnore
*/
class Steam
{
diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php
index 1530e98580..c360ee651a 100644
--- a/app/Transformers/AccountTransformer.php
+++ b/app/Transformers/AccountTransformer.php
@@ -105,7 +105,7 @@ class AccountTransformer extends AbstractTransformer
'notes' => $this->repository->getNoteText($account),
'monthly_payment_date' => $monthlyPaymentDate,
'credit_card_type' => $creditCardType,
- 'account_number' => $this->repository->getMetaValue($account, 'accountNumber'),
+ 'account_number' => $this->repository->getMetaValue($account, 'account_number'),
'iban' => '' === $account->iban ? null : $account->iban,
'bic' => $this->repository->getMetaValue($account, 'BIC'),
'virtual_balance' => round($account->virtual_balance, $decimalPlaces),
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 6ef94658ea..d75712fc36 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -433,7 +433,7 @@ class FireflyValidator extends Validator
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at')
->where('accounts.user_id', auth()->user()->id)
- ->where('account_meta.name', 'accountNumber');
+ ->where('account_meta.name', 'account_number');
if ($accountId > 0) {
// exclude current account from check.
diff --git a/config/firefly.php b/config/firefly.php
index ad3419778e..d38ea17020 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -120,33 +120,33 @@ use FireflyIII\User;
*/
return [
- 'configuration' => [
+ 'configuration' => [
'single_user_mode' => true,
'is_demo_site' => false,
],
- 'encryption' => null === env('USE_ENCRYPTION') || env('USE_ENCRYPTION') === true,
- 'version' => '4.8.0',
- 'api_version' => '0.10.0',
- 'db_version' => 11,
- 'maxUploadSize' => 15242880,
- 'send_error_message' => env('SEND_ERROR_MESSAGE', true),
- 'site_owner' => env('SITE_OWNER', ''),
- 'send_registration_mail' => env('SEND_REGISTRATION_MAIL', true),
- 'demo_username' => env('DEMO_USERNAME', ''),
- 'demo_password' => env('DEMO_PASSWORD', ''),
- 'is_sandstorm' => env('IS_SANDSTORM', 'unknown'),
- 'is_docker' => env('IS_DOCKER', 'unknown'),
- 'bunq_use_sandbox' => env('BUNQ_USE_SANDBOX', false),
- 'fixer_api_key' => env('FIXER_API_KEY', ''),
- 'mapbox_api_key' => env('MAPBOX_API_KEY', ''),
- 'trusted_proxies' => env('TRUSTED_PROXIES', ''),
- 'search_result_limit' => env('SEARCH_RESULT_LIMIT', 50),
- 'send_report_journals' => envNonEmpty('SEND_REPORT_JOURNALS', true),
- 'analytics_id' => env('ANALYTICS_ID', ''),
- 'disable_frame_header' => env('DISABLE_FRAME_HEADER', false),
- 'login_provider' => envNonEmpty('LOGIN_PROVIDER', 'eloquent'),
- 'cer_provider' => envNonEmpty('CER_PROVIDER', 'fixer'),
- 'allowedMimes' => [
+ 'encryption' => null === env('USE_ENCRYPTION') || env('USE_ENCRYPTION') === true,
+ 'version' => '4.8.0',
+ 'api_version' => '0.10.0',
+ 'db_version' => 11,
+ 'maxUploadSize' => 15242880,
+ 'send_error_message' => env('SEND_ERROR_MESSAGE', true),
+ 'site_owner' => env('SITE_OWNER', ''),
+ 'send_registration_mail' => env('SEND_REGISTRATION_MAIL', true),
+ 'demo_username' => env('DEMO_USERNAME', ''),
+ 'demo_password' => env('DEMO_PASSWORD', ''),
+ 'is_sandstorm' => env('IS_SANDSTORM', 'unknown'),
+ 'is_docker' => env('IS_DOCKER', 'unknown'),
+ 'bunq_use_sandbox' => env('BUNQ_USE_SANDBOX', false),
+ 'fixer_api_key' => env('FIXER_API_KEY', ''),
+ 'mapbox_api_key' => env('MAPBOX_API_KEY', ''),
+ 'trusted_proxies' => env('TRUSTED_PROXIES', ''),
+ 'search_result_limit' => env('SEARCH_RESULT_LIMIT', 50),
+ 'send_report_journals' => envNonEmpty('SEND_REPORT_JOURNALS', true),
+ 'analytics_id' => env('ANALYTICS_ID', ''),
+ 'disable_frame_header' => env('DISABLE_FRAME_HEADER', false),
+ 'login_provider' => envNonEmpty('LOGIN_PROVIDER', 'eloquent'),
+ 'cer_provider' => envNonEmpty('CER_PROVIDER', 'fixer'),
+ 'allowedMimes' => [
/* plain files */
'text/plain',
diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xml
index 1668ed37e6..34a20e5a32 100644
--- a/phpunit.coverage.specific.xml
+++ b/phpunit.coverage.specific.xml
@@ -43,8 +43,12 @@
./tests/Unit/Generator
./tests/Unit/Handlers
./tests/Unit/Helpers
- ./tests/Unit/Middleware
./tests/Unit/Import
+ ./tests/Unit/Jobs
+ ./tests/Unit/Middleware
+ ./tests/Unit/Rules
+ ./tests/Unit/Services
+ ./tests/Unit/Support
./tests/Feature
diff --git a/phpunit.coverage.xml b/phpunit.coverage.xml
index fb90e9e3ac..0541833e2c 100644
--- a/phpunit.coverage.xml
+++ b/phpunit.coverage.xml
@@ -43,8 +43,12 @@
./tests/Unit/Generator
./tests/Unit/Handlers
./tests/Unit/Helpers
- ./tests/Unit/Middleware
./tests/Unit/Import
+ ./tests/Unit/Jobs
+ ./tests/Unit/Middleware
+ ./tests/Unit/Rules
+ ./tests/Unit/Services
+ ./tests/Unit/Support
./tests/Feature
diff --git a/phpunit.xml b/phpunit.xml
index 7ec3b07a53..85e0cb367c 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -43,8 +43,12 @@
./tests/Unit/Generator
./tests/Unit/Handlers
./tests/Unit/Helpers
- ./tests/Unit/Middleware
./tests/Unit/Import
+ ./tests/Unit/Jobs
+ ./tests/Unit/Middleware
+ ./tests/Unit/Rules
+ ./tests/Unit/Services
+ ./tests/Unit/Support
./tests/Feature
diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php
index 9f9559b23e..b809d6a23d 100644
--- a/routes/breadcrumbs.php
+++ b/routes/breadcrumbs.php
@@ -290,8 +290,8 @@ try {
if (null !== $group && $group instanceof TransactionGroup) {
$breadcrumbs->parent('transactions.show', $object->transactionGroup);
}
- $breadcrumbs->push(limitStringLength($attachment->filename), route('attachments.edit', [$attachment]));
}
+ $breadcrumbs->push(limitStringLength($attachment->filename), route('attachments.edit', [$attachment]));
}
);
Breadcrumbs::register(
diff --git a/tests/Api/V1/Controllers/CurrencyControllerTest.php b/tests/Api/V1/Controllers/CurrencyControllerTest.php
index 3dda5deaa9..ddb3113a7a 100644
--- a/tests/Api/V1/Controllers/CurrencyControllerTest.php
+++ b/tests/Api/V1/Controllers/CurrencyControllerTest.php
@@ -76,6 +76,7 @@ class CurrencyControllerTest extends TestCase
// mock facades.
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
+ Preferences::shouldReceive('mark');
// mock calls:
$repository->shouldReceive('setUser')->once();
@@ -110,6 +111,9 @@ class CurrencyControllerTest extends TestCase
$transformer = $this->mock(CurrencyTransformer::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
+ // mock facades.
+ Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
+
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
@@ -124,8 +128,8 @@ class CurrencyControllerTest extends TestCase
$repository->shouldReceive('store')->andReturn($currency);
Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->once();
Preferences::shouldReceive('mark')->once();
- Preferences::shouldReceive('lastActivity')->once();
- Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
+ //Preferences::shouldReceive('lastActivity')->once();
+ //Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
// data to submit:
$data = [
@@ -162,6 +166,8 @@ class CurrencyControllerTest extends TestCase
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
+ Preferences::shouldReceive('mark');
+ Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
// mock calls:
$repository->shouldReceive('setUser')->once();
@@ -210,8 +216,9 @@ class CurrencyControllerTest extends TestCase
$repository->shouldReceive('update')->andReturn($currency);
Preferences::shouldReceive('set')->withArgs(['currencyPreference', 'EUR'])->once();
Preferences::shouldReceive('mark')->once();
- Preferences::shouldReceive('lastActivity')->once();
- Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
+ //Preferences::shouldReceive('lastActivity')->once();
+ Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
+ //Preferences::shouldReceive('getForUser')->once()->andReturn($preference);
// data to submit:
$data = [
diff --git a/tests/Api/V1/Controllers/RuleControllerTest.php b/tests/Api/V1/Controllers/RuleControllerTest.php
index c817d1e72c..b7c4a19504 100644
--- a/tests/Api/V1/Controllers/RuleControllerTest.php
+++ b/tests/Api/V1/Controllers/RuleControllerTest.php
@@ -24,17 +24,18 @@ declare(strict_types=1);
namespace Tests\Api\V1\Controllers;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
-use FireflyIII\Jobs\Job;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
+use FireflyIII\TransactionRules\Engine\RuleEngine;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use Laravel\Passport\Passport;
use Log;
-use Queue;
+use Preferences;
use Tests\TestCase;
/**
@@ -117,6 +118,7 @@ class RuleControllerTest extends TestCase
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(RuleTransformer::class);
+ Preferences::shouldReceive('mark');
$accountRepos->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('setUser')->once();
@@ -250,8 +252,23 @@ class RuleControllerTest extends TestCase
$rule = $this->user()->rules()->first();
$repository = $this->mock(AccountRepositoryInterface::class);
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
- $asset = $this->getRandomAsset();
- $expense = $this->getRandomExpense();
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $ruleEngine = $this->mock(RuleEngine::class);
+ Preferences::shouldReceive('mark');
+
+ // new mocks for ruleEngine
+ $ruleEngine->shouldReceive('setUser')->atLeast()->once();
+ $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
+ $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
+ $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
+
+ $collector->shouldReceive('setAccounts')->atLeast()->once();
+ $collector->shouldReceive('setRange')->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
+
+
+ $asset = $this->getRandomAsset();
+ $expense = $this->getRandomExpense();
$repository->shouldReceive('setUser')->once();
$ruleRepos->shouldReceive('setUser')->once();
@@ -259,16 +276,8 @@ class RuleControllerTest extends TestCase
$repository->shouldReceive('findNull')->withArgs([2])->andReturn($expense);
$repository->shouldReceive('findNull')->withArgs([3])->andReturn(null);
- Queue::fake();
-
$response = $this->post(route('api.v1.rules.trigger', [$rule->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
$response->assertStatus(204);
-
- Queue::assertPushed(
- ExecuteRuleOnExistingTransactions::class, function (Job $job) use ($rule) {
- return $job->getRule()->id === $rule->id;
- }
- );
}
/**
diff --git a/tests/Api/V1/Controllers/RuleGroupControllerTest.php b/tests/Api/V1/Controllers/RuleGroupControllerTest.php
index 03e34fcb51..550320959a 100644
--- a/tests/Api/V1/Controllers/RuleGroupControllerTest.php
+++ b/tests/Api/V1/Controllers/RuleGroupControllerTest.php
@@ -24,12 +24,14 @@ declare(strict_types=1);
namespace Tests\Api\V1\Controllers;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Jobs\Job;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use FireflyIII\TransactionRules\Engine\RuleEngine;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
@@ -171,6 +173,21 @@ class RuleGroupControllerTest extends TestCase
$repository = $this->mock(AccountRepositoryInterface::class);
$matcher = $this->mock(TransactionMatcher::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $ruleEngine = $this->mock(RuleEngine::class);
+
+
+ // new mocks for ruleEngine
+ $ruleEngine->shouldReceive('setUser')->atLeast()->once();
+ $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
+ $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
+ $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
+
+ $collector->shouldReceive('setAccounts')->atLeast()->once();
+ $collector->shouldReceive('setRange')->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
+
+
$ruleGroupRepos->shouldReceive('setUser')->once();
$repository->shouldReceive('setUser')->once();
$ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection([$rule]));
@@ -181,16 +198,9 @@ class RuleGroupControllerTest extends TestCase
$repository->shouldReceive('isAsset')->withArgs([1])->andReturn(true);
$repository->shouldReceive('isAsset')->withArgs([2])->andReturn(false);
- Queue::fake();
$response = $this->post(route('api.v1.rule_groups.trigger', [$group->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
$response->assertStatus(204);
-
- Queue::assertPushed(
- ExecuteRuleOnExistingTransactions::class, function (Job $job) use ($rule) {
- return $job->getRule()->id === $rule->id;
- }
- );
}
/**
diff --git a/tests/Feature/Controllers/Rule/SelectControllerTest.php b/tests/Feature/Controllers/Rule/SelectControllerTest.php
index 2e5655cd89..a6a71f3fd6 100644
--- a/tests/Feature/Controllers/Rule/SelectControllerTest.php
+++ b/tests/Feature/Controllers/Rule/SelectControllerTest.php
@@ -24,16 +24,16 @@ declare(strict_types=1);
namespace tests\Feature\Controllers\Rule;
use Carbon\Carbon;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
-use FireflyIII\Jobs\Job;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
+use FireflyIII\TransactionRules\Engine\RuleEngine;
use FireflyIII\TransactionRules\TransactionMatcher;
use Illuminate\Support\Collection;
use Log;
use Mockery;
-use Queue;
use Tests\TestCase;
@@ -61,10 +61,23 @@ class SelectControllerTest extends TestCase
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $ruleEngine = $this->mock(RuleEngine::class);
+
$this->session(['first' => new Carbon('2010-01-01')]);
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
- Queue::fake();
+
+ // new mocks for ruleEngine
+ $ruleEngine->shouldReceive('setUser')->atLeast()->once();
+ $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
+ $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
+ $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
+
+ $collector->shouldReceive('setAccounts')->atLeast()->once();
+ $collector->shouldReceive('setRange')->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
+
$data = [
'accounts' => [1],
@@ -77,11 +90,6 @@ class SelectControllerTest extends TestCase
$response->assertStatus(302);
$response->assertSessionHas('success');
- Queue::assertPushed(
- ExecuteRuleOnExistingTransactions::class, function (Job $job) {
- return 1 === $job->getRule()->id;
- }
- );
}
/**
diff --git a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
index 4b620b4a46..6bcb9a0223 100644
--- a/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
+++ b/tests/Feature/Controllers/RuleGroup/ExecutionControllerTest.php
@@ -23,14 +23,19 @@ namespace Tests\Feature\Controllers\RuleGroup;
use Carbon\Carbon;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
+use FireflyIII\TransactionRules\Engine\RuleEngine;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
+/**
+ * Class ExecutionControllerTest
+ */
class ExecutionControllerTest extends TestCase
{
/**
@@ -50,9 +55,21 @@ class ExecutionControllerTest extends TestCase
{
$this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
+
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $ruleEngine = $this->mock(RuleEngine::class);
+
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
- $this->expectsJobs(ExecuteRuleGroupOnExistingTransactions::class);
+ // new mocks for ruleEngine
+ $ruleEngine->shouldReceive('setUser')->atLeast()->once();
+ $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once();
+ $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once();
+ $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once();
+
+ $collector->shouldReceive('setAccounts')->atLeast()->once();
+ $collector->shouldReceive('setRange')->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]);
$this->session(['first' => new Carbon('2010-01-01')]);
$data = [
diff --git a/tests/TestCase.php b/tests/TestCase.php
index bca8c6354a..82c362c887 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -39,6 +39,7 @@ use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\CurrencyExchangeRate;
+use FireflyIII\Models\ImportJob;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Recurrence;
@@ -66,6 +67,13 @@ use RuntimeException;
abstract class TestCase extends BaseTestCase
{
+ /**
+ * @return ImportJob
+ */
+ public function getRandomImportJob(): ImportJob
+ {
+ return $this->user()->importJobs()->inRandomOrder()->first();
+ }
/**
* @return Recurrence
*/
diff --git a/tests/Unit/Factory/PiggyBankFactoryTest.php b/tests/Unit/Factory/PiggyBankFactoryTest.php
index fb28535920..d207f1fd10 100644
--- a/tests/Unit/Factory/PiggyBankFactoryTest.php
+++ b/tests/Unit/Factory/PiggyBankFactoryTest.php
@@ -102,6 +102,6 @@ class PiggyBankFactoryTest extends TestCase
/** @var PiggyBankFactory $factory */
$factory = app(PiggyBankFactory::class);
$factory->setUser($this->user());
- $this->assertNull($factory->find(null, 'I dont exist.' . random_int(1, 10000)));
+ $this->assertNull($factory->find(null, 'I dont exist.' . $this->randomInt()));
}
}
diff --git a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php
index e9ff7381b4..ecfc95019a 100644
--- a/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php
+++ b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php
@@ -116,7 +116,7 @@ class AttachmentHelperTest extends TestCase
'attachable_id' => $journal->id,
'user_id' => $this->user()->id,
'attachable_type' => TransactionJournal::class,
- 'md5' => md5('Hello' . random_int(1, 10000)),
+ 'md5' => md5('Hello' . $this->randomInt()),
'filename' => 'file.txt',
'title' => 'Some title',
'description' => 'Some descr',
@@ -151,7 +151,7 @@ class AttachmentHelperTest extends TestCase
'attachable_id' => $journal->id,
'user_id' => $this->user()->id,
'attachable_type' => TransactionJournal::class,
- 'md5' => md5('Hello' . random_int(1, 10000)),
+ 'md5' => md5('Hello' . $this->randomInt()),
'filename' => 'file.txt',
'title' => 'Some title',
'description' => 'Some descr',
diff --git a/tests/Unit/Import/Routine/FileRoutineTest.php b/tests/Unit/Import/Routine/FileRoutineTest.php
index cdbbe245b3..d9eac4ad69 100644
--- a/tests/Unit/Import/Routine/FileRoutineTest.php
+++ b/tests/Unit/Import/Routine/FileRoutineTest.php
@@ -25,12 +25,13 @@ namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Import\Routine\BunqRoutine;
+use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Import\Routine\FileRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\File\CSVProcessor;
+use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
@@ -60,7 +61,7 @@ class FileRoutineTest extends TestCase
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
- $job->provider = 'bunq';
+ $job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
@@ -68,19 +69,27 @@ class FileRoutineTest extends TestCase
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageImportDataHandler::class);
+ $this->mock(AttachmentHelperInterface::class);
+ $csv = $this->mock(CSVProcessor::class);
+
+ $csv->shouldReceive('setImportJob')->atLeast()->once();
+ $csv->shouldReceive('run')->atLeast()->once();
- $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']);
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']);
- $repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
+ $repository->shouldReceive('getConfiguration')->atLeast()->once()->andReturn([]);
+ //$repository->shouldReceive('getAttachments')->atLeast()->once()->andReturn(new Collection);
+ $repository->shouldReceive('setTransactions')->atLeast()->once();
+ //$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
- $handler->shouldReceive('setImportJob')->once();
- $handler->shouldReceive('run')->once();
- $handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
+ //$handler->shouldReceive('setImportJob')->once();
+ //$handler->shouldReceive('run')->once();
+ //$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
$handler->shouldReceive('isStillRunning')->andReturn(false);
- $routine = new BunqRoutine;
+ $routine = new FileRoutine;
$routine->setImportJob($job);
try {
$routine->run();
diff --git a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php b/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
index 861f06754a..ceaf3ecb12 100644
--- a/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
+++ b/tests/Unit/Jobs/CreateRecurringTransactionsTest.php
@@ -80,12 +80,23 @@ class CreateRecurringTransactionsTest extends TestCase
/**
* Submit one, but offer no occurrences.
*
+ * TODO there is a random element in this test that breaks the test.
+ *
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingle(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
// mock classes
- $recurrence = $this->getRandomRecurrence();
+ $date = new Carbon;
+ $date->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->latest_date = null;
+ $recurrence->first_date = $date;
+ $recurrence->save();
+
+ Log::debug(sprintf('Test is going to use Recurrence #%d', $recurrence->id), $recurrence->toArray());
+
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
@@ -308,7 +319,14 @@ class CreateRecurringTransactionsTest extends TestCase
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
- $recurrence = $this->getRandomRecurrence();
+ // mock classes
+ $carbon = new Carbon;
+ $carbon->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->latest_date = null;
+ $recurrence->first_date = $carbon;
+ $recurrence->save();
+
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
@@ -359,11 +377,21 @@ class CreateRecurringTransactionsTest extends TestCase
*/
public function testForced(): void
{
+ Log::info(sprintf('Now in test %s.', __METHOD__));
Event::fake();
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
- $recurrence = $this->getRandomRecurrence();
+ // overrule some fields in the recurrence.
+ $carbon = new Carbon;
+ $carbon->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
+ $recurrence->latest_date = null;
+ $recurrence->first_date = $carbon;
+ $recurrence->save();
+
+
+
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
@@ -418,11 +446,12 @@ class CreateRecurringTransactionsTest extends TestCase
Event::fake();
$date = new Carbon();
- $recurrence = $this->getRandomRecurrence();
- $group = $this->getRandomWithdrawalGroup();
-
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
+ $carbon = new Carbon;
+ $carbon->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
+ $recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
@@ -459,11 +488,12 @@ class CreateRecurringTransactionsTest extends TestCase
$tomorrow = new Carbon();
$tomorrow->addDays(2);
- $recurrence = $this->getRandomRecurrence();
- $group = $this->getRandomWithdrawalGroup();
-
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
+ $carbon = new Carbon;
+ $carbon->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
+ $recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
@@ -503,12 +533,16 @@ class CreateRecurringTransactionsTest extends TestCase
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
- $recurrence = $this->getRandomRecurrence();
+
$group = $this->getRandomWithdrawalGroup();
$piggy = $this->getRandomPiggyBank();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
+ $carbon = new Carbon;
+ $carbon->subDays(4);
+ $recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = null;
+ $recurrence->first_date = $carbon;
$recurrence->save();
// mock classes
diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.php
index 5d4fca3fe6..99415f967b 100644
--- a/tests/Unit/Middleware/BinderTest.php
+++ b/tests/Unit/Middleware/BinderTest.php
@@ -1537,6 +1537,8 @@ class BinderTest extends TestCase
}
/**
+ * TODO there is a random element in this test that breaks the middleware.
+ *
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
*/
diff --git a/tests/Unit/Rules/BelongsUserTest.php b/tests/Unit/Rules/BelongsUserTest.php
new file mode 100644
index 0000000000..8b4e56839f
--- /dev/null
+++ b/tests/Unit/Rules/BelongsUserTest.php
@@ -0,0 +1,344 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Rules\BelongsUser;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class BelongsUserTest
+ */
+class BelongsUserTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBillId(): void
+ {
+ $attribute = 'bill_id';
+ $bill = $this->getRandomBill();
+ $value = $bill->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBillIdFalse(): void
+ {
+ $attribute = 'bill_id';
+ $value = '-1';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBillName(): void
+ {
+ $attribute = 'bill_name';
+ $bill = $this->getRandomBill();
+ $value = $bill->name;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBillNameFalse(): void
+ {
+ $attribute = 'bill_name';
+ $value = 'Some random name';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testAccountIdFalse(): void
+ {
+ $attribute = 'source_id';
+ $value = '-1';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testAccountId(): void
+ {
+ $attribute = 'destination_id';
+ $asset =$this->getRandomAsset();
+ $value = $asset->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBudgetId(): void
+ {
+ $attribute = 'budget_id';
+ $budget = $this->getRandomBudget();
+ $value = $budget->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBudgetIdFalse(): void
+ {
+ $attribute = 'budget_id';
+ $value = '-1';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBudgetName(): void
+ {
+ $attribute = 'budget_name';
+ $budget = $this->getRandomBudget();
+ $value = $budget->name;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testBudgetNameFalse(): void
+ {
+ $attribute = 'budget_name';
+ $value = 'Some random budget';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testCategoryId(): void
+ {
+ $attribute = 'category_id';
+ $category = $this->getRandomCategory();
+ $value = $category->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testCategoryIdFalse(): void
+ {
+ $attribute = 'category_id';
+ $value = '-1';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testPiggyBankId(): void
+ {
+ $attribute = 'piggy_bank_id';
+ $piggyBank = $this->getRandomPiggyBank();
+ $value = $piggyBank->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testPiggyBankIdFalse(): void
+ {
+ $attribute = 'piggy_bank_id';
+ $value = '-1';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testPiggyBankIdLongAttribute(): void
+ {
+ $attribute = 'a.b.piggy_bank_id';
+ $piggyBank = $this->getRandomPiggyBank();
+ $value = $piggyBank->id;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testPiggyBankName(): void
+ {
+ $attribute = 'piggy_bank_name';
+ $piggyBank = $this->getRandomPiggyBank();
+ $value = $piggyBank->name;
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertTrue($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\BelongsUser
+ */
+ public function testPiggyBankNameFalse(): void
+ {
+ $attribute = 'piggy_bank_name';
+ $value = 'Some random name';
+
+ $this->be($this->user());
+ $engine = new BelongsUser;
+ try {
+ $this->assertFalse($engine->passes($attribute, $value));
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Rules/IsAssetAccountIdTest.php b/tests/Unit/Rules/IsAssetAccountIdTest.php
new file mode 100644
index 0000000000..523bf7b635
--- /dev/null
+++ b/tests/Unit/Rules/IsAssetAccountIdTest.php
@@ -0,0 +1,83 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Rules\IsAssetAccountId;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class IsAssetAccountIdTest
+ */
+class IsAssetAccountIdTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsAssetAccountId
+ */
+ public function testNotAsset(): void
+ {
+ $attribute = 'not-used';
+ $expense = $this->getRandomExpense();
+ $value = $expense->id;
+
+ $engine = new IsAssetAccountId();
+ $this->assertFalse($engine->passes($attribute, $value));
+ }
+
+
+ /**
+ * @covers \FireflyIII\Rules\IsAssetAccountId
+ */
+ public function testAsset(): void
+ {
+ $attribute = 'not-used';
+ $asset = $this->getRandomAsset();
+ $value = $asset->id;
+
+ $engine = new IsAssetAccountId();
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsAssetAccountId
+ */
+ public function testNull(): void
+ {
+ $attribute = 'not-used';
+ $value = '-1';
+
+ $engine = new IsAssetAccountId();
+ $this->assertFalse($engine->passes($attribute, $value));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Rules/IsBooleanTest.php b/tests/Unit/Rules/IsBooleanTest.php
new file mode 100644
index 0000000000..d86004d2b0
--- /dev/null
+++ b/tests/Unit/Rules/IsBooleanTest.php
@@ -0,0 +1,78 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Rules\IsBoolean;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class IsBooleanTest
+ */
+class IsBooleanTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsBoolean
+ */
+ public function testFalse(): void
+ {
+ $attribute = 'not-important';
+
+ $false = ['not', 2, -1, []];
+
+ /** @var mixed $value */
+ foreach ($false as $value) {
+
+ $engine = new IsBoolean();
+ $this->assertFalse($engine->passes($attribute, $value));
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsBoolean
+ */
+ public function testTrue(): void
+ {
+ $attribute = 'not-important';
+
+ $true = [true, false, 0, 1, '0', '1', 'true', 'false', 'yes', 'no', 'on', 'off'];
+
+ /** @var mixed $value */
+ foreach ($true as $value) {
+
+ $engine = new IsBoolean();
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Rules/IsDateOrTimeTest.php b/tests/Unit/Rules/IsDateOrTimeTest.php
new file mode 100644
index 0000000000..b2bde0f594
--- /dev/null
+++ b/tests/Unit/Rules/IsDateOrTimeTest.php
@@ -0,0 +1,74 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Rules\IsDateOrTime;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class IsDateOrTimeTest
+ */
+class IsDateOrTimeTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsDateOrTime
+ */
+ public function testFalse(): void
+ {
+ $attribute = 'not-important';
+ $values = ['20xx-01-x','1234567890', '2xx0101', '', false];
+
+ /** @var mixed $value */
+ foreach ($values as $value) {
+ $engine = new IsDateOrTime();
+ $this->assertFalse($engine->passes($attribute, $value), $value);
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsDateOrTime
+ */
+ public function testTrue(): void
+ {
+ $attribute = 'not-important';
+ $values = ['2019-01-01', '20190101', '2019-01-01 12:12:12', '12:12:12'];
+
+ /** @var mixed $value */
+ foreach ($values as $value) {
+ $engine = new IsDateOrTime();
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Rules/IsValidAttachmentModelTest.php b/tests/Unit/Rules/IsValidAttachmentModelTest.php
new file mode 100644
index 0000000000..d686b19095
--- /dev/null
+++ b/tests/Unit/Rules/IsValidAttachmentModelTest.php
@@ -0,0 +1,164 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Models\Bill;
+use FireflyIII\Models\ImportJob;
+use FireflyIII\Models\Transaction;
+use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Bill\BillRepositoryInterface;
+use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Rules\IsValidAttachmentModel;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class IsValidAttachmentModelTest
+ */
+class IsValidAttachmentModelTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testBillFull(): void
+ {
+ $bill = $this->getRandomBill();
+ $billRepos = $this->mock(BillRepositoryInterface::class);
+
+ $billRepos->shouldReceive('setUser')->atLeast()->once();
+ $billRepos->shouldReceive('find')->atLeast()->once()->withArgs([$bill->id])->andReturn($bill);
+
+ $value = $bill->id;
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel(Bill::class);
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testImportJob(): void
+ {
+ $job = $this->getRandomImportJob();
+ $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
+
+ $jobRepos->shouldReceive('setUser')->atLeast()->once();
+ $jobRepos->shouldReceive('find')->atLeast()->once()->withArgs([$job->id])->andReturn($job);
+
+ $value = $job->id;
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel(ImportJob::class);
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testTransaction(): void
+ {
+ $transaction = $this->getRandomWithdrawal()->transactions()->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+
+ $journalRepos->shouldReceive('setUser')->atLeast()->once();
+ $journalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
+
+ $value = $transaction->id;
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel(Transaction::class);
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testTransactionJournal(): void
+ {
+ $journal = $this->getRandomWithdrawal();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+
+ $journalRepos->shouldReceive('setUser')->atLeast()->once();
+ $journalRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$journal->id])->andReturn($journal);
+
+ $value = $journal->id;
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel(TransactionJournal::class);
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testBadModel(): void
+ {
+ $value = '123';
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel('False');
+ $this->assertFalse($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testBillPartial(): void
+ {
+ $bill = $this->getRandomBill();
+ $billRepos = $this->mock(BillRepositoryInterface::class);
+
+ $billRepos->shouldReceive('setUser')->atLeast()->once();
+ $billRepos->shouldReceive('find')->atLeast()->once()->withAnyArgs([$bill->id])->andReturn($bill);
+
+ $value = $bill->id;
+ $attribute = 'not-important';
+ $this->be($this->user());
+ $engine = new IsValidAttachmentModel('Bill');
+ $this->assertTrue($engine->passes($attribute, $value));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\IsValidAttachmentModel
+ */
+ public function testNotLoggedIn(): void
+ {
+ $value = '1';
+ $attribute = 'not-important';
+ $engine = new IsValidAttachmentModel(Bill::class);
+ $this->assertFalse($engine->passes($attribute, $value));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Rules/UniqueIbanTest.php b/tests/Unit/Rules/UniqueIbanTest.php
new file mode 100644
index 0000000000..97e09431b2
--- /dev/null
+++ b/tests/Unit/Rules/UniqueIbanTest.php
@@ -0,0 +1,150 @@
+.
+ */
+
+namespace Tests\Unit\Rules;
+
+
+use FireflyIII\Rules\UniqueIban;
+use Log;
+use Tests\TestCase;
+
+/**
+ * Class UniqueIbanTest
+ */
+class UniqueIbanTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\UniqueIban
+ */
+ public function testBasic(): void
+ {
+ $asset = $this->getRandomAsset();
+ $iban = $asset->iban;
+ $asset->iban = 'NL123';
+ $asset->save();
+
+ $this->be($this->user());
+
+ $engine = new UniqueIban(null, 'asset');
+ $this->assertFalse($engine->passes('not-important', $asset->iban));
+
+ $asset->iban = $iban;
+ $asset->save();
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\UniqueIban
+ */
+ public function testBasicSkipExisting(): void
+ {
+ $asset = $this->getRandomAsset();
+ $iban = $asset->iban;
+ $asset->iban = 'NL123';
+ $asset->save();
+
+ $this->be($this->user());
+
+ $engine = new UniqueIban($asset, 'asset');
+ $this->assertTrue($engine->passes('not-important', $asset->iban));
+
+ $asset->iban = $iban;
+ $asset->save();
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\UniqueIban
+ */
+ public function testRevenue(): void
+ {
+ // give revenue account new IBAN.
+ // should be OK to give it to an expense account
+ $revenue = $this->getRandomRevenue();
+ $iban = $revenue->iban;
+ $revenue->iban = 'NL123';
+ $revenue->save();
+
+ $this->be($this->user());
+
+ // returns true because this mix is OK.
+ $engine = new UniqueIban(null, 'expense');
+ $this->assertTrue($engine->passes('not-important', 'NL123'));
+
+
+ $revenue->iban = $iban;
+ $revenue->save();
+ }
+
+
+ /**
+ * @covers \FireflyIII\Rules\UniqueIban
+ */
+ public function testExpense(): void
+ {
+ // give expense account new IBAN.
+ // should be OK to give it to an expense account
+ $expense = $this->getRandomExpense();
+ $iban = $expense->iban;
+ $expense->iban = 'NL123';
+ $expense->save();
+
+ $this->be($this->user());
+
+ // returns true because this mix is OK.
+ $engine = new UniqueIban(null, 'revenue');
+ $this->assertTrue($engine->passes('not-important', 'NL123'));
+
+ $expense->iban = $iban;
+ $expense->save();
+ }
+
+ /**
+ * @covers \FireflyIII\Rules\UniqueIban
+ */
+ public function testRevenueAsset(): void
+ {
+ // give revenue account new IBAN.
+ // should be OK to give it to an expense account
+ $revenue = $this->getRandomRevenue();
+ $iban = $revenue->iban;
+ $revenue->iban = 'NL123';
+ $revenue->save();
+
+ $this->be($this->user());
+
+ // returns false because this mix is not OK.
+ $engine = new UniqueIban(null, 'asset');
+ $this->assertFalse($engine->passes('not-important', 'NL123'));
+
+
+ $revenue->iban = $iban;
+ $revenue->save();
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php b/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php
index 6f875bc053..06b9d8c345 100644
--- a/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php
+++ b/tests/Unit/Services/Internal/Destroy/AccountDestroyServiceTest.php
@@ -24,9 +24,11 @@ declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Destroy;
use FireflyIII\Models\Account;
+use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Transaction;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
+use FireflyIII\Services\Internal\Destroy\RecurrenceDestroyService;
use Log;
use Tests\TestCase;
@@ -49,8 +51,9 @@ class AccountDestroyServiceTest extends TestCase
*/
public function testDestroyBasic(): void
{
+ $this->mock(RecurrenceDestroyService::class);
$account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
/** @var AccountDestroyService $service */
@@ -60,14 +63,51 @@ class AccountDestroyServiceTest extends TestCase
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
}
+
+ /**
+ * @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
+ */
+ public function testDestroyWithRecurrence(): void
+ {
+ $recService = $this->mock(RecurrenceDestroyService::class);
+ $account = Account::create(
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
+ 'virtual_balance' => '0', 'iban' => null, 'active' => true]
+ );
+
+ $recurrence = $this->getRandomRecurrence();
+ $recurrenceTransaction = RecurrenceTransaction::create(
+ [
+ 'recurrence_id' => $recurrence->id,
+ 'transaction_currency_id' => $this->getEuro()->id,
+ 'source_id' => $account->id,
+ 'destination_id' => $account->id,
+ 'amount' => 10,
+ 'description' => 'Hello',
+ ]
+ );
+
+ $recService->shouldReceive('destroyById')->once()
+ ->withAnyArgs([$recurrenceTransaction->id]);
+
+ /** @var AccountDestroyService $service */
+ $service = app(AccountDestroyService::class);
+ $service->destroy($account, null);
+
+ $this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
+
+ $recurrenceTransaction->forceDelete();
+ }
+
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyDontMove(): void
{
+ $this->mock(RecurrenceDestroyService::class);
// create objects:
$account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
@@ -88,12 +128,13 @@ class AccountDestroyServiceTest extends TestCase
*/
public function testDestroyMove(): void
{
+ $this->mock(RecurrenceDestroyService::class);
$account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$move = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$transaction = Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
diff --git a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php
index b2bf7ef670..65fff25a90 100644
--- a/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php
+++ b/tests/Unit/Services/Internal/Update/AccountUpdateServiceTest.php
@@ -29,7 +29,9 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
+use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use Log;
use Tests\TestCase;
@@ -54,36 +56,22 @@ class AccountUpdateServiceTest extends TestCase
*/
public function testDeleteExistingIB(): void
{
- /** @var Account $account */
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $opposing = $this->user()->accounts()->first();
- $journal = TransactionJournal::create(
- ['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
- 'date' => '2018-01-01', 'completed' => true, 'tag_count' => 0,
- ]
- );
- // transactions:
- Transaction::create(
- ['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
- );
- Transaction::create(
- ['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
- );
-
+ $group = $this->getRandomWithdrawalGroup();
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $destroySerice = $this->mock(TransactionGroupDestroyService::class);
+ $accountRepos->shouldReceive('setUser')->atLeast()->once();
+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);
+ $destroySerice->shouldReceive('destroy')->atLeast()->once();
+ $account = $this->getRandomAsset();
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'notes' => 'Hello',
- 'currency_id' => 1,
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
+ 'notes' => 'Hello',
+ 'currency_id' => 1,
];
/** @var AccountUpdateService $service */
@@ -91,7 +79,6 @@ class AccountUpdateServiceTest extends TestCase
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
- $this->assertEquals(0, $account->transactions()->count());
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
@@ -106,11 +93,11 @@ class AccountUpdateServiceTest extends TestCase
/** @var Account $account */
$account = $this->user()->accounts()->first();
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
];
/** @var AccountUpdateService $service */
@@ -129,12 +116,12 @@ class AccountUpdateServiceTest extends TestCase
/** @var Account $account */
$account = $this->user()->accounts()->first();
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'notes' => '',
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
+ 'notes' => '',
];
/** @var AccountUpdateService $service */
@@ -159,12 +146,12 @@ class AccountUpdateServiceTest extends TestCase
$note->save();
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'notes' => '',
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
+ 'notes' => '',
];
/** @var AccountUpdateService $service */
@@ -182,38 +169,27 @@ class AccountUpdateServiceTest extends TestCase
*/
public function testUpdateExistingIB(): void
{
- /** @var Account $account */
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $opposing = $this->user()->accounts()->first();
- $journal = TransactionJournal::create(
- ['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
- 'date' => '2018-01-01', 'completed' => true, 'tag_count' => 0,
- ]
- );
- // transactions:
- Transaction::create(
- ['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
- );
- Transaction::create(
- ['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
- 'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
- );
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $destroySerice = $this->mock(TransactionGroupDestroyService::class);
+ $group = $this->getRandomWithdrawalGroup();
+
+ // make sure one transaction has the account as the asset.
+ $journal = $group->transactionJournals()->first();
+ $account = $journal->transactions()->first()->account;
+ $accountRepos->shouldReceive('setUser')->atLeast()->once();
+ $accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn($group);
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'openingBalance' => '105',
- 'openingBalanceDate' => new Carbon('2018-01-01'),
- 'notes' => 'Hello',
- 'currency_id' => 1,
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
+ 'opening_balance' => '105',
+ 'opening_balance_date' => new Carbon('2018-01-01'),
+ 'notes' => 'Hello',
+ 'currency_id' => 1,
];
/** @var AccountUpdateService $service */
@@ -221,8 +197,6 @@ class AccountUpdateServiceTest extends TestCase
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
- $this->assertEquals(1, $account->transactions()->count());
- $this->assertEquals(105, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
@@ -234,12 +208,13 @@ class AccountUpdateServiceTest extends TestCase
*/
public function testUpdateExistingIBZero(): void
{
+
$deleteService = $this->mock(JournalDestroyService::class);
- $deleteService->shouldReceive('destroy')->once();
+ //$deleteService->shouldReceive('destroy')->once();
/** @var Account $account */
$account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
+ ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . $this->randomInt(),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
@@ -260,53 +235,15 @@ class AccountUpdateServiceTest extends TestCase
$data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'openingBalance' => '0',
- 'openingBalanceDate' => new Carbon('2018-01-01'),
- 'notes' => 'Hello',
- 'currency_id' => 1,
- ];
-
- /** @var AccountUpdateService $service */
- $service = app(AccountUpdateService::class);
- $account = $service->update($account, $data);
-
- $this->assertEquals($data['name'], $account->name);
- $this->assertEquals(1, $account->transactions()->count());
- $this->assertEquals(100, $account->transactions()->first()->amount);
- /** @var Note $note */
- $note = $account->notes()->first();
- $this->assertEquals($data['notes'], $note->text);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
- * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
- */
- public function testUpdateNewIB(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- /** @var Account $account */
- $account = Account::create(
- ['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . random_int(1, 10000),
- 'virtual_balance' => '0', 'iban' => null, 'active' => true]
- );
- $data = [
- 'name' => 'Some new name #' . random_int(1, 10000),
- 'active' => true,
- 'virtualBalance' => '0',
- 'iban' => null,
- 'accountRole' => 'defaultAsset',
- 'openingBalance' => '100',
- 'openingBalanceDate' => new Carbon('2018-01-01'),
- 'notes' => 'Hello',
- 'currency_id' => 1,
+ 'name' => 'Some new name #' . $this->randomInt(),
+ 'active' => true,
+ 'virtual_balance' => '0',
+ 'iban' => null,
+ 'account_role' => 'defaultAsset',
+ 'opening_balance' => '0',
+ 'opening_balance_date' => new Carbon('2018-01-01'),
+ 'notes' => 'Hello',
+ 'currency_id' => 1,
];
/** @var AccountUpdateService $service */
diff --git a/tests/Unit/Services/Internal/Update/JournalUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/JournalUpdateServiceTest.php
deleted file mode 100644
index a704832f3d..0000000000
--- a/tests/Unit/Services/Internal/Update/JournalUpdateServiceTest.php
+++ /dev/null
@@ -1,242 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Services\Internal\Update;
-
-
-use Carbon\Carbon;
-use FireflyIII\Factory\BillFactory;
-use FireflyIII\Factory\TagFactory;
-use FireflyIII\Factory\TransactionFactory;
-use FireflyIII\Factory\TransactionJournalMetaFactory;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Services\Internal\Update\JournalUpdateService;
-use FireflyIII\Services\Internal\Update\TransactionUpdateService;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class JournalUpdateServiceTest
- */
-class JournalUpdateServiceTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testUpdateBasic(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- // mock other stuff:
- $transactionFactory = $this->mock(TransactionFactory::class);
- $transactionService = $this->mock(TransactionUpdateService::class);
- $billFactory = $this->mock(BillFactory::class);
- $tagFactory = $this->mock(TagFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
-
- // mock calls
- $billFactory->shouldReceive('setUser');
- $billFactory->shouldReceive('find')->andReturn(null);
- $transactionService->shouldReceive('setUser');
- $transactionFactory->shouldReceive('setUser');
- $tagFactory->shouldReceive('setUser');
- $metaFactory->shouldReceive('setUser');
-
- $metaFactory->shouldReceive('updateOrCreate');
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
- $data = [
- 'description' => 'Updated journal #' . random_int(1, 10000),
- 'date' => new Carbon('2018-01-01'),
- 'bill_id' => null,
- 'bill_name' => null,
- 'tags' => [],
- 'notes' => 'Hello',
- 'transactions' => [],
- ];
-
- /** @var JournalUpdateService $service */
- $service = app(JournalUpdateService::class);
- $result = $service->update($journal, $data);
-
- $this->assertEquals($data['description'], $result->description);
- $this->assertEquals(0, $result->transactions()->count());
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testUpdateBasicEmptyNote(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- // mock other stuff:
- $transactionFactory = $this->mock(TransactionFactory::class);
- $transactionService = $this->mock(TransactionUpdateService::class);
- $billFactory = $this->mock(BillFactory::class);
- $tagFactory = $this->mock(TagFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
-
- // mock calls
- $billFactory->shouldReceive('setUser');
- $billFactory->shouldReceive('find')->andReturn(null);
- $transactionService->shouldReceive('setUser');
- $transactionFactory->shouldReceive('setUser');
- $tagFactory->shouldReceive('setUser');
- $metaFactory->shouldReceive('setUser');
- $metaFactory->shouldReceive('updateOrCreate');
-
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->first();
- $data = [
- 'description' => 'Updated journal #' . random_int(1, 10000),
- 'date' => new Carbon('2018-01-01'),
- 'bill_id' => null,
- 'bill_name' => null,
- 'tags' => [],
- 'notes' => '',
- 'transactions' => [],
- ];
-
- /** @var JournalUpdateService $service */
- $service = app(JournalUpdateService::class);
- $result = $service->update($journal, $data);
-
- $this->assertEquals($data['description'], $result->description);
- $this->assertEquals(0, $result->transactions()->count());
- $this->assertEquals(0, $result->notes()->count());
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
- */
- public function testUpdateBudget(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- $budget = $this->user()->budgets()->first();
- $service = $this->mock(TransactionUpdateService::class);
- $service->shouldReceive('setUser');
- $service->shouldReceive('updateBudget')->withArgs([Mockery::any(), $budget->id])->twice();
-
- $withdrawal = $this->getRandomWithdrawal();
-
- // call update service to update budget. Should call transaction service twice.
- /** @var JournalUpdateService $service */
- $service = app(JournalUpdateService::class);
- $service->updateBudget($withdrawal, $budget->id);
- }
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
- */
- public function testUpdateCategory(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- $service = $this->mock(TransactionUpdateService::class);
- $service->shouldReceive('setUser');
- $service->shouldReceive('updateCategory')->withArgs([Mockery::any(), 'New category'])->twice();
-
-
- $withdrawal = $this->getRandomWithdrawal();
-
- // call update service to update budget. Should call transaction service twice.
- /** @var JournalUpdateService $service */
- $service = app(JournalUpdateService::class);
- $service->updateCategory($withdrawal, 'New category');
- }
-
-
- /**
- * @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
- * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
- */
- public function testUpdateLotsOfTransactions(): void
- {
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- // mock other stuff:
- $transactionFactory = $this->mock(TransactionFactory::class);
- $transactionService = $this->mock(TransactionUpdateService::class);
- $billFactory = $this->mock(BillFactory::class);
- $tagFactory = $this->mock(TagFactory::class);
- $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
-
-
- // mock calls
- $billFactory->shouldReceive('setUser');
- $billFactory->shouldReceive('find')->andReturn(null);
- $transactionService->shouldReceive('setUser');
- $transactionFactory->shouldReceive('setUser');
- $transactionService->shouldReceive('update')->times(2);
- $transactionFactory->shouldReceive('createPair')->times(2);
- $tagFactory->shouldReceive('setUser');
- $metaFactory->shouldReceive('setUser');
- $metaFactory->shouldReceive('updateOrCreate');
-
-
- /** @var TransactionJournal $journal */
- $journal = $this->user()->transactionJournals()->skip(4)->where('transaction_type_id', 1)->first();
- $data = [
- 'description' => 'Updated journal #' . random_int(1, 10000),
- 'date' => new Carbon('2018-01-01'),
- 'bill_id' => null,
- 'bill_name' => null,
- 'tags' => [],
- 'notes' => 'Hello',
- 'transactions' => [
- ['identifier' => 0],
- ['identifier' => 1],
- ['identifier' => 2],
- ],
- ];
-
- /** @var JournalUpdateService $service */
- $service = app(JournalUpdateService::class);
- $result = $service->update($journal, $data);
-
- $this->assertEquals($data['description'], $result->description);
- $this->assertEquals(2, $result->transactions()->count());
- }
-
-}
diff --git a/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php
deleted file mode 100644
index 67932a3480..0000000000
--- a/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php
+++ /dev/null
@@ -1,265 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Services\Internal\Update;
-
-
-use FireflyIII\Factory\BudgetFactory;
-use FireflyIII\Factory\CategoryFactory;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Services\Internal\Update\TransactionUpdateService;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class TransactionUpdateServiceTest
- */
-class TransactionUpdateServiceTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// */
-// public function testReconcile(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// $transaction = $this->user()->transactions()->inRandomOrder()->first();
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->reconcile($transaction->id);
-// $this->assertEquals($result->id, $transaction->id);
-// $this->assertEquals(true, $result->reconciled);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testReconcileNull(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->reconcile(-1);
-// $this->assertNull($result);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testUpdateBudget(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var Transaction $source */
-// $source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-// $budget = $this->user()->budgets()->inRandomOrder()->first();
-//
-// $factory = $this->mock(BudgetFactory::class);
-// $factory->shouldReceive('setUser');
-// $factory->shouldReceive('find')->andReturn($budget);
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->updateBudget($source, $budget->id);
-//
-// $this->assertEquals(1, $result->budgets()->count());
-// $this->assertEquals($budget->name, $result->budgets()->first()->name);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testUpdateCategory(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var Transaction $source */
-// $source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-// $category = $this->user()->categories()->inRandomOrder()->first();
-//
-// $factory = $this->mock(CategoryFactory::class);
-// $factory->shouldReceive('setUser');
-// $factory->shouldReceive('findOrCreate')->andReturn($category);
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->updateCategory($source, $category->name);
-//
-// $this->assertEquals(1, $result->categories()->count());
-// $this->assertEquals($category->name, $result->categories()->first()->name);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testUpdateDestinationBasic(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var Transaction $source */
-// $source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-// $data = [
-// 'currency_id' => 1,
-// 'currency_code' => null,
-// 'description' => 'Some new description',
-// 'reconciled' => false,
-// 'foreign_amount' => null,
-// 'budget_id' => null,
-// 'budget_name' => null,
-// 'destination_id' => (int)$source->account_id,
-// 'destination_name' => null,
-// 'category_id' => null,
-// 'category_name' => null,
-// 'amount' => $source->amount,
-// 'foreign_currency_id' => null,
-// 'foreign_currency_code' => null,
-// ];
-//
-// // mock repository:
-// $accountRepos = $this->mock(AccountRepositoryInterface::class);
-// $accountRepos->shouldReceive('setUser');
-// $accountRepos->shouldReceive('findNull')->andReturn($source->account);
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->update($source, $data);
-//
-// $this->assertEquals($source->id, $result->id);
-// $this->assertEquals($result->description, $data['description']);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testUpdateDestinationForeign(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var Transaction $source */
-// $source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-// $data = [
-// 'currency_id' => 1,
-// 'currency_code' => null,
-// 'description' => 'Some new description',
-// 'reconciled' => false,
-// 'foreign_amount' => '12.34',
-// 'budget_id' => null,
-// 'budget_name' => null,
-// 'destination_id' => (int)$source->account_id,
-// 'destination_name' => null,
-// 'category_id' => null,
-// 'category_name' => null,
-// 'amount' => $source->amount,
-// 'foreign_currency_id' => 2,
-// 'foreign_currency_code' => null,
-// ];
-//
-// // mock repository:
-// $accountRepos = $this->mock(AccountRepositoryInterface::class);
-// $accountRepos->shouldReceive('setUser');
-// $accountRepos->shouldReceive('findNull')->andReturn($source->account);
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->update($source, $data);
-//
-//
-// $this->assertEquals($source->id, $result->id);
-// $this->assertEquals($result->description, $data['description']);
-// $this->assertEquals($data['foreign_amount'], $result->foreign_amount);
-// $this->assertEquals($data['foreign_currency_id'], $result->foreign_currency_id);
-// }
-//
-// /**
-// * @covers \FireflyIII\Services\Internal\Update\TransactionUpdateService
-// * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
-// */
-// public function testUpdateSourceBasic(): void
-// {
-// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-//
-// return;
-// /** @var Transaction $source */
-// $source = $this->user()->transactions()->where('amount', '<', 0)->inRandomOrder()->first();
-// $data = [
-// 'currency_id' => 1,
-// 'currency_code' => null,
-// 'description' => 'Some new description',
-// 'reconciled' => false,
-// 'foreign_amount' => null,
-// 'budget_id' => null,
-// 'budget_name' => null,
-// 'source_id' => (int)$source->account_id,
-// 'source_name' => null,
-// 'category_id' => null,
-// 'category_name' => null,
-// 'amount' => $source->amount,
-// 'foreign_currency_id' => null,
-// 'foreign_currency_code' => null,
-// ];
-//
-// // mock repository:
-// $accountRepos = $this->mock(AccountRepositoryInterface::class);
-// $accountRepos->shouldReceive('setUser');
-// $accountRepos->shouldReceive('findNull')->andReturn($source->account);
-//
-// /** @var TransactionUpdateService $service */
-// $service = app(TransactionUpdateService::class);
-// $service->setUser($this->user());
-// $result = $service->update($source, $data);
-//
-// $this->assertEquals($source->id, $result->id);
-// $this->assertEquals($result->description, $data['description']);
-//
-//
-// }
-}
diff --git a/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php b/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php
new file mode 100644
index 0000000000..10cccc2ac6
--- /dev/null
+++ b/tests/Unit/Support/Cronjobs/RecurringCronjobTest.php
@@ -0,0 +1,142 @@
+.
+ */
+
+namespace Tests\Unit\Support\Cronjobs;
+
+
+use Carbon\Carbon;
+use FireflyConfig;
+use FireflyIII\Jobs\CreateRecurringTransactions;
+use FireflyIII\Models\Configuration;
+use FireflyIII\Support\Cronjobs\RecurringCronjob;
+use Log;
+use Mockery;
+use Tests\TestCase;
+
+/**
+ * Class RecurringCronjobTest
+ */
+class RecurringCronjobTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::info(sprintf('Now in %s.', get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
+ */
+ public function testBasic(): void
+ {
+ $class = $this->mock(CreateRecurringTransactions::class);
+ $force = false;
+ $date = new Carbon;
+ $config = new Configuration;
+ $config->data = 0;
+ FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
+
+ $class->shouldReceive('setDate')->atleast()->once();
+ $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
+ $class->shouldReceive('handle')->atleast()->once();
+
+ FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
+
+ $job = new RecurringCronjob;
+ $job->setDate($date);
+ $job->setForce($force);
+ $job->fire();
+ }
+
+ /**
+ * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
+ */
+ public function testShort(): void
+ {
+ $this->mock(CreateRecurringTransactions::class);
+ $force = false;
+ $date = new Carbon;
+ $time = time() - 100;
+ $config = new Configuration;
+ $config->data = $time;
+
+ FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
+
+ $job = new RecurringCronjob;
+ $job->setDate($date);
+ $job->setForce($force);
+ $job->fire();
+ }
+
+ /**
+ * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
+ */
+ public function testShortForced(): void
+ {
+ $class = $this->mock(CreateRecurringTransactions::class);
+ $force = true;
+ $date = new Carbon;
+ $time = time() - 100;
+ $config = new Configuration;
+ $config->data = $time;
+ FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
+
+ $class->shouldReceive('setDate')->atleast()->once();
+ $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
+ $class->shouldReceive('handle')->atleast()->once();
+
+ FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
+
+ $job = new RecurringCronjob;
+ $job->setDate($date);
+ $job->setForce($force);
+ $job->fire();
+ }
+
+ /**
+ * @covers \FireflyIII\Support\Cronjobs\RecurringCronjob
+ */
+ public function testTwoDays(): void
+ {
+ $class = $this->mock(CreateRecurringTransactions::class);
+ $force = false;
+ $date = new Carbon;
+ $time = time() - 43300;
+ $config = new Configuration;
+ $config->data = $time;
+ FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->atLeast()->once()->andReturn($config);
+
+ $class->shouldReceive('setDate')->atleast()->once();
+ $class->shouldReceive('setForce')->atleast()->once()->withArgs([$force]);
+ $class->shouldReceive('handle')->atleast()->once();
+
+ FireflyConfig::shouldReceive('set')->atLeast()->once()->withArgs(['last_rt_job', Mockery::any()]);
+
+ $job = new RecurringCronjob;
+ $job->setDate($date);
+ $job->setForce($force);
+ $job->fire();
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
index 6395e5ef31..f3c935f22e 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
@@ -60,7 +60,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'caha' . random_int(1, 10000);
+ $job->key = 'caha' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -91,7 +91,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahb' . random_int(1, 10000);
+ $job->key = 'cahb' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -124,7 +124,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahc' . random_int(1, 10000);
+ $job->key = 'cahc' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -179,7 +179,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahd' . random_int(1, 10000);
+ $job->key = 'cahd' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -234,7 +234,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahe' . random_int(1, 10000);
+ $job->key = 'cahe' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -289,7 +289,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahf' . random_int(1, 10000);
+ $job->key = 'cahf' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -335,7 +335,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahg' . random_int(1, 10000);
+ $job->key = 'cahg' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -398,7 +398,7 @@ class ChooseAccountsHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cahg' . random_int(1, 10000);
+ $job->key = 'cahg' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php
index 3061ae9bd3..3e8fa4bf8d 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php
@@ -51,7 +51,7 @@ class NewBunqJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'cXha' . random_int(1, 10000);
+ $job->key = 'cXha' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php
index dd0c3e622e..feec1aa1d0 100644
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php
@@ -63,7 +63,7 @@ class ConfigureMappingHandlerTest extends TestCase
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapG' . random_int(1, 10000);
+ $job->key = 'mapG' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -131,7 +131,7 @@ class ConfigureMappingHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapA' . random_int(1, 10000);
+ $job->key = 'mapA' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -165,7 +165,7 @@ class ConfigureMappingHandlerTest extends TestCase
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapE' . random_int(1, 10000);
+ $job->key = 'mapE' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -230,7 +230,7 @@ class ConfigureMappingHandlerTest extends TestCase
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapC' . random_int(1, 10000);
+ $job->key = 'mapC' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -260,7 +260,7 @@ class ConfigureMappingHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapH' . random_int(1, 10000);
+ $job->key = 'mapH' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -343,7 +343,7 @@ class ConfigureMappingHandlerTest extends TestCase
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapD' . random_int(1, 10000);
+ $job->key = 'mapD' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -372,7 +372,7 @@ class ConfigureMappingHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapF' . random_int(1, 10000);
+ $job->key = 'mapF' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -461,7 +461,7 @@ class ConfigureMappingHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapB' . random_int(1, 10000);
+ $job->key = 'mapB' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -491,7 +491,7 @@ class ConfigureMappingHandlerTest extends TestCase
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'mapB' . random_int(1, 10000);
+ $job->key = 'mapB' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php
index bee2a58f04..f753ddb0a3 100644
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php
@@ -134,7 +134,7 @@ class ConfigureRolesHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'role-B' . random_int(1, 10000);
+ $job->key = 'role-B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -215,7 +215,7 @@ class ConfigureRolesHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'role-x' . random_int(1, 10000);
+ $job->key = 'role-x' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -297,7 +297,7 @@ class ConfigureRolesHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'role-x' . random_int(1, 10000);
+ $job->key = 'role-x' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -368,7 +368,7 @@ class ConfigureRolesHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'role-x' . random_int(1, 10000);
+ $job->key = 'role-x' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -543,7 +543,7 @@ class ConfigureRolesHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'role-A' . random_int(1, 10000);
+ $job->key = 'role-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php
index 1e0683fbdc..d2e7fd5c5b 100644
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php
@@ -53,7 +53,7 @@ class ConfigureUploadHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'upload-B' . random_int(1, 10000);
+ $job->key = 'upload-B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -102,7 +102,7 @@ class ConfigureUploadHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'upload-B' . random_int(1, 10000);
+ $job->key = 'upload-B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -150,7 +150,7 @@ class ConfigureUploadHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'upload-A' . random_int(1, 10000);
+ $job->key = 'upload-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php
index 1dc92a2481..c6e0b771fe 100644
--- a/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php
@@ -56,7 +56,7 @@ class NewFileJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . random_int(1, 10000);
+ $job->key = 'newfile-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -111,7 +111,7 @@ class NewFileJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . random_int(1, 10000);
+ $job->key = 'newfile-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -169,7 +169,7 @@ class NewFileJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . random_int(1, 10000);
+ $job->key = 'newfile-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -216,7 +216,7 @@ class NewFileJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'newfile-x' . random_int(1, 10000);
+ $job->key = 'newfile-x' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
@@ -264,7 +264,7 @@ class NewFileJobHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'newfile-x' . random_int(1, 10000);
+ $job->key = 'newfile-x' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php
index 0956c5175a..3b304e9af5 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php
@@ -64,7 +64,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-A' . random_int(1, 10000);
+ $job->key = 'sca-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -99,7 +99,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-B' . random_int(1, 10000);
+ $job->key = 'sca-B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -138,7 +138,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-c' . random_int(1, 10000);
+ $job->key = 'sca-c' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -197,7 +197,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-E' . random_int(1, 10000);
+ $job->key = 'sca-E' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -256,7 +256,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-D' . random_int(1, 10000);
+ $job->key = 'sca-D' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -313,7 +313,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-E' . random_int(1, 10000);
+ $job->key = 'sca-E' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -443,7 +443,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-F' . random_int(1, 10000);
+ $job->key = 'sca-F' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -596,7 +596,7 @@ class ChooseAccountsHandlerTest extends TestCase
// fake job:
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sca-F' . random_int(1, 10000);
+ $job->key = 'sca-F' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php
index e9edcceb98..53cb425b43 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php
@@ -62,7 +62,7 @@ class ChooseLoginHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'slh-A' . random_int(1, 10000);
+ $job->key = 'slh-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -85,7 +85,7 @@ class ChooseLoginHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'slh-B' . random_int(1, 10000);
+ $job->key = 'slh-B' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -109,7 +109,7 @@ class ChooseLoginHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'slh-C' . random_int(1, 10000);
+ $job->key = 'slh-C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -149,7 +149,7 @@ class ChooseLoginHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'slh-C' . random_int(1, 10000);
+ $job->key = 'slh-C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -269,7 +269,7 @@ class ChooseLoginHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'slh-C' . random_int(1, 10000);
+ $job->key = 'slh-C' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php
index aafdb09240..7121e50f33 100644
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php
+++ b/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php
@@ -62,7 +62,7 @@ class DoAuthenticateHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sda-A' . random_int(1, 10000);
+ $job->key = 'sda-A' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php
index 38cb2c24f1..4d70f988f8 100644
--- a/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php
@@ -67,7 +67,7 @@ class StageImportDataHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sidh_bbunq_' . random_int(1, 10000);
+ $job->key = 'sidh_bbunq_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -117,7 +117,7 @@ class StageImportDataHandlerTest extends TestCase
$payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
$payment->setAmount($amount);
$payment->setCounterpartyAlias($labelMonetaryAccount);
- $payment->setDescription('Random description #' . random_int(1, 10000));
+ $payment->setDescription('Random description #' . $this->randomInt());
$value = [$payment];
$list = new BunqResponsePaymentList($value, [], null);
@@ -216,7 +216,7 @@ class StageImportDataHandlerTest extends TestCase
// {
// $job = new ImportJob;
// $job->user_id = $this->user()->id;
- // $job->key = 'sidA_bbunq_' . random_int(1, 10000);
+ // $job->key = 'sidA_bbunq_' . $this->randomInt();
// $job->status = 'new';
// $job->stage = 'new';
// $job->provider = 'bunq';
@@ -290,7 +290,7 @@ class StageImportDataHandlerTest extends TestCase
// {
// $job = new ImportJob;
// $job->user_id = $this->user()->id;
- // $job->key = 'sidh_bbunq_' . random_int(1, 10000);
+ // $job->key = 'sidh_bbunq_' . $this->randomInt();
// $job->status = 'new';
// $job->stage = 'new';
// $job->provider = 'bunq';
@@ -344,7 +344,7 @@ class StageImportDataHandlerTest extends TestCase
//
// $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
// $payment->setAmount($amount);
- // $payment->setDescription('Some random thing #' . random_int(1, 10000));
+ // $payment->setDescription('Some random thing #' . $this->randomInt());
// $payment->setCounterpartyAlias($labelMonetaryAccount);
// $value = [$payment];
// $list = new BunqResponsePaymentList($value, [], null);
@@ -427,7 +427,7 @@ class StageImportDataHandlerTest extends TestCase
// {
// $job = new ImportJob;
// $job->user_id = $this->user()->id;
- // $job->key = 'sidh_bbunq_' . random_int(1, 10000);
+ // $job->key = 'sidh_bbunq_' . $this->randomInt();
// $job->status = 'new';
// $job->stage = 'new';
// $job->provider = 'bunq';
@@ -477,7 +477,7 @@ class StageImportDataHandlerTest extends TestCase
// $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
// $payment->setAmount($amount);
// $payment->setCounterpartyAlias($labelMonetaryAccount);
- // $payment->setDescription('Random transfer #' . random_int(1, 10000));
+ // $payment->setDescription('Random transfer #' . $this->randomInt());
// $value = [$payment];
// $list = new BunqResponsePaymentList($value, [], null);
//
diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
index b94f4c5b00..57c688f3ed 100644
--- a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
@@ -67,7 +67,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'snh_bunq_' . random_int(1, 10000);
+ $job->key = 'snh_bunq_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -154,7 +154,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'snha_bunq_' . random_int(1, 10000);
+ $job->key = 'snha_bunq_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
@@ -246,7 +246,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'snh_bbunq_' . random_int(1, 10000);
+ $job->key = 'snh_bbunq_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'bunq';
diff --git a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php b/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
index 9be4f3c9d1..20bc586cda 100644
--- a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
+++ b/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
@@ -87,8 +87,8 @@ class ImportableConverterTest extends TestCase
$accountRepos->shouldReceive('setUser')->once();
// get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
+ $euro = $this->getEuro();
+ $usd = $this->getDollar();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
// set user and config:
@@ -113,9 +113,9 @@ class ImportableConverterTest extends TestCase
$result = $converter->convert($importables);
// verify content of $result
- $this->assertEquals('withdrawal', $result[0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['date']);
- $this->assertEquals($importable->tags, $result[0]['tags']);
+ $this->assertEquals('withdrawal', $result[0]['transactions'][0]['type']);
+ $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
+ $this->assertEquals($importable->tags, $result[0]['transactions'][0]['tags']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
}
@@ -176,9 +176,9 @@ class ImportableConverterTest extends TestCase
// verify content of $result
$today = new Carbon();
- $this->assertEquals('transfer', $result[0]['type']);
- $this->assertEquals($today->format('Y-m-d H:i:s'), $result[0]['date']);
- $this->assertEquals([], $result[0]['tags']);
+ $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
+ $this->assertEquals($today->format('Y-m-d H:i:s'), $result[0]['transactions'][0]['date']);
+ $this->assertEquals([], $result[0]['transactions'][0]['tags']);
$this->assertEquals($euro->id, $result[0]['transactions'][0]['currency_id']);
}
@@ -237,13 +237,13 @@ class ImportableConverterTest extends TestCase
$result = $converter->convert($importables);
// verify content of $result
- $this->assertEquals('deposit', $result[0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['date']);
- $this->assertEquals([], $result[0]['tags']);
+ $this->assertEquals('deposit', $result[0]['transactions'][0]['type']);
+ $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
+ $this->assertEquals([], $result[0]['transactions'][0]['tags']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
$this->assertEquals($revenue->id, $result[0]['transactions'][0]['source_id']);
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
- $this->assertEquals('2018-01-02 00:00:00', $result[0]['book_date']);
+ $this->assertEquals('2018-01-02 00:00:00', $result[0]['transactions'][0]['book_date']);
}
@@ -361,11 +361,11 @@ class ImportableConverterTest extends TestCase
$result = $converter->convert($importables);
// verify content of $result
- $this->assertEquals('transfer', $result[0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['date']);
- $this->assertEquals([], $result[0]['tags']);
- $this->assertEquals(2, $result[0]['bill_id']); // will NOT be ignored.
- $this->assertEquals($importable->billName, $result[0]['bill_name']);
+ $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
+ $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
+ $this->assertEquals([], $result[0]['transactions'][0]['tags']);
+ $this->assertEquals(2, $result[0]['transactions'][0]['bill_id']); // will NOT be ignored.
+ $this->assertEquals($importable->billName, $result[0]['transactions'][0]['bill_name']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
// since amount is positive, $asset recieves the money
@@ -434,11 +434,11 @@ class ImportableConverterTest extends TestCase
$result = $converter->convert($importables);
// verify content of $result
- $this->assertEquals('transfer', $result[0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['date']);
- $this->assertEquals([], $result[0]['tags']);
- $this->assertEquals(3, $result[0]['bill_id']);
- $this->assertEquals($importable->billName, $result[0]['bill_name']);
+ $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
+ $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
+ $this->assertEquals([], $result[0]['transactions'][0]['tags']);
+ $this->assertEquals(3, $result[0]['transactions'][0]['bill_id']);
+ $this->assertEquals($importable->billName, $result[0]['transactions'][0]['bill_name']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
// since amount is negative, $asset sends the money
diff --git a/tests/Unit/Support/Import/Routine/File/LineReaderTest.php b/tests/Unit/Support/Import/Routine/File/LineReaderTest.php
index a98a1a15a0..db3cb35f10 100644
--- a/tests/Unit/Support/Import/Routine/File/LineReaderTest.php
+++ b/tests/Unit/Support/Import/Routine/File/LineReaderTest.php
@@ -55,7 +55,7 @@ class LineReaderTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'linerA' . random_int(1, 10000);
+ $job->key = 'linerA' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php b/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
index 7aa1a8c1c5..856d5a2b5f 100644
--- a/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
+++ b/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
@@ -132,7 +132,7 @@ class MappingConvergerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'linerB' . random_int(1, 10000);
+ $job->key = 'linerB' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'fake';
diff --git a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php b/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php
index bfb427c029..40a032c025 100644
--- a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php
+++ b/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php
@@ -72,16 +72,16 @@ class OpposingAccountMapperTest extends TestCase
*/
public function testAccountIdBadType(): void
{
- $expected = $this->user()->accounts()->where('account_type_id', 5)->inRandomOrder()->first();
+ $expected = $this->getRandomRevenue();
$expected->iban = null;
$expected->save();
$amount = '-12.34';
$expectedArgs = [
'name' => $expected->name,
'iban' => null,
- 'accountNumber' => null,
+ 'account_number' => null,
'account_type_id' => null,
- 'accountType' => AccountType::EXPENSE,
+ 'account_type' => AccountType::EXPENSE,
'active' => true,
'BIC' => null,
];
@@ -116,9 +116,9 @@ class OpposingAccountMapperTest extends TestCase
$expectedArgs = [
'name' => $expected->name,
'iban' => $expected->iban,
- 'accountNumber' => null,
+ 'account_number' => null,
'account_type_id' => null,
- 'accountType' => AccountType::EXPENSE,
+ 'account_type' => AccountType::EXPENSE,
'active' => true,
'BIC' => null,
];
@@ -152,9 +152,9 @@ class OpposingAccountMapperTest extends TestCase
$expectedArgs = [
'name' => '(no name)',
'iban' => null,
- 'accountNumber' => null,
+ 'account_number' => null,
'account_type_id' => null,
- 'accountType' => AccountType::EXPENSE,
+ 'account_type' => AccountType::EXPENSE,
'active' => true,
'BIC' => null,
];
@@ -184,9 +184,9 @@ class OpposingAccountMapperTest extends TestCase
$expectedArgs = [
'name' => '(no name)',
'iban' => null,
- 'accountNumber' => null,
+ 'account_number' => null,
'account_type_id' => null,
- 'accountType' => AccountType::REVENUE,
+ 'account_type' => AccountType::REVENUE,
'active' => true,
'BIC' => null,
];
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php
index 78857f7382..5411fa8e80 100644
--- a/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php
@@ -122,7 +122,7 @@ class StageAuthenticatedHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . random_int(1, 10000);
+ $job->key = 'sa_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -251,7 +251,7 @@ class StageAuthenticatedHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . random_int(1, 10000);
+ $job->key = 'sa_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -380,7 +380,7 @@ class StageAuthenticatedHandlerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . random_int(1, 10000);
+ $job->key = 'sa_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php
index d1f3375476..cca0a6c86f 100644
--- a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php
@@ -325,7 +325,7 @@ class StageImportDataHandlerTest extends TestCase
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sid_a_' . random_int(1, 10000);
+ $job->key = 'sid_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -524,7 +524,7 @@ class StageImportDataHandlerTest extends TestCase
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sid_a_' . random_int(1, 10000);
+ $job->key = 'sid_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php
index 7667c47a0d..8e72f72b49 100644
--- a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php
+++ b/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php
@@ -67,7 +67,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . random_int(1, 10000);
+ $job->key = 'sn_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -134,7 +134,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . random_int(1, 10000);
+ $job->key = 'sn_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -187,7 +187,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . random_int(1, 10000);
+ $job->key = 'sn_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -256,7 +256,7 @@ class StageNewHandlerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . random_int(1, 10000);
+ $job->key = 'sn_a_' . $this->randomInt();
$job->status = 'new';
$job->stage = 'new';
$job->provider = 'spectre';
diff --git a/tests/Unit/TransactionRules/Actions/AddTagTest.php b/tests/Unit/TransactionRules/Actions/AddTagTest.php
index 9a6fd15759..bb95a0be36 100644
--- a/tests/Unit/TransactionRules/Actions/AddTagTest.php
+++ b/tests/Unit/TransactionRules/Actions/AddTagTest.php
@@ -75,7 +75,7 @@ class AddTagTest extends TestCase
*/
public function testActNoTag(): void
{
- $newTagName = 'TestTag-' . random_int(1, 10000);
+ $newTagName = 'TestTag-' . $th;
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$ruleAction = new RuleAction;
$ruleAction->action_value = $newTagName;
diff --git a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php b/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php
index 0deb03cdea..8e55fb94d2 100644
--- a/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php
+++ b/tests/Unit/TransactionRules/Actions/ConvertToDepositTest.php
@@ -59,7 +59,7 @@ class ConvertToDepositTest extends TestCase
return;
$revenue = $this->getRandomRevenue();
- $name = 'Random revenue #' . random_int(1, 10000);
+ $name = 'Random revenue #' . $this->randomInt();
$journal = $this->getRandomTransfer();
// journal is a transfer:
@@ -98,7 +98,7 @@ class ConvertToDepositTest extends TestCase
return;
$revenue = $this->getRandomRevenue();
- $name = 'Random revenue #' . random_int(1, 10000);
+ $name = 'Random revenue #' . $this->randomInt();
$journal = $this->getRandomWithdrawal();
// journal is a withdrawal:
diff --git a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php b/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php
index 80cb65f845..b13c52c013 100644
--- a/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php
+++ b/tests/Unit/TransactionRules/Actions/ConvertToWithdrawalTest.php
@@ -59,7 +59,7 @@ class ConvertToWithdrawalTest extends TestCase
return;
$expense = $this->getRandomExpense();
- $name = 'Random expense #' . random_int(1, 10000);
+ $name = 'Random expense #' . $this->randomInt();
$deposit = $this->getRandomDeposit();
// journal is a deposit:
@@ -98,7 +98,7 @@ class ConvertToWithdrawalTest extends TestCase
return;
$expense = $this->getRandomExpense();
- $name = 'Random expense #' . random_int(1, 10000);
+ $name = 'Random expense #' . $this->randomInt();
$transfer = $this->getRandomTransfer();
// journal is a transfer:
diff --git a/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php b/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php
index e884ab1c00..03f3ed9a63 100644
--- a/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php
+++ b/tests/Unit/TransactionRules/Actions/PrependDescriptionTest.php
@@ -38,7 +38,7 @@ class PrependDescriptionTest extends TestCase
public function testAct(): void
{
// get journal, give fixed description
- $description = 'text' . random_int(1, 10000);
+ $description = 'text' . $this->randomInt();
$prepend = 'prepend' . random_int(1, 1234);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
diff --git a/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php b/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php
index 2b62486942..71de5fedb4 100644
--- a/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php
+++ b/tests/Unit/TransactionRules/Actions/SetDescriptionTest.php
@@ -38,7 +38,7 @@ class SetDescriptionTest extends TestCase
public function testAct(): void
{
// get journal, give fixed description
- $description = 'text' . random_int(1, 10000);
+ $description = 'text' . $this->randomInt();
$newDescription = 'new description' . random_int(1, 1234);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
diff --git a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php b/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php
index ce816ba32e..5ad3610c92 100644
--- a/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php
+++ b/tests/Unit/TransactionRules/Actions/SetDestinationAccountTest.php
@@ -94,7 +94,7 @@ class SetDestinationAccountTest extends TestCase
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Not existing asset account #' . random_int(1, 10000);
+ $ruleAction->action_value = 'Not existing asset account #' . $this->randomInt();
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($deposit);
$this->assertFalse($result);
@@ -121,7 +121,7 @@ class SetDestinationAccountTest extends TestCase
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Not existing expense account #' . random_int(1, 10000);
+ $ruleAction->action_value = 'Not existing expense account #' . $this->randomInt();
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($withdrawal);
@@ -186,7 +186,7 @@ class SetDestinationAccountTest extends TestCase
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Some new asset ' . random_int(1, 10000);
+ $ruleAction->action_value = 'Some new asset ' . $this->randomInt();
$action = new SetDestinationAccount($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
diff --git a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php b/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php
index 55a4832d78..61982826b1 100644
--- a/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php
+++ b/tests/Unit/TransactionRules/Actions/SetSourceAccountTest.php
@@ -93,7 +93,7 @@ class SetSourceAccountTest extends TestCase
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Some new revenue #' . random_int(1, 10000);
+ $ruleAction->action_value = 'Some new revenue #' . $this->randomInt();
$action = new SetSourceAccount($ruleAction);
$result = $action->act($deposit);
$this->assertTrue($result);
@@ -155,7 +155,7 @@ class SetSourceAccountTest extends TestCase
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Some new account #' . random_int(1, 10000);
+ $ruleAction->action_value = 'Some new account #' . $this->randomInt();
$action = new SetSourceAccount($ruleAction);
$result = $action->act($withdrawal);
$this->assertFalse($result);
@@ -181,7 +181,7 @@ class SetSourceAccountTest extends TestCase
$accountRepos->shouldReceive('setUser');
// fire the action:
$ruleAction = new RuleAction;
- $ruleAction->action_value = 'Some new asset ' . random_int(1, 10000);
+ $ruleAction->action_value = 'Some new asset ' . $this->randomInt();
$action = new SetSourceAccount($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
diff --git a/tests/Unit/Transformers/AttachmentTransformerTest.php b/tests/Unit/Transformers/AttachmentTransformerTest.php
index e449acd4c6..bda945afe6 100644
--- a/tests/Unit/Transformers/AttachmentTransformerTest.php
+++ b/tests/Unit/Transformers/AttachmentTransformerTest.php
@@ -53,7 +53,7 @@ class AttachmentTransformerTest extends TestCase
public function testBasic(): void
{
$repository = $this->mock(AttachmentRepositoryInterface::class);
- $md5 = md5('hello' . random_int(1, 10000));
+ $md5 = md5('hello' . $this->randomInt());
$attachment = Attachment::create(
[
'user_id' => $this->user()->id,
diff --git a/tests/Unit/Transformers/TagTransformerTest.php b/tests/Unit/Transformers/TagTransformerTest.php
index b38f7e555d..34cdc02b0e 100644
--- a/tests/Unit/Transformers/TagTransformerTest.php
+++ b/tests/Unit/Transformers/TagTransformerTest.php
@@ -44,7 +44,7 @@ class TagTransformerTest extends TestCase
$tag = Tag::create(
[
'user_id' => $this->user()->id,
- 'tag' => 'Some tag ' . random_int(1, 10000),
+ 'tag' => 'Some tag ' . $this->randomInt(),
'tagMode' => 'nothing',
'date' => '2018-01-01',
'description' => 'Some tag',