mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Speed up category tests.
This commit is contained in:
@@ -181,19 +181,20 @@ class CategoryController extends Controller
|
|||||||
$periods = new Collection;
|
$periods = new Collection;
|
||||||
$page = (int)$request->get('page');
|
$page = (int)$request->get('page');
|
||||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||||
|
Log::debug('Start of noCategory()');
|
||||||
// prep for "all" view.
|
// prep for "all" view.
|
||||||
if ('all' === $moment) {
|
if ('all' === $moment) {
|
||||||
$subTitle = trans('firefly.all_journals_without_category');
|
$subTitle = trans('firefly.all_journals_without_category');
|
||||||
$first = $this->journalRepos->firstNull();
|
$first = $this->journalRepos->firstNull();
|
||||||
$start = null === $first ? new Carbon : $first->date;
|
$start = null === $first ? new Carbon : $first->date;
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
|
Log::debug('Moment is all()');
|
||||||
}
|
}
|
||||||
|
|
||||||
// prep for "specific date" view.
|
// prep for "specific date" view.
|
||||||
if ('all' !== $moment && \strlen($moment) > 0) {
|
if ('all' !== $moment && \strlen($moment) > 0) {
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = app('navigation')->startOfPeriod(new Carbon($moment), $range);
|
$start = app('navigation')->startOfPeriod(new Carbon($moment), $range);
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = app('navigation')->endOfPeriod($start, $range);
|
$end = app('navigation')->endOfPeriod($start, $range);
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
@@ -201,6 +202,7 @@ class CategoryController extends Controller
|
|||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
);
|
);
|
||||||
$periods = $this->getNoCategoryPeriodOverview($start);
|
$periods = $this->getNoCategoryPeriodOverview($start);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prep for current period
|
// prep for current period
|
||||||
@@ -213,6 +215,8 @@ class CategoryController extends Controller
|
|||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
|
||||||
|
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
|
||||||
|
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
@@ -258,7 +262,7 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
// prep for "specific date" view.
|
// prep for "specific date" view.
|
||||||
if ('all' !== $moment && \strlen($moment) > 0) {
|
if ('all' !== $moment && \strlen($moment) > 0) {
|
||||||
$start = app('navigation')->startOfPeriod(new Carbon($moment), $range);
|
$start = app('navigation')->startOfPeriod(new Carbon($moment), $range);
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = app('navigation')->endOfPeriod($start, $range);
|
$end = app('navigation')->endOfPeriod($start, $range);
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
@@ -358,11 +362,15 @@ class CategoryController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
|
private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$first = $this->journalRepos->firstNull();
|
$first = $this->journalRepos->firstNull();
|
||||||
$start = null === $first ? new Carbon : $first->date;
|
$start = null === $first ? new Carbon : $first->date;
|
||||||
$end = $theDate ?? new Carbon;
|
$end = $theDate ?? new Carbon;
|
||||||
|
|
||||||
|
Log::debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d')));
|
||||||
|
Log::debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d')));
|
||||||
|
|
||||||
// properties for cache
|
// properties for cache
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
@@ -408,7 +416,7 @@ class CategoryController extends Controller
|
|||||||
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()->withOpposingAccount()->setTypes(
|
$collector->setAllAssetAccounts()->setRange($date['start'], $date['end'])->withoutCategory()->withOpposingAccount()->setTypes(
|
||||||
[TransactionType::DEPOSIT]
|
[TransactionType::DEPOSIT]
|
||||||
);
|
);
|
||||||
$earned = $collector->getJournals()->sum('transaction_amount');
|
$earned = $collector->getJournals()->sum('transaction_amount');
|
||||||
/** @noinspection PhpUndefinedMethodInspection */
|
/** @noinspection PhpUndefinedMethodInspection */
|
||||||
$dateStr = $date['end']->format('Y-m-d');
|
$dateStr = $date['end']->format('Y-m-d');
|
||||||
$dateName = app('navigation')->periodShow($date['end'], $date['period']);
|
$dateName = app('navigation')->periodShow($date['end'], $date['period']);
|
||||||
@@ -462,8 +470,8 @@ class CategoryController extends Controller
|
|||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
|
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
$spent = $this->repository->spentInPeriod(new Collection([$category]), $accounts, $currentDate['start'], $currentDate['end']);
|
$spent = $this->repository->spentInPeriod(new Collection([$category]), $accounts, $currentDate['start'], $currentDate['end']);
|
||||||
$earned = $this->repository->earnedInPeriod(new Collection([$category]), $accounts, $currentDate['start'], $currentDate['end']);
|
$earned = $this->repository->earnedInPeriod(new Collection([$category]), $accounts, $currentDate['start'], $currentDate['end']);
|
||||||
/** @noinspection PhpUndefinedMethodInspection */
|
/** @noinspection PhpUndefinedMethodInspection */
|
||||||
$dateStr = $currentDate['end']->format('Y-m-d');
|
$dateStr = $currentDate['end']->format('Y-m-d');
|
||||||
$dateName = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
$dateName = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||||
|
@@ -509,7 +509,7 @@ class Navigation
|
|||||||
{
|
{
|
||||||
$date = clone $theDate;
|
$date = clone $theDate;
|
||||||
// 1D 1W 1M 3M 6M 1Y
|
// 1D 1W 1M 3M 6M 1Y
|
||||||
Log::debug(sprintf('subtractPeriod: date is %s', $date->format('Y-m-d')));
|
Log::debug(sprintf('subtractPeriod: date is %s, repeat frequency is %s and subtract is %d', $date->format('Y-m-d'), $repeatFreq, $subtract));
|
||||||
$functionMap = [
|
$functionMap = [
|
||||||
'1D' => 'subDays',
|
'1D' => 'subDays',
|
||||||
'daily' => 'subDays',
|
'daily' => 'subDays',
|
||||||
|
@@ -60,6 +60,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('TestCreate()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
@@ -78,6 +79,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete(): void
|
public function testDelete(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test Delete()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
@@ -96,6 +98,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy(): void
|
public function testDestroy(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test destroy()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
@@ -116,6 +119,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit(): void
|
public function testEdit(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test edit()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
@@ -135,6 +139,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex(): void
|
public function testIndex(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test index()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$category = factory(Category::class)->make();
|
$category = factory(Category::class)->make();
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
@@ -160,12 +165,17 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoCategory(string $range): void
|
public function testNoCategory(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Test noCategory(%s)', $range));
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
|
||||||
|
|
||||||
|
// get the journal with the most recent date for firstNull:
|
||||||
|
$journal = $this->user()->transactionJournals()->orderBy('date','DESC')->first();
|
||||||
|
$journalRepos->shouldReceive('firstNull')->twice()->andReturn($journal);
|
||||||
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||||
@@ -197,6 +207,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoCategoryAll(string $range): void
|
public function testNoCategoryAll(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test nocategoryAll()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
@@ -233,6 +244,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoCategoryDate(string $range): void
|
public function testNoCategoryDate(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test nocategorydate()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
@@ -277,6 +289,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow(string $range): void
|
public function testShow(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test show()');
|
||||||
$transaction = factory(Transaction::class)->make();
|
$transaction = factory(Transaction::class)->make();
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
@@ -326,6 +339,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowAll(string $range): void
|
public function testShowAll(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test showAll()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$transaction = factory(Transaction::class)->make();
|
$transaction = factory(Transaction::class)->make();
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
@@ -364,6 +378,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowByDate(string $range): void
|
public function testShowByDate(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test showbydate()');
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$transaction = factory(Transaction::class)->make();
|
$transaction = factory(Transaction::class)->make();
|
||||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
@@ -412,6 +427,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowEmpty(string $range): void
|
public function testShowEmpty(string $range): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test showempty()');
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
||||||
|
|
||||||
@@ -451,6 +467,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore(): void
|
public function testStore(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test store()');
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
@@ -475,6 +492,7 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(): void
|
public function testUpdate(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Test update()');
|
||||||
$category = Category::first();
|
$category = Category::first();
|
||||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ToAccountIsTest
|
* Class ToAccountIsTest
|
||||||
@@ -36,14 +37,22 @@ class ToAccountIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$loops = 0; // FINAL LOOP METHOD.
|
||||||
do {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
/** @var TransactionJournal $journal */
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$transactionCount = $journal->transactions()->count();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = null === $transaction ? null : $transaction->account;
|
$account = $transaction->account;
|
||||||
$count++;
|
$count = $journal->transactions()->count();
|
||||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
|
||||||
|
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||||
|
|
||||||
|
$loops++;
|
||||||
|
|
||||||
|
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||||
|
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$trigger = ToAccountIs::makeFromStrings($account->name, false);
|
$trigger = ToAccountIs::makeFromStrings($account->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
@@ -55,14 +64,20 @@ class ToAccountIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNot(): void
|
public function testTriggeredNot(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$loops = 0; // FINAL LOOP METHOD.
|
||||||
do {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
/** @var TransactionJournal $journal */
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$transactionCount = $journal->transactions()->count();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = null === $transaction ? null : $transaction->account;
|
$account = $transaction->account;
|
||||||
$count++;
|
$count = $journal->transactions()->count();
|
||||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
|
||||||
|
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||||
|
|
||||||
|
$loops++;
|
||||||
|
|
||||||
|
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||||
|
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||||
|
|
||||||
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
|
Reference in New Issue
Block a user