mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Update tests so repositories are not called. Saves on DB calls, speeds up tests.
This commit is contained in:
@@ -26,9 +26,9 @@ namespace Tests\Unit\Import\JobConfiguration;
|
||||
use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FakeJobConfigurationTest
|
||||
@@ -52,6 +52,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCC(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'A_unit_' . random_int(1, 10000);
|
||||
@@ -62,6 +65,8 @@ class FakeJobConfigurationTest extends TestCase
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
|
||||
|
||||
// should be false:
|
||||
$configurator = new FakeJobConfiguration;
|
||||
$configurator->setImportJob($job);
|
||||
@@ -75,6 +80,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCAlbumFalse(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'B_unit_' . random_int(1, 10000);
|
||||
@@ -98,6 +106,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCApplyRules(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'C_unit_' . random_int(1, 10000);
|
||||
@@ -123,6 +134,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCBadAlbum(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'D_unit_' . random_int(1, 10000);
|
||||
@@ -151,6 +165,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCBadInfo(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'E_unit_' . random_int(1, 10000);
|
||||
@@ -178,6 +195,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCGoodAlbum(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'f_unit_' . random_int(1, 10000);
|
||||
@@ -206,6 +226,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCGoodNewInfo(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'g_unit_' . random_int(1, 10000);
|
||||
@@ -513,6 +536,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewAlbum(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 10000);
|
||||
@@ -537,6 +563,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewArtist(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 10000);
|
||||
@@ -561,6 +590,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewRules(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 10000);
|
||||
@@ -585,6 +617,9 @@ class FakeJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewSong(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'p_unit_' . random_int(1, 10000);
|
||||
|
@@ -27,6 +27,7 @@ namespace Tests\Unit\Import\JobConfiguration;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\JobConfiguration\FileJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler;
|
||||
@@ -57,6 +58,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCFalse(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'File_A_unit_' . random_int(1, 10000);
|
||||
@@ -80,6 +83,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testCCTrue(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'File_B_unit_' . random_int(1, 10000);
|
||||
@@ -103,6 +108,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'I-Cfile_' . random_int(1, 10000);
|
||||
@@ -138,6 +145,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextDataCU(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'G-Dfile_' . random_int(1, 10000);
|
||||
@@ -171,6 +180,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextDataMap(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'H-Efile_' . random_int(1, 10000);
|
||||
@@ -204,6 +215,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextDataNew(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'F-fFile_' . random_int(1, 10000);
|
||||
@@ -237,6 +250,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextDataRoles(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'H-fiGle_' . random_int(1, 10000);
|
||||
@@ -270,6 +285,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewCU(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'DfiHle_' . random_int(1, 10000);
|
||||
@@ -298,6 +315,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewMap(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'FfilIe_' . random_int(1, 10000);
|
||||
@@ -326,6 +345,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewNew(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'CfJile_' . random_int(1, 10000);
|
||||
@@ -354,6 +375,8 @@ class FileJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewRoles(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once()->atLeast();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'EfiKle_' . random_int(1, 10000);
|
||||
|
@@ -26,6 +26,7 @@ namespace Tests\Unit\Import\JobConfiguration;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\JobConfiguration\SpectreJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
|
||||
@@ -55,6 +56,8 @@ class SpectreJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testConfigurationComplete(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_A' . random_int(1, 10000);
|
||||
@@ -84,6 +87,8 @@ class SpectreJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_B' . random_int(1, 10000);
|
||||
@@ -116,6 +121,8 @@ class SpectreJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextData(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_C' . random_int(1, 10000);
|
||||
@@ -146,6 +153,8 @@ class SpectreJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextView(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_D' . random_int(1, 10000);
|
||||
@@ -175,6 +184,8 @@ class SpectreJobConfigurationTest extends TestCase
|
||||
*/
|
||||
public function testGetNextViewAccount(): void
|
||||
{
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$jobRepos->shouldReceive('setUser')->once();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_E' . random_int(1, 10000);
|
||||
|
@@ -38,10 +38,12 @@ use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ImportArrayStorageTest
|
||||
*/
|
||||
@@ -57,7 +59,6 @@ class ImportArrayStorageTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Very basic storage routine. Doesn't call store()
|
||||
*
|
||||
@@ -65,6 +66,10 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasic(): void
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
@@ -77,9 +82,6 @@ class ImportArrayStorageTest extends TestCase
|
||||
$job->transactions = [];
|
||||
$job->save();
|
||||
|
||||
// mock stuff
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@@ -94,6 +96,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreDoubleTransferWithRules(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// get a transfer:
|
||||
/** @var TransactionJournal $transfer */
|
||||
$transfer = $this->user()->transactionJournals()
|
||||
@@ -183,6 +188,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreIsDouble(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$transactions = [$this->singleWithdrawal(), $this->singleWithdrawal()];
|
||||
$job = new ImportJob;
|
||||
@@ -245,6 +253,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreNothing(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
@@ -284,6 +295,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreNothingWithRules(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
@@ -326,6 +340,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreSingleWithNoRules(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
@@ -377,6 +394,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreSingleWithRules(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
@@ -433,6 +453,9 @@ class ImportArrayStorageTest extends TestCase
|
||||
*/
|
||||
public function testBasicStoreTransferWithRules(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('findNull')->once()->andReturn($this->user());
|
||||
|
||||
// make fake job
|
||||
$job = new ImportJob;
|
||||
$job->user()->associate($this->user());
|
||||
|
Reference in New Issue
Block a user