Code cleanup and realign.

This commit is contained in:
James Cole
2018-08-06 19:14:30 +02:00
parent f7eef25fed
commit 5908c0ce8c
188 changed files with 1019 additions and 1031 deletions

View File

@@ -69,46 +69,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
}
/**
* Test minimal set of data to make factory work (asset account).
*
* @covers \FireflyIII\Factory\AccountFactory
* @covers \FireflyIII\Factory\AccountMetaFactory
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testCreateBasicEmptyVb(): void
{
$data = [
'account_type_id' => null,
'accountType' => 'asset',
'iban' => null,
'name' => 'Basic asset account #' . random_int(1, 10000),
'virtualBalance' => '',
'active' => true,
'accountRole' => 'defaultAsset',
];
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user());
$account = $factory->create($data);
// assert stuff about account:
$this->assertEquals($account->name, $data['name']);
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
$this->assertEquals('', $account->iban);
$this->assertTrue($account->active);
$this->assertEquals('0', $account->virtual_balance);
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
}
@@ -148,17 +109,56 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('ccAsset', $meta->data);
// get the date:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','ccMonthlyPaymentDate')->first();
$meta = $account->accountMeta()->where('name', 'ccMonthlyPaymentDate')->first();
$this->assertNotNull($meta);
$this->assertEquals('2018-01-01', $meta->data);
}
/**
* Test minimal set of data to make factory work (asset account).
*
* @covers \FireflyIII\Factory\AccountFactory
* @covers \FireflyIII\Factory\AccountMetaFactory
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testCreateBasicEmptyVb(): void
{
$data = [
'account_type_id' => null,
'accountType' => 'asset',
'iban' => null,
'name' => 'Basic asset account #' . random_int(1, 10000),
'virtualBalance' => '',
'active' => true,
'accountRole' => 'defaultAsset',
];
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user());
$account = $factory->create($data);
// assert stuff about account:
$this->assertEquals($account->name, $data['name']);
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
$this->assertEquals('', $account->iban);
$this->assertTrue($account->active);
$this->assertEquals('0', $account->virtual_balance);
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
}
/**
* Create an expense account. This overrules the virtual balance.
* Role should not be set.
@@ -194,7 +194,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNull($meta);
}
@@ -233,7 +233,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNull($meta);
}
@@ -274,7 +274,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
@@ -320,7 +320,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
@@ -362,7 +362,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
}
@@ -401,7 +401,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
}
@@ -443,7 +443,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);
@@ -487,7 +487,7 @@ class AccountFactoryTest extends TestCase
// get the role:
/** @var AccountMeta $meta */
$meta = $account->accountMeta()->where('name','accountRole')->first();
$meta = $account->accountMeta()->where('name', 'accountRole')->first();
$this->assertNotNull($meta);
$this->assertEquals('defaultAsset', $meta->data);

View File

@@ -67,6 +67,20 @@ class TransactionCurrencyFactoryTest extends TestCase
}
/**
* submit ID = 1000
*
* @covers \FireflyIII\Factory\TransactionCurrencyFactory
*/
public function testFindByBadID(): void
{
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find(1000, $currency->code);
$this->assertEquals($currency->id, $result->id);
}
/**
* @covers \FireflyIII\Factory\TransactionCurrencyFactory
*/
@@ -92,20 +106,6 @@ class TransactionCurrencyFactoryTest extends TestCase
$this->assertEquals($currency->id, $result->id);
}
/**
* submit ID = 1000
*
* @covers \FireflyIII\Factory\TransactionCurrencyFactory
*/
public function testFindByBadID(): void
{
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find(1000, $currency->code);
$this->assertEquals($currency->id, $result->id);
}
/**
* @covers \FireflyIII\Factory\TransactionCurrencyFactory
*/

View File

