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:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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(
|
||||
|
@@ -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();
|
||||
|
@@ -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' => [
|
||||
|
Reference in New Issue
Block a user