mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
See if this is the solution in Scrutinizer as well.
This commit is contained in:
@@ -79,6 +79,7 @@ class BudgetController extends Controller
|
|||||||
public function budget(Budget $budget): JsonResponse
|
public function budget(Budget $budget): JsonResponse
|
||||||
{
|
{
|
||||||
$start = $this->repository->firstUseDate($budget);
|
$start = $this->repository->firstUseDate($budget);
|
||||||
|
/** @var Carbon $end */
|
||||||
$end = session('end', new Carbon);
|
$end = session('end', new Carbon);
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
|
@@ -24,6 +24,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
|||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
|
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
|
||||||
|
use Log;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,14 +37,26 @@ class ToAccountEndsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$loops = 0; // FINAL LOOP METHOD.
|
||||||
$account = null;
|
do {
|
||||||
while ($count === 0 && $account === null) {
|
/** @var TransactionJournal $journal */
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = $transaction->account;
|
$account = $transaction->account;
|
||||||
}
|
$count = $journal->transactions()->count();
|
||||||
|
$name = $account->name ?? '';
|
||||||
|
|
||||||
|
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||||
|
|
||||||
|
$loops++;
|
||||||
|
|
||||||
|
// do this while the following is untrue:
|
||||||
|
// 1) account is not null,
|
||||||
|
// 2) journal has two transactions
|
||||||
|
// 3) loops is less than 30
|
||||||
|
// 4) $name is longer than 3
|
||||||
|
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||||
|
|
||||||
|
|
||||||
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
@@ -55,13 +68,25 @@ class ToAccountEndsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredLonger(): void
|
public function testTriggeredLonger(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$loops = 0; // FINAL LOOP METHOD.
|
||||||
while ($count === 0) {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
/** @var TransactionJournal $journal */
|
||||||
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
}
|
$account = $transaction->account;
|
||||||
$account = $transaction->account;
|
$count = $journal->transactions()->count();
|
||||||
|
$name = $account->name ?? '';
|
||||||
|
|
||||||
|
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||||
|
|
||||||
|
$loops++;
|
||||||
|
|
||||||
|
// do this while the following is untrue:
|
||||||
|
// 1) account is not null,
|
||||||
|
// 2) journal has two transactions
|
||||||
|
// 3) loops is less than 30
|
||||||
|
// 4) $name is longer than 3
|
||||||
|
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||||
|
|
||||||
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
@@ -73,11 +98,25 @@ class ToAccountEndsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNot(): void
|
public function testTriggeredNot(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$loops = 0; // FINAL LOOP METHOD.
|
||||||
while ($count === 0) {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
/** @var TransactionJournal $journal */
|
||||||
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
}
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
|
$account = $transaction->account;
|
||||||
|
$count = $journal->transactions()->count();
|
||||||
|
$name = $account->name ?? '';
|
||||||
|
|
||||||
|
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d, name = "%s"', $loops, $count, (int)null === $account, $name));
|
||||||
|
|
||||||
|
$loops++;
|
||||||
|
|
||||||
|
// do this while the following is untrue:
|
||||||
|
// 1) account is not null,
|
||||||
|
// 2) journal has two transactions
|
||||||
|
// 3) loops is less than 30
|
||||||
|
// 4) $name is longer than 3
|
||||||
|
} while (!(null !== $account && 2 === $count && $loops < 30 && \strlen($name) > 3));
|
||||||
|
|
||||||
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 1234), false);
|
$trigger = ToAccountEnds::makeFromStrings((string)random_int(1, 1234), false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
|
Reference in New Issue
Block a user