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,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);
}
}