Improve test coverage.

This commit is contained in:
James Cole 2019-08-03 04:46:47 +02:00
parent 00dee03709
commit 40dd2e0f7f
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
21 changed files with 118 additions and 410 deletions

View File

@ -1,7 +1,7 @@
sudo: required
language: bash
env:
- VERSION=4.7.17.5
- VERSION=4.8.0
dist: xenial

View File

@ -50,6 +50,7 @@
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
</testsuite>
<testsuite name="Feature">

View File

@ -50,6 +50,7 @@
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>

View File

@ -38,6 +38,7 @@
</testsuite>
<!-- unit tests, splitted: -->
<testsuite name="Unit">
<!--
<directory suffix="Test.php">./tests/Unit/Console</directory>
<directory suffix="Test.php">./tests/Unit/Factory</directory>
<directory suffix="Test.php">./tests/Unit/Generator</directory>
@ -50,6 +51,8 @@
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
-->
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>

View File

@ -435,7 +435,7 @@ class AccountControllerTest extends TestCase
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1), null);
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro(), null);
$generator->shouldReceive('multiSet')->andReturn([]);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
@ -482,7 +482,7 @@ class AccountControllerTest extends TestCase
Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
// currency should be looking for the currency ID's:
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($this->getEuro());
$currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));
$generator->shouldReceive('multiSet')->andReturn([])->once();

View File

@ -66,7 +66,7 @@ class BillControllerTest extends TestCase
2 => '100',
];
$currencyRepos->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1))->withArgs([1]);
$currencyRepos->shouldReceive('findNull')->once()->andReturn($this->getEuro())->withArgs([1]);
$currencyRepos->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(2))->withArgs([2]);
$repository->shouldReceive('getBillsPaidInRangePerCurrency')->once()->andReturn($amounts);

View File

@ -164,7 +164,7 @@ class CategoryControllerTest extends TestCase
$repository->shouldReceive('spentInPeriodPerCurrency')->times(2)->andReturn($spentData);
$repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentNoCategory);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn($this->getEuro());
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user());

View File

@ -191,7 +191,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -205,7 +205,7 @@ class BoxControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
@ -224,7 +224,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -237,7 +237,7 @@ class BoxControllerTest extends TestCase
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
@ -261,7 +261,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -274,7 +274,7 @@ class BoxControllerTest extends TestCase
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
@ -297,7 +297,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -328,7 +328,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -341,7 +341,7 @@ class BoxControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('0');
@ -360,7 +360,7 @@ class BoxControllerTest extends TestCase
$this->mockDefaultSession();
$result = [
[
'currency' => TransactionCurrency::find(1),
'currency' => $this->getEuro(),
'balance' => '3',
],
];
@ -375,7 +375,7 @@ class BoxControllerTest extends TestCase
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->andReturn($this->getEuro());
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');

View File

@ -74,7 +74,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
@ -102,7 +102,7 @@ class PiggyBankControllerTest extends TestCase
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
@ -292,7 +292,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
Preferences::shouldReceive('mark')->atLeast()->once();
@ -322,7 +322,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
@ -349,7 +349,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
Preferences::shouldReceive('mark')->atLeast()->once();
@ -377,7 +377,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$repository->shouldReceive('canRemoveAmount')->once()->andReturn(false);
@ -404,7 +404,7 @@ class PiggyBankControllerTest extends TestCase
$repetition = PiggyBankRepetition::first();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
$piggyRepos->shouldReceive('getRepetition')->once()->andReturn($repetition);
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
@ -428,7 +428,7 @@ class PiggyBankControllerTest extends TestCase
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');

View File

@ -106,7 +106,7 @@ class EditControllerTest extends TestCase
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
//\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
//\Amount::shouldReceive('getDefaultCurrency')->andReturn($this->getEuro());
$this->be($this->user());

View File