@@ -704,11 +704,11 @@ class TransactionFactoryTest extends TestCase
public function testCreatePairReconciliation(): void
{
// objects:
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
$reconAccount = $this->user()->accounts()->where('account_type_id', 10)->first();
//$opposing = $this->user()->accounts()->where('id', '!=', $asset->id)->where('account_type_id', 3)->first();
$euro = TransactionCurrency::first();
$foreign = TransactionCurrency::where('id', '!=', $euro->id)->first();
$euro = TransactionCurrency::first();
$foreign = TransactionCurrency::where('id', '!=', $euro->id)->first();
// mocked classes
$accountRepos = $this->mock(AccountRepositoryInterface::class);

View File

@@ -90,7 +90,7 @@ class TransactionJournalMetaFactoryTest extends TestCase
'data' => 'bye!',
]
);
$count = $journal->transactionJournalMeta()->count();
$count = $journal->transactionJournalMeta()->count();
$set = [
'journal' => $journal,
@@ -101,7 +101,7 @@ class TransactionJournalMetaFactoryTest extends TestCase
$factory = app(TransactionJournalMetaFactory::class);
$factory->updateOrCreate($set);
$this->assertEquals($count-1, $journal->transactionJournalMeta()->count());
$this->assertEquals($count - 1, $journal->transactionJournalMeta()->count());
}
/**

View File

@@ -169,7 +169,7 @@ class AmountCreditTest extends TestCase
foreach ($values as $value => $expected) {
$converter = new AmountCredit;
$result = $converter->convert($value);
//$this->assertEquals($expected, $result, sprintf('The original value was %s, expected was %s', $value, $expected));
//$this->assertEquals($expected, $result, sprintf('The original value was %s, expected was %s', $value, $expected));
}
}

View File

@@ -28,8 +28,8 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\SpectreRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
use Mockery;
use Tests\TestCase;
@@ -39,37 +39,6 @@ use Tests\TestCase;
*/
class SpectreRoutineTest extends TestCase
{
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunDoAuthenticate(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR1A' . random_int(1, 10000);
$job->status = 'ready_to_run';
$job->stage = 'do-authenticate';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
@@ -108,6 +77,37 @@ class SpectreRoutineTest extends TestCase
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/
public function testRunDoAuthenticate(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR1A' . random_int(1, 10000);
$job->status = 'ready_to_run';
$job->stage = 'do-authenticate';
$job->provider = 'spectre';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock handler and repository
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls for repository
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
$routine = new SpectreRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
/**
* @covers \FireflyIII\Import\Routine\SpectreRoutine
*/

View File

@@ -112,7 +112,9 @@ class AbnAmroDescriptionTest extends TestCase
*/
public function testSepaBasic(): void
{
$row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: 1232138 1232131233 412321 iBOOD.com iBOOD.com B.V. Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
$row = [0, 1, 2, 3, 4, 5, 6,
'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: 1232138 1232131233 412321 iBOOD.com iBOOD.com B.V. Kenmerk: 12-12-2014 21:03 002000 0213123238',
'', ''];
$parser = new AbnAmroDescription;
$result = $parser->run($row);
$this->assertEquals('1232138 1232131233 412321 iBOOD.com iBOOD.com B.V.', $result[7]);
@@ -127,7 +129,9 @@ class AbnAmroDescriptionTest extends TestCase
*/
public function testSepaBasicNoDescription(): void
{
$row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
$row = [0, 1, 2, 3, 4, 5, 6,
'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: Kenmerk: 12-12-2014 21:03 002000 0213123238',
'', ''];
$parser = new AbnAmroDescription;
$result = $parser->run($row);
$this->assertEquals(' PLAIN: SEPA iDEAL - Silver Ocean B.V. (12-12-2014)', $result[7]);
@@ -140,23 +144,27 @@ class AbnAmroDescriptionTest extends TestCase
*
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
*/
public function testTRTPBasic(): void {
public function testTRTPBasic(): void
{
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI/Nullijn/EREF/NOTPROVIDED', '',''];
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI/Nullijn/EREF/NOTPROVIDED', '',
''];
$parser = new AbnAmroDescription;
$result = $parser->run($row);
$this->assertEquals('Nullijn', $result[7]);
$this->assertEquals('baasd dsdsT CJ', $result[8]);
$this->assertEquals('NL23ABNA0000000000', $result[9]);
}
/**
* Basic TRTP data with empty description
*
* @covers \FireflyIII\Import\Specifics\AbnAmroDescription
*/
public function testTRTPEmptyDescr(): void {
public function testTRTPEmptyDescr(): void
{
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI//EREF/NOTPROVIDED', '',''];
$row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI//EREF/NOTPROVIDED', '', ''];
$parser = new AbnAmroDescription;
$result = $parser->run($row);
$this->assertEquals('SEPA OVERBOEKING - (NOTPROVIDED)', $result[7]);

View File

@@ -32,6 +32,52 @@ use Tests\TestCase;
*/
class IngDescriptionTest extends TestCase
{
/**
* Test changes to BA row.
*
* Remove specific fields.
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunBABasic(): void
{
$row = [0, 'XX', 2, '', 'BA', 5, 6, 7, 'XX', 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('XX XX', $result[8]);
}
/**
* Empty description? Use "tegenrekening".
* Remove specific fields.
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunEmptyDescr(): void
{
$row = [0, 1, 2, '', 'GT', 5, 6, 7, 'Naar Oranje Spaarrekening Bla bla', 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('Bla bla', $result[3]);
}
/**
* See if the description is removed
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunGTRemoveDescr(): void
{
$iban = 'NL66INGB0665877351';
$row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Bla bla bla Omschrijving: Should be removed IBAN: ' . $iban, 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('Should be removed', $result[8]);
}
/**
* Try if the IBAN is removed in GT transactions
*
@@ -47,21 +93,6 @@ class IngDescriptionTest extends TestCase
$this->assertEquals('Should be removed', $result[8]);
}
/**
* Try if the IBAN is removed in OV transactions
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunOVRemoveIban(): void
{
$iban = 'NL66INGB0665877351';
$row = [0, 1, 2, $iban, 'OV', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('Should be removed', $result[8]);
}
/**
* Try if the IBAN is removed in IC transactions
*
@@ -78,44 +109,14 @@ class IngDescriptionTest extends TestCase
}
/**
* Empty description? Use "tegenrekening".
* Remove specific fields.
* Try if the IBAN is removed in OV transactions
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunEmptyDescr(): void
{
$row = [0, 1, 2, '', 'GT', 5, 6, 7, 'Naar Oranje Spaarrekening Bla bla', 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('Bla bla', $result[3]);
}
/**
* Test changes to BA row.
*
* Remove specific fields.
*
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunBABasic(): void
{
$row = [0, 'XX', 2, '', 'BA', 5, 6, 7, 'XX', 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);
$this->assertEquals('XX XX', $result[8]);
}
/**
* See if the description is removed
* @covers \FireflyIII\Import\Specifics\IngDescription
*/
public function testRunGTRemoveDescr(): void
public function testRunOVRemoveIban(): void
{
$iban = 'NL66INGB0665877351';
$row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Bla bla bla Omschrijving: Should be removed IBAN: ' . $iban, 9, 10];
$row = [0, 1, 2, $iban, 'OV', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
$parser = new IngDescription;
$result = $parser->run($row);

View File

@@ -36,20 +36,9 @@ class PresidentsChoiceTest extends TestCase
/**
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
*/
public function testRunBasic():void {
$row = [''];
$parser = new PresidentsChoice;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
/**
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
*/
public function testRunAmount():void {
$row = ['','Descr','12.34','',''];
public function testRunAmount(): void
{
$row = ['', 'Descr', '12.34', '', ''];
$parser = new PresidentsChoice;
$result = $parser->run($row);
@@ -58,4 +47,17 @@ class PresidentsChoiceTest extends TestCase
}
/**
* @covers \FireflyIII\Import\Specifics\PresidentsChoice
*/
public function testRunBasic(): void
{
$row = [''];
$parser = new PresidentsChoice;
$result = $parser->run($row);
$this->assertEquals($row, $result);
}
}

View File

@@ -155,8 +155,6 @@ class ImportArrayStorageTest extends TestCase
$collector->shouldReceive('addFilter')->andReturnSelf();
$storage = new ImportArrayStorage;
$storage->setImportJob($job);
$result = new Collection;
@@ -409,7 +407,6 @@ class ImportArrayStorageTest extends TestCase
$journalRepos->shouldReceive('findByHash')->andReturn(null)->times(2);
$storage = new ImportArrayStorage;
$storage->setImportJob($job);
$result = new Collection;

View File

@@ -23,10 +23,11 @@ declare(strict_types=1);
namespace Tests\Unit\Middleware;
use Log;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
use Log;
/**
* Class AuthenticateTest
*/

View File

@@ -534,7 +534,7 @@ class BinderTest extends TestCase
);
// mock fiscal helper:
$date = new Carbon;
$date = new Carbon;
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();

View File

@@ -44,15 +44,6 @@ class IsDemoUserTest extends TestCase
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser
*/
public function testMiddlewareNotAuthenticated(): void
{
$response = $this->get('/_test/is-demo');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser
*/
@@ -64,6 +55,15 @@ class IsDemoUserTest extends TestCase
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser
*/
public function testMiddlewareNotAuthenticated(): void
{
$response = $this->get('/_test/is-demo');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* Set up test
*/

View File

@@ -25,10 +25,10 @@ namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\Sandstorm;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Mockery;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
use Mockery;
/**
* Class RangeTest

View File

@@ -159,7 +159,7 @@ class TransactionUpdateServiceTest extends TestCase
{
/** @var Transaction $source */
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
$data = [
$data = [
'currency_id' => 1,
'currency_code' => null,
'description' => 'Some new description',
@@ -187,7 +187,6 @@ class TransactionUpdateServiceTest extends TestCase
$result = $service->update($source, $data);
$this->assertEquals($source->id, $result->id);
$this->assertEquals($result->description, $data['description']);
$this->assertEquals($data['foreign_amount'], $result->foreign_amount);
@@ -202,7 +201,7 @@ class TransactionUpdateServiceTest extends TestCase
{
/** @var Transaction $source */
$source = $this->user()->transactions()->where('amount', '<', 0)->inRandomOrder()->first();
$data = [
$data = [
'currency_id' => 1,
'currency_code' => null,
'description' => 'Some new description',

View File

@@ -287,10 +287,10 @@ class ChooseAccountsHandlerTest extends TestCase
// data:
$data = ['account_mapping' => [], 'apply_rules' => true,];
$config = [
'accounts' => [
'accounts' => [
0 => ['id' => 1234, 'name' => 'bunq'],
],
'apply-rules' => true,
'apply-rules' => true,
];

View File

@@ -27,7 +27,6 @@ namespace Tests\Unit\Support\Import\JobConfiguration\Bunq;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler;
use Mockery;
use Tests\TestCase;
class NewBunqJobHandlerTest extends TestCase

View File

@@ -43,6 +43,7 @@ class DoAuthenticateHandlerTest extends TestCase
{
/**
* No token in config, but grab it from users preferences.
*
* @covers \FireflyIII\Support\Import\Information\GetSpectreTokenTrait
* @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler
*/

View File

@@ -69,6 +69,48 @@ class CurrencyMapperTest extends TestCase
$this->assertNull($result);
}
/**
* @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
*/
public function testEmpty(): void
{
// mock data
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
$result = $mapper->map(null, []);
$this->assertNull($result);
}
/**
* @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
*/
public function testFindAndCreate(): void
{
$currency = TransactionCurrency::inRandomOrder()->first();
// mock data
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findBySymbolNull')->withArgs([$currency->symbol])->andReturn(null)->once();
$repository->shouldReceive('findByCodeNull')->withArgs([$currency->code])->andReturn(null)->once();
$repository->shouldReceive('findByNameNull')->withArgs([$currency->name])->andReturn(null)->once();
// nothing found, mapper will try to create it.
$repository->shouldReceive('store')
->withArgs([['code' => $currency->code, 'name' => $currency->name, 'symbol' => $currency->symbol, 'decimal_places' => 2]])
->once()->andReturn($currency);
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
$result = $mapper->map(null, ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol]);
$this->assertEquals($currency->id, $result->id);
}
/**
* @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
*/
@@ -79,7 +121,7 @@ class CurrencyMapperTest extends TestCase
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByCodeNull')->withArgs([$currency->code])
->andReturn($currency)->once();
->andReturn($currency)->once();
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
@@ -126,46 +168,4 @@ class CurrencyMapperTest extends TestCase
$this->assertEquals($currency->id, $result->id);
}
/**
* @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
*/
public function testFindAndCreate(): void
{
$currency = TransactionCurrency::inRandomOrder()->first();
// mock data
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findBySymbolNull')->withArgs([$currency->symbol])->andReturn(null)->once();
$repository->shouldReceive('findByCodeNull')->withArgs([$currency->code])->andReturn(null)->once();
$repository->shouldReceive('findByNameNull')->withArgs([$currency->name])->andReturn(null)->once();
// nothing found, mapper will try to create it.
$repository->shouldReceive('store')
->withArgs([['code' => $currency->code, 'name' => $currency->name, 'symbol' => $currency->symbol,'decimal_places'=>2]])
->once()->andReturn($currency);
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
$result = $mapper->map(null, ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol]);
$this->assertEquals($currency->id, $result->id);
}
/**
* @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
*/
public function testEmpty(): void
{
// mock data
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
$result = $mapper->map(null, []);
$this->assertNull($result);
}
}

View File

@@ -39,7 +39,7 @@ class ImportableCreatorTest extends TestCase
*/
public function testConvertSets(): void
{
$columnValue =new ColumnValue();
$columnValue = new ColumnValue();
$columnValue->setOriginalRole('account-name');
$columnValue->setRole('account-id');
$columnValue->setValue('Checking Account');
@@ -47,13 +47,13 @@ class ImportableCreatorTest extends TestCase
$input = [
[
$columnValue
]
$columnValue,
],
];
$creator = new ImportableCreator;
$result = $creator->convertSets($input);
$result = $creator->convertSets($input);
$this->assertCount(1, $result);
$this->assertInstanceOf(ImportTransaction::class, $result[0]);

View File

@@ -103,7 +103,7 @@ class MappingConvergerTest extends TestCase
5 => 'USD',
6 => 'SomeNumber',
7 => 'I am a description',
8 => 'IBANX'
8 => 'IBANX',
],
[
0 => 'CheckingX Account',
@@ -114,7 +114,7 @@ class MappingConvergerTest extends TestCase
5 => 'USA',
6 => 'SomeANumber',
7 => 'I am X description',
8 => 'IBANXX'
8 => 'IBANXX',
],
];

View File

@@ -62,7 +62,7 @@ class OpposingAccountMapperTest extends TestCase
*/
public function testAccountIdBadType(): void
{
$expected = $this->user()->accounts()->where('account_type_id', 5)->inRandomOrder()->first();
$expected = $this->user()->accounts()->where('account_type_id', 5)->inRandomOrder()->first();
$expected->iban = null;
$expected->save();
$amount = '-12.34';
@@ -160,30 +160,6 @@ class OpposingAccountMapperTest extends TestCase
$mapper->map(null, $amount, []);
}
/**
* Amount = negative
* ID = null
* other data = null
* Should call store() with "(no name") for expense account
*
* @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
*/
public function testFindByAccountNumber(): void
{
$expected = $this->user()->accounts()->where('account_type_id', 4)->inRandomOrder()->first();
$amount = '-12.34';
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByAccountNumber')->withArgs(['12345', [AccountType::EXPENSE]])
->andReturn($expected)->once();
$mapper = new OpposingAccountMapper;
$mapper->setUser($this->user());
$result = $mapper->map(null, $amount, ['number' => '12345']);
$this->assertEquals($result->id, $expected->id);
}
/**
* Amount = positive
* ID = null
@@ -216,4 +192,28 @@ class OpposingAccountMapperTest extends TestCase
$mapper->map(null, $amount, []);
}
/**
* Amount = negative
* ID = null
* other data = null
* Should call store() with "(no name") for expense account
*
* @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
*/
public function testFindByAccountNumber(): void
{
$expected = $this->user()->accounts()->where('account_type_id', 4)->inRandomOrder()->first();
$amount = '-12.34';
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByAccountNumber')->withArgs(['12345', [AccountType::EXPENSE]])
->andReturn($expected)->once();
$mapper = new OpposingAccountMapper;
$mapper->setUser($this->user());
$result = $mapper->map(null, $amount, ['number' => '12345']);
$this->assertEquals($result->id, $expected->id);
}
}

View File

@@ -56,7 +56,7 @@ class ClearBudgetTest extends TestCase
$this->assertEquals(0, $journal->budgets()->count());
/** @var Transaction $transaction */
foreach($journal->transactions as $transaction) {
foreach ($journal->transactions as $transaction) {
$this->assertEquals(0, $transaction->budgets()->count());
}

View File

@@ -56,7 +56,7 @@ class ClearCategoryTest extends TestCase
$this->assertEquals(0, $journal->categories()->count());
/** @var Transaction $transaction */
foreach($journal->transactions as $transaction) {
foreach ($journal->transactions as $transaction) {
$this->assertEquals(0, $transaction->categories()->count());
}
}

View File

@@ -86,11 +86,11 @@ class BudgetIsTest extends TestCase
/** @var Collection $transactions */
$transactions = $journal->transactions()->get();
$budget = $journal->user->budgets()->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
/** @var Transaction $transaction */
foreach($transactions as $transaction) {
foreach ($transactions as $transaction) {
$transaction->budgets()->detach();
$transaction->budgets()->save($budget);
$this->assertEquals(1, $transaction->budgets()->count());

View File

@@ -92,8 +92,8 @@ class FromAccountEndsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = FromAccountEnds::willMatchEverything($value);
$value = '';
$result = FromAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -103,8 +103,8 @@ class FromAccountEndsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = FromAccountEnds::willMatchEverything($value);
$value = 'x';
$result = FromAccountEnds::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -114,8 +114,8 @@ class FromAccountEndsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = FromAccountEnds::willMatchEverything($value);
$value = null;
$result = FromAccountEnds::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@@ -27,7 +27,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
/**
* Class FromAccountIsTest
*/
@@ -76,8 +76,8 @@ class FromAccountIsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = FromAccountIs::willMatchEverything($value);
$value = '';
$result = FromAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -87,8 +87,8 @@ class FromAccountIsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = FromAccountIs::willMatchEverything($value);
$value = 'x';
$result = FromAccountIs::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -98,8 +98,8 @@ class FromAccountIsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = FromAccountIs::willMatchEverything($value);
$value = null;
$result = FromAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@@ -103,8 +103,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = FromAccountStarts::willMatchEverything($value);
$value = '';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -114,8 +114,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = FromAccountStarts::willMatchEverything($value);
$value = 'x';
$result = FromAccountStarts::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -125,8 +125,8 @@ class FromAccountStartsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = FromAccountStarts::willMatchEverything($value);
$value = null;
$result = FromAccountStarts::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@@ -38,9 +38,9 @@ class HasAttachmentTest extends TestCase
{
do {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
} while($count !== 0);
$count = $journal->attachments()->count();
} while ($count !== 0);
$attachment = $journal->user->attachments()->first();
$journal->attachments()->save($attachment);
$this->assertEquals(1, $journal->attachments()->count());
@@ -58,8 +58,8 @@ class HasAttachmentTest extends TestCase
do {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
} while($count !== 0);
$count = $journal->attachments()->count();
} while ($count !== 0);
$this->assertEquals(0, $journal->attachments()->count());

View File

@@ -74,8 +74,8 @@ class HasNoBudgetTest extends TestCase
{
$loopCount = 0;
do {
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($loopCount < 30 && $count !== 2);
$transactions = $journal->transactions()->get();

View File

@@ -77,8 +77,8 @@ class ToAccountContainsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = ToAccountContains::willMatchEverything($value);
$value = '';
$result = ToAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -88,8 +88,8 @@ class ToAccountContainsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = ToAccountContains::willMatchEverything($value);
$value = 'x';
$result = ToAccountContains::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -99,8 +99,8 @@ class ToAccountContainsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = ToAccountContains::willMatchEverything($value);
$value = null;
$result = ToAccountContains::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@@ -26,7 +26,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**

View File

@@ -27,7 +27,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
/**
* Class ToAccountIsTest
@@ -48,7 +47,6 @@ class ToAccountIsTest extends TestCase
$repository->shouldReceive('getJournalDestinationAccounts')->once()->andReturn($collection);
$trigger = ToAccountIs::makeFromStrings($account->name, false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
@@ -78,8 +76,8 @@ class ToAccountIsTest extends TestCase
public function testWillMatchEverythingEmpty(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = '';
$result = ToAccountIs::willMatchEverything($value);
$value = '';
$result = ToAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
@@ -89,8 +87,8 @@ class ToAccountIsTest extends TestCase
public function testWillMatchEverythingNotNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = 'x';
$result = ToAccountIs::willMatchEverything($value);
$value = 'x';
$result = ToAccountIs::willMatchEverything($value);
$this->assertFalse($result);
}
@@ -100,8 +98,8 @@ class ToAccountIsTest extends TestCase
public function testWillMatchEverythingNull(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$value = null;
$result = ToAccountIs::willMatchEverything($value);
$value = null;
$result = ToAccountIs::willMatchEverything($value);
$this->assertTrue($result);
}
}

View File

@@ -26,7 +26,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**

View File

@@ -25,7 +25,6 @@ namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Note;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Transformers\BillTransformer;
use Illuminate\Support\Collection;