Update tests so repositories are not called. Saves on DB calls, speeds up tests.

This commit is contained in:
James Cole
2018-09-04 16:47:01 +02:00
parent ca04113aa7
commit d43fa3790d
23 changed files with 376 additions and 65 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\IsAdmin;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Mockery;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
@@ -54,6 +56,8 @@ class IsAdminTest extends TestCase
*/
public function testMiddleware(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
@@ -65,6 +69,8 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareAjax(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin', $server);
@@ -76,6 +82,9 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareNotOwner(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
$this->withoutExceptionHandling();
$this->be($this->emptyUser());
$response = $this->get('/_test/is-admin');
@@ -88,6 +97,9 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareOwner(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin');

View File

@@ -35,9 +35,9 @@ use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
use Illuminate\Support\Collection;
use League\Csv\Exception;
use League\Csv\Reader;
use Log;
use Mockery;
use Tests\TestCase;
use Log;
/**
* Class ConfigureMappingHandlerTest
@@ -59,6 +59,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testApplySpecifics(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapG' . random_int(1, 10000);
@@ -94,6 +96,7 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testConfigureJob(): void
{
// create fake input for class method:
$input = [
'mapping' => [
@@ -158,6 +161,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testDoColumnConfig(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapE' . random_int(1, 10000);
@@ -221,7 +226,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testDoMapOfColumn(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapC' . random_int(1, 10000);
@@ -251,6 +257,7 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testGetNextData(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapH' . random_int(1, 10000);
@@ -332,6 +339,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testGetPreProcessorName(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapD' . random_int(1, 10000);
@@ -360,6 +369,7 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testGetReader(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapF' . random_int(1, 10000);
@@ -408,6 +418,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testGetValuesForMapping(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
// create a reader to use in method.
// 5 columns, of which #4 (index 3) is budget-id
// 5 columns, of which #5 (index 4) is tags-space
@@ -475,7 +487,8 @@ class ConfigureMappingHandlerTest extends TestCase
*/
public function testSanitizeColumnName(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'mapB' . random_int(1, 10000);

View File

@@ -57,6 +57,9 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testConfigurationCompleteBasic(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-count' => 5,
'column-roles' => [
@@ -77,6 +80,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testConfigurationCompleteForeign(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-count' => 5,
'column-roles' => [
@@ -101,6 +106,7 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testConfigurationCompleteNoAmount(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-count' => 5,
'column-roles' => [
@@ -125,6 +131,7 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testConfigureJob(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'role-B' . random_int(1, 10000);
@@ -178,7 +185,7 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testGetExampleFromLine(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$lines = [
['one', 'two', '', 'three'],
['four', 'five', '', 'six'],
@@ -201,6 +208,11 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testGetExamplesFromFile(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$importRepos->shouldReceive('setUser')->once();
$importRepos->shouldReceive('setConfiguration')->once()
->withAnyArgs();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'role-x' . random_int(1, 10000);
@@ -239,6 +251,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testGetHeadersHas(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
//$importRepos->shouldReceive('setUser')->once();
// create a reader to use in method.
// 5 columns, of which #4 (index 3) is budget-id
// 5 columns, of which #5 (index 4) is tags-space
@@ -260,6 +274,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testGetHeadersNone(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
// create a reader to use in method.
// 5 columns, of which #4 (index 3) is budget-id
// 5 columns, of which #5 (index 4) is tags-space
@@ -278,6 +294,7 @@ class ConfigureRolesHandlerTest extends TestCase
public function testGetNextData(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'role-x' . random_int(1, 10000);
@@ -348,6 +365,7 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testGetReader(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'role-x' . random_int(1, 10000);
@@ -396,6 +414,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testIgnoreUnmappableColumns(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-count' => 5,
'column-roles' => [
@@ -439,6 +459,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testIsMappingNecessaryNo(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-do-mapping' => [false, false, false],
];
@@ -452,6 +474,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testIsMappingNecessaryYes(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$config = [
'column-do-mapping' => [false, true, false, false],
];
@@ -465,6 +489,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testMakeExamplesUnique(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$lines = [
['one', 'two', '', 'three'],
['four', 'five', '', 'six'],
@@ -491,6 +517,8 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testProcessSpecifics(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$line = [];
$config = [
'specifics' => [
@@ -512,6 +540,7 @@ class ConfigureRolesHandlerTest extends TestCase
*/
public function testSaveColumCount(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'role-A' . random_int(1, 10000);

View File

@@ -59,6 +59,7 @@ class ChooseLoginHandlerTest extends TestCase
*/
public function testCCFalse(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'slh-A' . random_int(1, 10000);
@@ -205,6 +206,8 @@ class ChooseLoginHandlerTest extends TestCase
*/
public function testGetNextData(): void
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
// fake login:
$holder = new Holder([]);
$attempt = new Attempt(

View File

@@ -27,15 +27,16 @@ namespace Tests\Unit\Support\Import\Routine\File;
use Amount;
use Carbon\Carbon;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
use FireflyIII\Support\Import\Routine\File\AssetAccountMapper;
use FireflyIII\Support\Import\Routine\File\CurrencyMapper;
use FireflyIII\Support\Import\Routine\File\ImportableConverter;
use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
use Log;
use Mockery;
use Tests\TestCase;
use Log;
/**
* todo test foreign currency
@@ -81,6 +82,9 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -138,6 +142,10 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -159,7 +167,7 @@ class ImportableConverterTest extends TestCase
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn(null);
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
$currencyMapper->shouldReceive('map')->times(1)->withArgs([$euro->id, []])->andReturn($euro);
$currencyMapper->shouldReceive('map')->times(2)->withArgs([$euro->id, []])->andReturn($euro);
$converter = new ImportableConverter;
@@ -199,6 +207,8 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -261,6 +271,8 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -318,6 +330,8 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -389,6 +403,8 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -454,6 +470,8 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
// get default currency
$euro = TransactionCurrency::whereCode('EUR')->first();
@@ -502,7 +520,10 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$euro = TransactionCurrency::whereCode('EUR')->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
$euro = TransactionCurrency::whereCode('EUR')->first();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
$repository->shouldReceive('setUser')->once();
$assetMapper->shouldReceive('setUser')->once();
@@ -532,7 +553,10 @@ class ImportableConverterTest extends TestCase
$assetMapper = $this->mock(AssetAccountMapper::class);
$opposingMapper = $this->mock(OpposingAccountMapper::class);
$currencyMapper = $this->mock(CurrencyMapper::class);
$euro = TransactionCurrency::whereCode('EUR')->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
$euro = TransactionCurrency::whereCode('EUR')->first();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
$repository->shouldReceive('setUser')->once();
$assetMapper->shouldReceive('setUser')->once();

View File

@@ -26,6 +26,7 @@ namespace Tests\Unit\Support\Import\Routine\File;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\File\MappingConverger;
use Tests\TestCase;
use Log;
@@ -48,7 +49,8 @@ class MappingConvergerTest extends TestCase
*/
public function testConverge(): void
{
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
$jobRepos->shouldReceive('setUser')->once();
// configuration
$config = [
'column-roles' => [

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
use Illuminate\Support\Collection;
@@ -49,7 +50,7 @@ class FromAccountStartsTest extends TestCase
public function testTriggered(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
$account = $this->user()->accounts()->inRandomOrder()->first();
@@ -67,6 +68,7 @@ class FromAccountStartsTest extends TestCase
public function testTriggeredLonger(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
@@ -85,6 +87,7 @@ class FromAccountStartsTest extends TestCase
public function testTriggeredNot(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
@@ -103,6 +106,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$value = '';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
@@ -114,6 +119,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$value = 'x';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertFalse($result);
@@ -125,6 +132,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$value = null;
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);