@ -596,7 +596,7 @@ abstract class TestCase extends BaseTestCase
*/
protected function getEuro(): TransactionCurrency
{
return TransactionCurrency::find(1);
return TransactionCurrency::where('code', 'EUR')->first();
}
/**

View File

@ -415,7 +415,7 @@ class RecurrenceFactoryTest extends TestCase
$validator = $this->mock(AccountValidator::class);
// mock calls:
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
$piggyFactory->shouldReceive('setUser')->once();
$piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
@ -521,7 +521,7 @@ class RecurrenceFactoryTest extends TestCase
$validator = $this->mock(AccountValidator::class);
// mock calls:
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
$piggyFactory->shouldReceive('setUser')->once();
$piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn(null);
@ -625,7 +625,7 @@ class RecurrenceFactoryTest extends TestCase
$validator = $this->mock(AccountValidator::class);
// mock calls:
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
$piggyFactory->shouldReceive('setUser')->once();
$piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
@ -730,7 +730,7 @@ class RecurrenceFactoryTest extends TestCase
$accountFactory = $this->mock(AccountFactory::class);
// mock calls:
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->once();
$piggyFactory->shouldReceive('setUser')->once();
$piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);

View File

@ -69,7 +69,7 @@ class NetWorthTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// mock calls to facades
Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn(TransactionCurrency::find(1));
Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn($this->getEuro());
Steam::shouldReceive('balancesByAccounts')->once()->withAnyArgs()->andReturn($balanceInfo);
// mock other calls:
@ -77,7 +77,7 @@ class NetWorthTest extends TestCase
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset');
$currencyRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->times(1);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->times(1);
$helper = new NetWorth();
@ -106,7 +106,7 @@ class NetWorthTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// mock calls to facades
Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn(TransactionCurrency::find(1));
Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn($this->getEuro());
Steam::shouldReceive('balancesByAccounts')->once()->withAnyArgs()->andReturn($balanceInfo);
// mock other calls:
@ -114,7 +114,7 @@ class NetWorthTest extends TestCase
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->times(2)->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->times(2)->andReturn('defaultAsset', 'ccAsset');
$currencyRepos->shouldReceive('setUser')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->times(1);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro())->times(1);
$helper = new NetWorth();

View File

@ -56,7 +56,7 @@ class AccountTransformerTest extends TestCase
{
// mock stuff and get object:
$account = $this->getRandomAsset();
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$parameters = new ParameterBag;
@ -72,9 +72,9 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
// get all kinds of meta values:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
// opening balance:
@ -127,7 +127,7 @@ class AccountTransformerTest extends TestCase
{
// mock stuff and get object:
$account = $this->getRandomAsset();
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transformer = app(AccountTransformer::class);
@ -140,9 +140,9 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
// get all kinds of meta values:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
// opening balance:
@ -195,7 +195,7 @@ class AccountTransformerTest extends TestCase
{
// mock stuff and get object:
$account = $this->getRandomAsset();
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transformer = app(AccountTransformer::class);
@ -208,14 +208,14 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
// get all kinds of meta values:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('ccAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
// credit card fields:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('monthlyFull')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('2018-01-01')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('monthlyFull')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('2018-01-01')->atLeast()->once();
// opening balance:
@ -270,7 +270,7 @@ class AccountTransformerTest extends TestCase
{
// mock stuff and get object:
$account = $this->getRandomAsset();
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transformer = app(AccountTransformer::class);
@ -283,9 +283,9 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
// get all kinds of meta values:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
// data for liability
@ -344,7 +344,7 @@ class AccountTransformerTest extends TestCase
{
// mock stuff and get object:
$account = $this->getRandomExpense();
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transformer = app(AccountTransformer::class);
@ -357,9 +357,9 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();
// get all kinds of meta values:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();
// steam is also called for the account balance:

View File

@ -23,8 +23,11 @@ declare(strict_types=1);
namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Transformers\AvailableBudgetTransformer;
use Illuminate\Support\Collection;
use Log;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
@ -50,6 +53,9 @@ class AvailableBudgetTransformerTest extends TestCase
*/
public function testBasic(): void
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('setUser')->atLeast()->once();
/** @var AvailableBudget $availableBudget */
$availableBudget = AvailableBudget::first();
$currency = $availableBudget->transactionCurrency;
@ -63,7 +69,55 @@ class AvailableBudgetTransformerTest extends TestCase
$this->assertEquals($currency->id, $result['currency_id']);
$this->assertEquals($availableBudget->start_date->format('Y-m-d'), $result['start']);
$this->assertEquals(round($availableBudget->amount, 2), $result['amount']);
}
/**
* Test basic transformer
*
* @covers \FireflyIII\Transformers\AvailableBudgetTransformer
*/
public function testBasicDates(): void
{
$euro = $this->getEuro();
$data= [
[
'currency_id' => $euro->id,
'currency_code' => $euro->code,
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places,
'amount' => '12.45',
]
];
$budget = $this->getRandomBudget();
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn($data);
$repository->shouldReceive('spentInPeriodWoBudgetMc')->atLeast()->once()->andReturn($data);
// spentInPeriodWoBudgetMc
$start = new Carbon;
$end = new Carbon;
$parameterBag = new ParameterBag;
$parameterBag->set('start', $start);
$parameterBag->set('end', $end);
/** @var AvailableBudget $availableBudget */
$availableBudget = AvailableBudget::first();
$currency = $availableBudget->transactionCurrency;
// make transformer
$transformer = app(AvailableBudgetTransformer::class);
$transformer->setParameters($parameterBag);
$result = $transformer->transform($availableBudget);
// test results
$this->assertEquals($availableBudget->id, $result['id']);
$this->assertEquals($currency->id, $result['currency_id']);
$this->assertEquals($availableBudget->start_date->format('Y-m-d'), $result['start']);
$this->assertEquals(round($availableBudget->amount, 2), $result['amount']);
}
}

