mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Speed up category tests.
This commit is contained in:
@@ -60,6 +60,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
Log::debug('TestCreate()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -78,6 +79,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
Log::debug('Test Delete()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -96,6 +98,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
Log::debug('Test destroy()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -116,6 +119,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
Log::debug('Test edit()');
|
||||
// mock stuff
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -135,6 +139,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
Log::debug('Test index()');
|
||||
// mock stuff
|
||||
$category = factory(Category::class)->make();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
@@ -160,12 +165,17 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategory(string $range): void
|
||||
{
|
||||
Log::debug(sprintf('Test noCategory(%s)', $range));
|
||||
// mock stuff
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::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('setTypes')->andReturnSelf();
|
||||
@@ -197,6 +207,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategoryAll(string $range): void
|
||||
{
|
||||
Log::debug('Test nocategoryAll()');
|
||||
// mock stuff
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
@@ -233,6 +244,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testNoCategoryDate(string $range): void
|
||||
{
|
||||
Log::debug('Test nocategorydate()');
|
||||
// mock stuff
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
@@ -277,6 +289,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testShow(string $range): void
|
||||
{
|
||||
Log::debug('Test show()');
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@@ -326,6 +339,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testShowAll(string $range): void
|
||||
{
|
||||
Log::debug('Test showAll()');
|
||||
// mock stuff
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
@@ -364,6 +378,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testShowByDate(string $range): void
|
||||
{
|
||||
Log::debug('Test showbydate()');
|
||||
// mock stuff
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
@@ -412,6 +427,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testShowEmpty(string $range): void
|
||||
{
|
||||
Log::debug('Test showempty()');
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->twice()->andReturn(TransactionJournal::first());
|
||||
|
||||
@@ -451,6 +467,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
Log::debug('Test store()');
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
@@ -475,6 +492,7 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
Log::debug('Test update()');
|
||||
$category = Category::first();
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
@@ -25,6 +25,7 @@ namespace Tests\Unit\TransactionRules\Triggers;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ToAccountIsTest
|
||||
@@ -36,14 +37,22 @@ class ToAccountIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$count = 0;
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
|
||||
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings($account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -55,14 +64,20 @@ class ToAccountIsTest extends TestCase
|
||||
*/
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$count = 0;
|
||||
$loops = 0; // FINAL LOOP METHOD.
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = null === $transaction ? null : $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$account = $transaction->account;
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
Log::debug(sprintf('Loop: %d, transaction count: %d, account is null: %d', $loops, $count, (int)null===$account));
|
||||
|
||||
$loops++;
|
||||
|
||||
// do this until: account is not null, journal has two transactions, loops is below 30
|
||||
} while (!(null !== $account && 2 === $count && $loops < 30));
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
Reference in New Issue
Block a user