View File

@ -87,16 +87,16 @@ class CategoryTransformerTest extends TestCase
// mock some objects for the spent/earned lists.
$expense = new Transaction;
$expense->transaction_currency_code = 'EUR';
$expense->transactionCurrency = TransactionCurrency::find(1);
$expense->transactionCurrency = $this->getEuro();
$expense->transaction_amount = '-100';
$income = new Transaction;
$income->transaction_currency_code = 'EUR';
$income->transactionCurrency = TransactionCurrency::find(1);
$income->transactionCurrency = $this->getEuro();
$income->transaction_amount = '100';
$incomeCollection = new Collection([$income]);
$expenseCollection = new Collection([$expense]);
$incomeCollection = [$income];
$expenseCollection = [$expense];
$repository->shouldReceive('spentInPeriodCollection')->atLeast()->once()->andReturn($expenseCollection);
$repository->shouldReceive('earnedInPeriodCollection')->atLeast()->once()->andReturn($incomeCollection);

View File

@ -56,9 +56,6 @@ class PiggyBankEventTransformerTest extends TestCase
*/
public function testBasic(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// repositories
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
@ -70,7 +67,7 @@ class PiggyBankEventTransformerTest extends TestCase
// mock calls:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());
$piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);
$event = PiggyBankEvent::first();
@ -91,9 +88,6 @@ class PiggyBankEventTransformerTest extends TestCase
*/
public function testNoCurrency(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// repositories
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
@ -108,7 +102,7 @@ class PiggyBankEventTransformerTest extends TestCase
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);
$piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->atLeast()->once();
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->atLeast()->once();
$event = PiggyBankEvent::first();
$transformer = app(PiggyBankEventTransformer::class);

View File

@ -68,7 +68,7 @@ class PiggyBankTransformerTest extends TestCase
// return a currency
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());
// get a note
$piggyRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('I am a note.');
@ -109,7 +109,7 @@ class PiggyBankTransformerTest extends TestCase
// return a currency
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn(TransactionCurrency::find(1));
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($this->getEuro());
// get a note
$piggyRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('I am a note.');

View File

@ -60,9 +60,6 @@ class RecurrenceTransformerTest extends TestCase
*/
public function testBasic(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$recurrenceRepos = $this->mock(RecurringRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);

View File

@ -42,9 +42,6 @@ class TransactionLinkTransformerTest extends TestCase
*/
public function testBasic(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('getLinkNoteText')->atLeast()->once()->andReturn('abc');

View File

@ -1,339 +0,0 @@
<?php
/**
* TransactionTransformerTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Mockery;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
/**
* Class TransactionTransformerTest
*/
class TransactionTransformerTest extends TestCase
{
/**
* Test basic transaction transformer.
*
* @covers \FireflyIII\Transformers\TransactionTransformer
*/
public function testBasic(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$repository = $this->mock(JournalRepositoryInterface::class);
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag());
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('getNoteText')->once()->andReturn('Notes');
// all meta fields:
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-cc'])->andReturn('a')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-op'])->andReturn('b')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-ud'])->andReturn('c')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-db'])->andReturn('d')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-country'])->andReturn('e')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ep'])->andReturn('f')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ci'])->andReturn('g')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-batch-id'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'internal_reference'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'bunq_payment_id'])->andReturn('12345')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'importHashV2'])->andReturn('abcdef')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'recurrence_id'])->andReturn('5')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'external_id'])->andReturn('1')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'original-source'])->andReturn('test')->atLeast()->once();
// all meta dates.
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'interest_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'book_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'process_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'due_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'payment_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'invoice_date'])->andReturn('2018-01-01')->atLeast()->once();
// get tags
$repository->shouldReceive('getTags')->once()->andReturn(['a', 'b']);
// create fake transaction object:
$transaction = new Transaction;
$journal = TransactionJournal::find(1);
// fill transaction with details
$transaction->transactionJournal = $journal;
$transaction->created_at = new Carbon;
$transaction->updated_at = new Carbon;
$transaction->description = '';
$transaction->transaction_description = '';
$transaction->date = new Carbon;
$transaction->identifier = 0;
$transaction->journal_id = 1;
$transaction->reconciled = false;
$transaction->transaction_amount = '123.456';
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_code = 'EUR';
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_dp = 2;
$transaction->bill_id = 1;
$transaction->bill_name = 'Bill';
$transaction->transaction_type_type = 'Withdrawal';
$transaction->transaction_budget_id = 1;
$transaction->transaction_budget_name = 'X';
$transaction->transaction_category_id = 2;
$transaction->transaction_category_name = 'xab';
// account info (for a withdrawal):
$transaction->account_id = 1;
$transaction->account_name = 'Some source';
$transaction->account_iban = 'IBAN';
$transaction->account_type = 'Asset account';
$transaction->opposing_account_id = 3;
$transaction->opposing_account_name = 'Some destination';
$transaction->opposing_account_iban = 'IBAN2';
$transaction->opposing_account_type = 'Expense';
// next test: foreign currency info.
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($transaction);
$this->assertEquals('Some source', $result['source_name']);
}
/**
* Test deposit. Budget should be null, despite the link.
*
* @covers \FireflyIII\Transformers\TransactionTransformer
*/
public function testDeposit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$repository = $this->mock(JournalRepositoryInterface::class);
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag());
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('getNoteText')->once()->andReturn('Notes');
// all meta fields:
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-cc'])->andReturn('a')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-op'])->andReturn('b')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-ud'])->andReturn('c')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-db'])->andReturn('d')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-country'])->andReturn('e')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ep'])->andReturn('f')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ci'])->andReturn('g')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-batch-id'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'internal_reference'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'bunq_payment_id'])->andReturn('12345')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'importHashV2'])->andReturn('abcdef')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'recurrence_id'])->andReturn('5')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'external_id'])->andReturn('1')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'original-source'])->andReturn('test')->atLeast()->once();
// all meta dates.
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'interest_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'book_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'process_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'due_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'payment_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'invoice_date'])->andReturn('2018-01-01')->atLeast()->once();
// get tags
$repository->shouldReceive('getTags')->once()->andReturn(['a', 'b']);
// create fake transaction object:
$transaction = new Transaction;
$journal = TransactionJournal::find(1);
// fill transaction with details
$transaction->transactionJournal = $journal;
$transaction->created_at = new Carbon;
$transaction->updated_at = new Carbon;
$transaction->description = 'Some description';
$transaction->transaction_description = 'Some expanded description';
$transaction->date = new Carbon;
$transaction->identifier = 0;
$transaction->journal_id = 1;
$transaction->reconciled = false;
$transaction->transaction_amount = '123.456';
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_code = 'EUR';
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_dp = 2;
$transaction->bill_id = 1;
$transaction->bill_name = 'Bill';
$transaction->transaction_type_type = 'Deposit';
$transaction->transaction_budget_id = 1;
$transaction->transaction_budget_name = 'X';
$transaction->transaction_category_id = 2;
$transaction->transaction_category_name = 'xab';
// foreign amount info:
$transaction->transaction_foreign_amount = '456.789';
$transaction->foreign_currency_dp = 2;
$transaction->foreign_currency_code = 'USD';
$transaction->foreign_currency_symbol = 'x';
// account info (for a withdrawal):
$transaction->account_id = 1;
$transaction->account_name = 'Some source';
$transaction->account_iban = 'IBAN';
$transaction->account_type = 'Asset account';
$transaction->opposing_account_id = 3;
$transaction->opposing_account_name = 'Some destination';
$transaction->opposing_account_iban = 'IBAN2';
$transaction->opposing_account_type = 'Expense';
// next test: foreign currency info.
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($transaction);
$this->assertEquals('Some destination', $result['source_name']);
$this->assertEquals(456.79, $result['foreign_amount']);
$this->assertEquals('Some expanded description', $result['transaction_description']);
$this->assertEquals('Some description', $result['journal_description']);
$this->assertEquals('Some expanded description (Some description)', $result['description']);
$this->assertNull($result['budget_id']);
$this->assertNull($result['budget_name']);
}
/**
* Test transformer with foreign amount info.
*
* @covers \FireflyIII\Transformers\TransactionTransformer
*/
public function testForeign(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$repository = $this->mock(JournalRepositoryInterface::class);
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag());
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('getNoteText')->once()->andReturn('Notes');
// all meta fields:
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-cc'])->andReturn('a')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-op'])->andReturn('b')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ct-ud'])->andReturn('c')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-db'])->andReturn('d')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-country'])->andReturn('e')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ep'])->andReturn('f')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-ci'])->andReturn('g')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'sepa-batch-id'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'internal_reference'])->andReturn('h')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'bunq_payment_id'])->andReturn('12345')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'importHashV2'])->andReturn('abcdef')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'recurrence_id'])->andReturn('5')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'external_id'])->andReturn('1')->atLeast()->once();
$repository->shouldReceive('getMetaField')->withArgs([Mockery::any(), 'original-source'])->andReturn('test')->atLeast()->once();
// all meta dates.
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'interest_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'book_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'process_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'due_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'payment_date'])->andReturn('2018-01-01')->atLeast()->once();
$repository->shouldReceive('getMetaDateString')->withArgs([Mockery::any(), 'invoice_date'])->andReturn('2018-01-01')->atLeast()->once();
// get tags
$repository->shouldReceive('getTags')->once()->andReturn(['a', 'b']);
// create fake transaction object:
$transaction = new Transaction;
$journal = TransactionJournal::find(1);
// fill transaction with details
$transaction->transactionJournal = $journal;
$transaction->created_at = new Carbon;
$transaction->updated_at = new Carbon;
$transaction->description = 'Some description';
$transaction->transaction_description = 'Some expanded description';
$transaction->date = new Carbon;
$transaction->identifier = 0;
$transaction->journal_id = 1;
$transaction->reconciled = false;
$transaction->transaction_amount = '123.456';
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_code = 'EUR';
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_dp = 2;
$transaction->bill_id = 1;
$transaction->bill_name = 'Bill';
$transaction->transaction_type_type = 'Withdrawal';
$transaction->transaction_budget_id = 1;
$transaction->transaction_budget_name = 'X';
$transaction->transaction_category_id = 2;
$transaction->transaction_category_name = 'xab';
// foreign amount info:
$transaction->transaction_foreign_amount = '456.789';
$transaction->foreign_currency_dp = 2;
$transaction->foreign_currency_code = 'USD';
$transaction->foreign_currency_symbol = 'x';
// account info (for a withdrawal):
$transaction->account_id = 1;
$transaction->account_name = 'Some source';
$transaction->account_iban = 'IBAN';
$transaction->account_type = 'Asset account';
$transaction->opposing_account_id = 3;
$transaction->opposing_account_name = 'Some destination';
$transaction->opposing_account_iban = 'IBAN2';
$transaction->opposing_account_type = 'Expense';
// next test: foreign currency info.
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($transaction);
$this->assertEquals('Some source', $result['source_name']);
$this->assertEquals(456.79, $result['foreign_amount']);
$this->assertEquals('Some expanded description', $result['transaction_description']);
$this->assertEquals('Some description', $result['journal_description']);
$this->assertEquals('Some expanded description (Some description)', $result['description']);
}
}