Expand test code.

This commit is contained in:
James Cole 2021-03-19 06:12:28 +01:00
parent b4d44fdd2b
commit 03d3ede036
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
37 changed files with 1343 additions and 1187 deletions

View File

@ -36,7 +36,7 @@
</coverage> </coverage>
<testsuites> <testsuites>
<testsuite name="Api"> <testsuite name="Api">
<directory suffix="Test.php">./tests/Api/Models</directory> <directory suffix="Test.php">./tests/Api/Models/Account</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<php> <php>

View File

@ -22,9 +22,9 @@
namespace Tests\Api\Autocomplete; namespace Tests\Api\Autocomplete;
use Tests\TestCase;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use Log; use Log;
use Tests\TestCase;
/** /**
* Class AccountControllerTest * Class AccountControllerTest
@ -41,14 +41,6 @@ class AccountControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
*
*/
public function testBasic(): void
{
$this->assertTrue(true);
}
/** /**
* @covers \FireflyIII\Api\V1\Controllers\Autocomplete\AccountController * @covers \FireflyIII\Api\V1\Controllers\Autocomplete\AccountController
*/ */
@ -60,4 +52,12 @@ class AccountControllerTest extends TestCase
$response->assertHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
} }
/**
*
*/
public function testBasic(): void
{
$this->assertTrue(true);
}
} }

View File

@ -22,14 +22,11 @@
namespace Tests\Api\Models\Account; namespace Tests\Api\Models\Account;
use Faker\Factory;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use Log; use Log;
use Tests\Objects\Field; use Tests\Objects\Field;
use Tests\Objects\FieldSet; use Tests\Objects\FieldSet;
use Tests\Objects\TestConfiguration; use Tests\Objects\TestConfiguration;
use Tests\Objects\TestMandatoryField;
use Tests\Objects\TestMandatoryFieldSet;
use Tests\TestCase; use Tests\TestCase;
use Tests\Traits\CollectsValues; use Tests\Traits\CollectsValues;
use Tests\Traits\RandomValues; use Tests\Traits\RandomValues;
@ -42,6 +39,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -54,323 +60,161 @@ class StoreControllerTest extends TestCase
/** /**
* @param array $submission * @param array $submission
* emptyDataProvider / storeDataProvider
* *
* @dataProvider storeDataProvider * newStoreDataProvider / emptyDataProvider
*
* @dataProvider newStoreDataProvider
*/ */
public function testStore(array $submission): void public function testStore(array $submission): void
{ {
$this->someTestData();
exit;
if ([] === $submission) { if ([] === $submission) {
$this->markTestSkipped('Empty data provider'); $this->markTestSkipped('Empty provider.');
} }
Log::debug('testStoreUpdated()');
Log::debug('submission :', $submission['submission']);
Log::debug('expected :', $submission['expected']);
Log::debug('ignore :', $submission['ignore']);
// run account store with a minimal data set: // run account store with a minimal data set:
$route = 'api.v1.accounts.store'; $address = route('api.v1.accounts.store');
$this->storeAndCompare($route, $submission); $this->updatedStoreAndCompare($address, $submission);
} }
/** /**
* @return array * @return array
*/ */
public function emptyDataProvider(): array public function newStoreDataProvider(): array
{ {
return [[[]]]; // some test configs:
$configuration = new TestConfiguration;
} // default asset account test set:
$defaultAssetSet = new FieldSet();
$defaultAssetSet->title = 'default_asset_account';
$defaultAssetSet->addField(Field::createBasic('name', 'uuid'));
$defaultAssetSet->addField(Field::createBasic('type', 'static-asset'));
$defaultAssetSet->addField(Field::createBasic('account_role', 'random-asset-accountRole'));
$configuration->addMandatoryFieldSet($defaultAssetSet);
/** // expense test set:
* @return array $expenseSet = new FieldSet();
*/ $expenseSet->title = 'expense_account';
public function storeDataProvider(): array $expenseSet->addField(Field::createBasic('name', 'uuid'));
{
$minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets();
$regenConfig = [
'name' => function () {
$faker = Factory::create();
return $faker->uuid; // to make sure expense set ignores the opening balance fields:
}, $field = new Field;
'iban' => function () { $field->title = 'type';
$faker = Factory::create(); $field->fieldTitle = 'type';
$field->fieldType = 'static-expense';
$field->ignorableFields = ['opening_balance', 'opening_balance_date', 'virtual_balance', 'order'];
$expenseSet->addField($field);
$configuration->addMandatoryFieldSet($expenseSet);
return $faker->iban(); // liability test set:
}, $fieldSet = new FieldSet();
'account_number' => function () { $fieldSet->title = 'liabilities_account';
$faker = Factory::create(); $fieldSet->addField(Field::createBasic('name', 'uuid'));
$fieldSet->addField(Field::createBasic('type', 'static-liabilities'));
$fieldSet->addField(Field::createBasic('liability_type', 'random-liability-type'));
$fieldSet->addField(Field::createBasic('liability_amount', 'random-amount'));
$fieldSet->addField(Field::createBasic('interest', 'random-percentage'));
$fieldSet->addField(Field::createBasic('interest_period', 'random-interest-period'));
$field = new Field;
$field->fieldTitle = 'liability_start_date';
$field->fieldType = 'random-past-date';
$field->ignorableFields = ['opening_balance', 'opening_balance_date'];
$field->title = 'liability_start_date';
$fieldSet->addField($field);
$configuration->addMandatoryFieldSet($fieldSet);
return $faker->iban(); // credit card set:
}, $fieldSet = new FieldSet();
]; $fieldSet->title = 'cc_account';
$fieldSet->addField(Field::createBasic('name', 'uuid'));
$fieldSet->addField(Field::createBasic('type', 'static-asset'));
$fieldSet->addField(Field::createBasic('account_role', 'static-ccAsset'));
$fieldSet->addField(Field::createBasic('credit_card_type', 'static-monthlyFull'));
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'random-past-date'));
$configuration->addMandatoryFieldSet($fieldSet);
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); // optional field sets (for all test configs)
} $fieldSet = new FieldSet;
$fieldSet->addField(Field::createBasic('active', 'boolean'));
$configuration->addOptionalFieldSet('active', $fieldSet);
/** $fieldSet = new FieldSet;
* @return \array[][] $fieldSet->addField(Field::createBasic('iban', 'iban'));
*/ $configuration->addOptionalFieldSet('iban', $fieldSet);
private function optionalSets(): array
{
$faker = Factory::create();
$currencies = [
1 => 'EUR',
2 => 'HUF',
3 => 'GBP',
4 => 'UAH',
];
$rand = rand(1, 4);
$fieldSet = new FieldSet;
$fieldSet->addField(Field::createBasic('bic', 'bic'));
$configuration->addOptionalFieldSet('bic', $fieldSet);
return [ $fieldSet = new FieldSet;
'active' => [ $fieldSet->addField(Field::createBasic('account_number', 'account_number'));
'fields' => [ $configuration->addOptionalFieldSet('account_number', $fieldSet);
'active' => $faker->boolean,
],
],
'iban' => [
'fields' => [
'iban' => $faker->iban(),
],
],
'bic' => [
'fields' => [
'bic' => $faker->swiftBicNumber,
],
],
'account_number' => [
'fields' => [
'account_number' => $faker->iban(),
],
],
'ob' => [
'fields' => [
'opening_balance' => $this->getRandomAmount(),
'opening_balance_date' => $this->getRandomDateString(),
],
],
'virtual_balance' => [
'fields' => [
'virtual_balance' => $this->getRandomAmount(),
],
],
'currency_id' => [
'fields' => [
'currency_id' => $rand,
],
],
'currency_code' => [
'fields' => [
'currency_code' => $currencies[$rand],
],
],
'order' => [
'fields' => [
'order' => $faker->numberBetween(1, 5),
],
],
'include_net_worth' => [
'fields' => [
'include_net_worth' => $faker->boolean,
],
],
'notes' => [
'fields' => [
'notes' => join(' ', $faker->words(5)),
],
],
'location' => [
'fields' => [
'latitude' => $faker->latitude,
'longitude' => $faker->longitude,
'zoom_level' => $faker->numberBetween(1, 10),
],
],
];
}
/** $fieldSet = new FieldSet;
* @return array $fieldSet->addField(Field::createBasic('opening_balance', 'random-amount'));
*/ $fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
private function minimalSets(): array $configuration->addOptionalFieldSet('ob', $fieldSet);
{
$faker = Factory::create();
return [ $fieldSet = new FieldSet;
'asset' => [ $fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
'parameters' => [], $configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
'fields' => [
'name' => $faker->uuid,
'type' => 'asset',
'account_role' => $this->randomAccountRole(),
],
],
'expense' => [
'parameters' => [],
'fields' => [
'name' => $faker->uuid,
'type' => 'expense',
],
],
'liability' => [
'parameters' => [],
'fields' => [
'name' => $faker->uuid,
'type' => 'liabilities',
'liability_type' => $this->randomLiabilityType(),
'liability_amount' => $this->getRandomAmount(),
'liability_start_date' => $this->getRandomDateString(),
'interest' => $this->getRandomPercentage(),
'interest_period' => $this->getRandomInterestPeriod(),
],
'ignore' => [
'opening_balance', 'opening_balance_date',
],
],
'cc' => [
'fields' => [
'name' => $faker->uuid,
'type' => 'asset',
'account_role' => 'ccAsset',
'credit_card_type' => 'monthlyFull',
'monthly_payment_date' => $this->getRandomDateString(),
], $fieldSet = new FieldSet;
], $field = new Field;
]; $field->fieldTitle = 'currency_id';
} $field->fieldType = 'random-currency-id';
$field->ignorableFields = ['currency_code'];
$field->title = 'currency_id';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
public function someTestData(): void $fieldSet = new FieldSet;
{ $field = new Field;
// a basic test config set contains $field->fieldTitle = 'currency_code';
// mandatory fields and X optional fields $field->fieldType = 'random-currency-code';
// the optional fields will be rotated automatically. $field->ignorableFields = ['currency_id'];
$config = new TestConfiguration; $field->title = 'currency_code';
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
// add a set of mandatory fields: $fieldSet = new FieldSet;
$mandatoryFieldSet = new FieldSet(); $fieldSet->addField(Field::createBasic('order', 'order'));
$mandatoryFieldSet->title = 'default_asset_account'; $configuration->addOptionalFieldSet('order', $fieldSet);
// name $fieldSet = new FieldSet;
$mandatoryField = new Field; $fieldSet->addField(Field::createBasic('include_net_worth', 'boolean'));
$mandatoryField->title = 'name'; $configuration->addOptionalFieldSet('include_net_worth', $fieldSet);
$mandatoryField->fieldTitle = 'name';
$mandatoryField->fieldPosition = ''; // root
$mandatoryField->fieldType = 'uuid'; // refers to a generator or something?
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
$mandatoryField->expectedReturn = null; // or the callback
$mandatoryField->ignorableFields = [];
$mandatoryFieldSet->addField($mandatoryField);
// type $fieldSet = new FieldSet;
$mandatoryField = new Field; $fieldSet->addField(Field::createBasic('notes', 'uuid'));
$mandatoryField->title = 'type'; $configuration->addOptionalFieldSet('notes', $fieldSet);
$mandatoryField->fieldTitle = 'type';
$mandatoryField->fieldPosition = ''; // root
$mandatoryField->fieldType = 'static-asset'; // refers to a generator or something?
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
$mandatoryField->expectedReturn = null; // or the callback
$mandatoryField->ignorableFields = []; // something like transactions/0/currency_code
$mandatoryFieldSet->addField($mandatoryField);
// role $fieldSet = new FieldSet;
$mandatoryField = new Field; $fieldSet->addField(Field::createBasic('latitude', 'latitude'));
$mandatoryField->title = 'role'; $fieldSet->addField(Field::createBasic('longitude', 'longitude'));
$mandatoryField->fieldTitle = 'account_role'; $fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
$mandatoryField->fieldPosition = ''; // root $configuration->addOptionalFieldSet('notes', $fieldSet);
$mandatoryField->fieldType = 'random-asset-accountRole'; // refers to a generator or something?
$mandatoryField->expectedReturnType = 'equal'; // or 'callback'
$mandatoryField->expectedReturn = null; // or the callback
$mandatoryField->ignorableFields = []; // something like transactions/0/currency_code
$mandatoryFieldSet->addField($mandatoryField);
$config->mandatoryFieldSet = $mandatoryFieldSet;
unset($mandatoryField);
// $mandatoryField = new TestMandatoryField;
// $mandatoryField->title = 'transaction_type';
// $mandatoryField->fieldTitle = 'type';
// $mandatoryField->fieldPosition = 'transactions/0'; // not root!
// $mandatoryField->fieldType = 'random-transactionType'; // refers to a generator or something?
// $mandatoryField->expectedReturnType = 'equal'; // or 'callback'
// $mandatoryField->expectedReturn = null; // or the callback
// $mandatoryField->ignorableFields = [];
// $mandatoryFieldSet->addMandatoryField($mandatoryField);
$optionalFieldSet = new FieldSet;
$optionalField = new Field;
$optionalField->title = 'active';
$optionalField->fieldTitle = 'active';
$optionalField->fieldPosition = '';
$optionalField->fieldType = 'boolean'; // refers to a generator or something?
$optionalField->expectedReturnType = 'equal'; // or 'callback'
$optionalField->expectedReturn = null; // or the callback
$optionalField->ignorableFields = []; // something like transactions/0/currency_code
$optionalFieldSet->addField($optionalField, 'active');
$optionalField = new Field;
$optionalField->title = 'iban';
$optionalField->fieldTitle = 'iban';
$optionalField->fieldPosition = '';
$optionalField->fieldType = 'iban'; // refers to a generator or something?
$optionalField->expectedReturnType = 'equal'; // or 'callback'
$optionalField->expectedReturn = null; // or the callback
$optionalField->ignorableFields = []; // something like transactions/0/currency_code
$optionalFieldSet->addField($optionalField, 'iban');
$config->optionalFieldSet = $optionalFieldSet;
// generate submissions // generate submissions
$arr = $config->generateSubmission(); $array = $configuration->generateSubmissions();
var_dump($arr); $expected = $configuration->generateExpected($array);
exit; $ignored = $configuration->ignores;
// generate expected returns.
$set = [ // now create a combination for each submission and associated data:
// set for withdrawal, copy this for $final = [];
// other transaction types etc. foreach ($array as $index => $submission) {
// make a CLASS!! $final[] = [[
'identifier' => [ 'submission' => $submission,
'mandatory_fields' => [ 'expected' => $expected[$index],
'name_of_set' => [ 'ignore' => $ignored[$index],
'fields' => [ ]];
'basic_text_field' => [ }
'test_value' => function () {
return 'callback';
},
'expected_return_value' => function ($input) {
// the same?
return $input;
// a conversion? return $final;
return (string)$input;
// something else entirely?
return 'something else entirely.';
},
'ignore_other_fields' => [
'key_to_ignore',
'sub_array_like_transactions' => [0 => 'field_to_ignore'],
],
],
'another_basic_text_field' => [
// see above for 'test_value', 'expected_return_value' and 'ignore_other_fields'
],
'complex_array_field_like_transactions' => [
'transactions' => [
0 => [
'field_is_here' => [
'test_value' => null, // see above
'expected_return_value' => null, // see above
'ignore_other_fields' => [], // see above
],
],
],
],
],
],
],
// these will be permutated
'optional_fields' => [],
],
];
} }
} }

View File

@ -53,6 +53,7 @@ class UpdateControllerTest extends TestCase
*/ */
public function testUpdate(array $submission): void public function testUpdate(array $submission): void
{ {
$this->markTestSkipped('Skipped');
$ignore = [ $ignore = [
'created_at', 'created_at',
'updated_at', 'updated_at',
@ -151,7 +152,7 @@ class UpdateControllerTest extends TestCase
'virtual_balance' => [ 'virtual_balance' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'virtual_balance' => ['test_value' => number_format($faker->randomFloat(2,10,100), 2)], 'virtual_balance' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
@ -195,7 +196,7 @@ class UpdateControllerTest extends TestCase
'ob' => [ 'ob' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'opening_balance' => ['test_value' => number_format($faker->randomFloat(2,10,100), 2)], 'opening_balance' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
'opening_balance_date' => ['test_value' => $faker->date('Y-m-d')], 'opening_balance_date' => ['test_value' => $faker->date('Y-m-d')],
], ],
'extra_ignore' => [], 'extra_ignore' => [],

View File

@ -37,33 +37,6 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.attachments.store';
$this->storeAndCompare($route, $submission);
}
/** /**
* @return array * @return array
*/ */
@ -73,6 +46,15 @@ class StoreControllerTest extends TestCase
} }
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/** /**
* @return array * @return array
@ -86,7 +68,6 @@ class StoreControllerTest extends TestCase
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
} }
/** /**
* @return array * @return array
*/ */
@ -135,4 +116,21 @@ class StoreControllerTest extends TestCase
], ],
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.attachments.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -110,7 +110,7 @@ class UpdateControllerTest extends TestCase
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'attachable_type' => ['test_value' => 'TransactionJournal'], 'attachable_type' => ['test_value' => 'TransactionJournal'],
'attachable_id' => ['test_value' => (string)2], 'attachable_id' => ['test_value' => (string)2],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.available_budgets.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -85,7 +68,6 @@ class StoreControllerTest extends TestCase
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
} }
/** /**
* @return array * @return array
*/ */
@ -104,7 +86,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -132,4 +113,21 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.available_budgets.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.bills.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -91,7 +74,6 @@ class StoreControllerTest extends TestCase
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
} }
/** /**
* @return array * @return array
*/ */
@ -114,7 +96,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -197,4 +178,21 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.bills.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -140,21 +140,21 @@ class UpdateControllerTest extends TestCase
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'active' => [ 'active' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'active' => ['test_value' => $faker->boolean], 'active' => ['test_value' => $faker->boolean],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'notes' => [ 'notes' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'notes' => ['test_value' => join(' ', $faker->words(5))], 'notes' => ['test_value' => join(' ', $faker->words(5))],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'object_group_id' => [ 'object_group_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'object_group_id' => ['test_value' => (string)$objectGroupId], 'object_group_id' => ['test_value' => (string)$objectGroupId],
@ -168,14 +168,14 @@ class UpdateControllerTest extends TestCase
], ],
'extra_ignore' => ['object_group_order', 'object_group_id'], 'extra_ignore' => ['object_group_order', 'object_group_id'],
], ],
'currency_id' => [ 'currency_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'currency_id' => ['test_value' => (string)$rand], 'currency_id' => ['test_value' => (string)$rand],
], ],
'extra_ignore' => ['currency_code', 'currency_symbol'], 'extra_ignore' => ['currency_code', 'currency_symbol'],
], ],
'currency_code' => [ 'currency_code' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'currency_code' => ['test_value' => $currencies[$rand]], 'currency_code' => ['test_value' => $currencies[$rand]],

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.budgets.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -91,13 +74,13 @@ class StoreControllerTest extends TestCase
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
} }
/** /**
* @return array * @return array
*/ */
private function minimalSets(): array private function minimalSets(): array
{ {
$faker = Factory::create(); $faker = Factory::create();
return [ return [
'default_budget' => [ 'default_budget' => [
'fields' => [ 'fields' => [
@ -107,7 +90,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -130,12 +112,12 @@ class StoreControllerTest extends TestCase
$autoBudgetType = $autoBudgetTypes[rand(0, count($autoBudgetTypes) - 1)]; $autoBudgetType = $autoBudgetTypes[rand(0, count($autoBudgetTypes) - 1)];
return [ return [
'active' => [ 'active' => [
'fields' => [ 'fields' => [
'active' => $faker->boolean, 'active' => $faker->boolean,
], ],
], ],
'auto_budget_id' => [ 'auto_budget_id' => [
'fields' => [ 'fields' => [
'auto_budget_type' => $autoBudgetType, 'auto_budget_type' => $autoBudgetType,
'auto_budget_currency_id' => $rand, 'auto_budget_currency_id' => $rand,
@ -143,16 +125,33 @@ class StoreControllerTest extends TestCase
'auto_budget_period' => $repeatFreq, 'auto_budget_period' => $repeatFreq,
], ],
], ],
'auto_budget_code' => [ 'auto_budget_code' => [
'fields' => [ 'fields' => [
'auto_budget_type' => $autoBudgetType, 'auto_budget_type' => $autoBudgetType,
'auto_budget_currency_code' => $currencies[$rand], 'auto_budget_currency_code' => $currencies[$rand],
'auto_budget_amount' => number_format($faker->randomFloat(2, 10, 100), 2), 'auto_budget_amount' => number_format($faker->randomFloat(2, 10, 100), 2),
'auto_budget_period' => $repeatFreq, 'auto_budget_period' => $repeatFreq,
], ],
] ],
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.budgets.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.budgets.limits.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -115,7 +98,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -160,4 +142,21 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
// run account store with a minimal data set:
$route = 'api.v1.budgets.limits.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -105,7 +105,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'currency_id' => ['test_value' => (string)$rand], 'currency_id' => ['test_value' => (string)$rand],
], ],
'extra_ignore' => ['currency_code','currency_name','currency_symbol'], 'extra_ignore' => ['currency_code', 'currency_name', 'currency_symbol'],
], ],
'currency_code' => [ 'currency_code' => [
'id' => 1, 'id' => 1,
@ -113,7 +113,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'currency_code' => ['test_value' => $currencies[$rand]], 'currency_code' => ['test_value' => $currencies[$rand]],
], ],
'extra_ignore' => ['currency_id','currency_name','currency_symbol'], 'extra_ignore' => ['currency_id', 'currency_name', 'currency_symbol'],
], ],
'start' => [ 'start' => [
'id' => 1, 'id' => 1,

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.categories.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -108,7 +91,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -125,4 +107,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.categories.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -83,19 +83,19 @@ class UpdateControllerTest extends TestCase
*/ */
public function updateDataSet(): array public function updateDataSet(): array
{ {
$faker = Factory::create(); $faker = Factory::create();
$set = [ $set = [
'name' => [ 'name' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'name' => ['test_value' => $faker->uuid], 'name' => ['test_value' => $faker->uuid],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'notes' => [ 'notes' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'notes' => ['test_value' => join(' ',$faker->words(5))], 'notes' => ['test_value' => join(' ', $faker->words(5))],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.piggy_banks.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -110,7 +93,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -160,4 +142,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.piggy_banks.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -99,7 +99,7 @@ class UpdateControllerTest extends TestCase
'fields' => [ 'fields' => [
'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)], 'account_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
], ],
'extra_ignore' => ['account_name','currency_id','currency_code'], 'extra_ignore' => ['account_name', 'currency_id', 'currency_code'],
], ],
'target_amount' => [ 'target_amount' => [
'id' => 1, 'id' => 1,
@ -146,16 +146,16 @@ class UpdateControllerTest extends TestCase
'object_group_id' => [ 'object_group_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'object_group_id' => ['test_value' => (string) $objectGroupId], 'object_group_id' => ['test_value' => (string)$objectGroupId],
], ],
'extra_ignore' => ['object_group_order','object_group_title'], 'extra_ignore' => ['object_group_order', 'object_group_title'],
], ],
'object_group_title' => [ 'object_group_title' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'object_group_title' => ['test_value' => $objectGroupName], 'object_group_title' => ['test_value' => $objectGroupName],
], ],
'extra_ignore' => ['object_group_order','object_group_id'], 'extra_ignore' => ['object_group_order', 'object_group_id'],
], ],
]; ];

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.recurrences.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -109,7 +92,7 @@ class StoreControllerTest extends TestCase
['weekly', (string)$faker->numberBetween(1, 7)], ['weekly', (string)$faker->numberBetween(1, 7)],
['ndom', (string)$faker->numberBetween(1, 4) . ',' . $faker->numberBetween(1, 7)], ['ndom', (string)$faker->numberBetween(1, 4) . ',' . $faker->numberBetween(1, 7)],
['monthly', (string)$faker->numberBetween(1, 31)], ['monthly', (string)$faker->numberBetween(1, 31)],
['yearly', $faker->dateTimeBetween('-1 year','now')->format('Y-m-d')], ['yearly', $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')],
]; ];
$set = []; $set = [];
@ -144,7 +127,6 @@ class StoreControllerTest extends TestCase
return $set; return $set;
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -153,38 +135,38 @@ class StoreControllerTest extends TestCase
$faker = Factory::create(); $faker = Factory::create();
return [ return [
'description' => [ 'description' => [
'fields' => [ 'fields' => [
'description' => $faker->uuid, 'description' => $faker->uuid,
], ],
], ],
'nr_of_repetitions' => [ 'nr_of_repetitions' => [
'fields' => [ 'fields' => [
'nr_of_repetitions' => $faker->numberBetween(1, 2), 'nr_of_repetitions' => $faker->numberBetween(1, 2),
], ],
'remove_fields' => ['repeat_until'], 'remove_fields' => ['repeat_until'],
], ],
'apply_rules' => [ 'apply_rules' => [
'fields' => [ 'fields' => [
'apply_rules' => $faker->boolean, 'apply_rules' => $faker->boolean,
], ],
], ],
'active' => [ 'active' => [
'fields' => [ 'fields' => [
'active' => $faker->boolean, 'active' => $faker->boolean,
], ],
], ],
'notes' => [ 'notes' => [
'fields' => [ 'fields' => [
'notes' => $faker->uuid, 'notes' => $faker->uuid,
], ],
], ],
'repetitions_skip' => [ 'repetitions_skip' => [
'fields' => [ 'fields' => [
'repetitions' => [ 'repetitions' => [
// first entry, set field: // first entry, set field:
[ [
'skip' => $faker->numberBetween(1,3), 'skip' => $faker->numberBetween(1, 3),
], ],
], ],
], ],
@ -194,12 +176,28 @@ class StoreControllerTest extends TestCase
'repetitions' => [ 'repetitions' => [
// first entry, set field: // first entry, set field:
[ [
'weekend' => $faker->numberBetween(1,4), 'weekend' => $faker->numberBetween(1, 4),
], ],
], ],
], ],
] ],
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.recurrences.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.rules.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -152,7 +135,6 @@ class StoreControllerTest extends TestCase
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -234,4 +216,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.rules.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.rule_groups.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -108,7 +91,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -135,4 +117,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.rule_groups.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.tags.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -108,7 +91,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -137,4 +119,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.tags.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -22,6 +22,7 @@
namespace Tests\Api\Models\Transaction; namespace Tests\Api\Models\Transaction;
use DateTimeInterface;
use Faker\Factory; use Faker\Factory;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use Log; use Log;
@ -37,6 +38,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +57,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.transactions.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -117,7 +101,7 @@ class StoreControllerTest extends TestCase
'transactions' => [ 'transactions' => [
[ [
'type' => $combi[0], 'type' => $combi[0],
'date' => $faker->dateTime(null, 'Europe/Amsterdam')->format(\DateTimeInterface::RFC3339), 'date' => $faker->dateTime(null, 'Europe/Amsterdam')->format(DateTimeInterface::RFC3339),
'amount' => number_format($faker->randomFloat(2, 10, 100), 12), 'amount' => number_format($faker->randomFloat(2, 10, 100), 12),
'description' => $faker->uuid, 'description' => $faker->uuid,
'source_id' => $combi[1], 'source_id' => $combi[1],
@ -131,7 +115,6 @@ class StoreControllerTest extends TestCase
return $set; return $set;
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -211,4 +194,20 @@ class StoreControllerTest extends TestCase
return $set; return $set;
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.transactions.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.currencies.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -81,19 +64,20 @@ class StoreControllerTest extends TestCase
$minimalSets = $this->minimalSets(); $minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets(); $optionalSets = $this->optionalSets();
$regenConfig = [ $regenConfig = [
'code' => function () { 'code' => function () {
$faker = Factory::create(); $faker = Factory::create();
return substr($faker->uuid, 0, 3); return substr($faker->uuid, 0, 3);
}, },
'name' => function () { 'name' => function () {
$faker = Factory::create(); $faker = Factory::create();
return $faker->uuid; return $faker->uuid;
}, },
'symbol' => function () { 'symbol' => function () {
$faker = Factory::create(); $faker = Factory::create();
return $faker->randomAscii.$faker->randomAscii;
return $faker->randomAscii . $faker->randomAscii;
}, },
]; ];
@ -113,13 +97,12 @@ class StoreControllerTest extends TestCase
'fields' => [ 'fields' => [
'code' => substr($faker->uuid, 0, 3), 'code' => substr($faker->uuid, 0, 3),
'name' => $faker->uuid, 'name' => $faker->uuid,
'symbol' => $faker->randomAscii.$faker->randomAscii, 'symbol' => $faker->randomAscii . $faker->randomAscii,
], ],
], ],
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -133,12 +116,12 @@ class StoreControllerTest extends TestCase
'enabled' => $faker->boolean, 'enabled' => $faker->boolean,
], ],
], ],
'default' => [ 'default' => [
'fields' => [ 'fields' => [
'default' => $faker->boolean, 'default' => $faker->boolean,
], ],
], ],
'decimal_places' => [ 'decimal_places' => [
'fields' => [ 'fields' => [
'decimal_places' => $faker->numberBetween(1, 6), 'decimal_places' => $faker->numberBetween(1, 6),
], ],
@ -146,4 +129,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.currencies.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -102,7 +102,7 @@ class UpdateControllerTest extends TestCase
'symbol' => [ 'symbol' => [
'id' => 'RUB', 'id' => 'RUB',
'fields' => [ 'fields' => [
'description' => ['test_value' => $faker->randomAscii.$faker->randomAscii], 'description' => ['test_value' => $faker->randomAscii . $faker->randomAscii],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.transaction_links.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -123,7 +106,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -140,4 +122,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.transaction_links.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -85,35 +85,35 @@ class UpdateControllerTest extends TestCase
{ {
$faker = Factory::create(); $faker = Factory::create();
$set = [ $set = [
'link_type_id' => [ 'link_type_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'link_type_id' => ['test_value' => (string)$faker->numberBetween(1,3)], 'link_type_id' => ['test_value' => (string)$faker->numberBetween(1, 3)],
], ],
'extra_ignore' => ['link_type_name'], 'extra_ignore' => ['link_type_name'],
], ],
'link_type_name' => [ 'link_type_name' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'link_type_name' => ['test_value' => 'Refund'], 'link_type_name' => ['test_value' => 'Refund'],
], ],
'extra_ignore' => ['link_type_id'], 'extra_ignore' => ['link_type_id'],
], ],
'inward_id' => [ 'inward_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'inward_id' => ['test_value' => (string)$faker->numberBetween(11,20)], 'inward_id' => ['test_value' => (string)$faker->numberBetween(11, 20)],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'outward_id' => [ 'outward_id' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'outward_id' => ['test_value' => (string)$faker->numberBetween(11, 30)], 'outward_id' => ['test_value' => (string)$faker->numberBetween(11, 30)],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'notes' => [ 'notes' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'notes' => ['test_value' => join(' ', $faker->words(5))], 'notes' => ['test_value' => join(' ', $faker->words(5))],

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.link_types.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -121,7 +104,6 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
@ -132,4 +114,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.link_types.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -37,6 +37,15 @@ class StoreControllerTest extends TestCase
{ {
use RandomValues, TestHelpers, CollectsValues; use RandomValues, TestHelpers, CollectsValues;
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* *
*/ */
@ -47,32 +56,6 @@ class StoreControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.webhooks.store';
$this->storeAndCompare($route, $submission);
}
/**
* @return array
*/
public function emptyDataProvider(): array
{
return [[[]]];
}
/** /**
* @return array * @return array
*/ */
@ -81,12 +64,12 @@ class StoreControllerTest extends TestCase
$minimalSets = $this->minimalSets(); $minimalSets = $this->minimalSets();
$optionalSets = $this->optionalSets(); $optionalSets = $this->optionalSets();
$regenConfig = [ $regenConfig = [
'title' => function () { 'title' => function () {
$faker = Factory::create(); $faker = Factory::create();
return $faker->uuid; return $faker->uuid;
}, },
'url' => function () { 'url' => function () {
$faker = Factory::create(); $faker = Factory::create();
return str_replace(['http://'], 'https://', $faker->url); return str_replace(['http://'], 'https://', $faker->url);
@ -138,15 +121,15 @@ class StoreControllerTest extends TestCase
]; ];
} }
/** /**
* @return \array[][] * @return \array[][]
*/ */
private function optionalSets(): array private function optionalSets(): array
{ {
$faker = Factory::create(); $faker = Factory::create();
return [ return [
'active' => [ 'active' => [
'fields' => [ 'fields' => [
'active' => $faker->boolean, 'active' => $faker->boolean,
], ],
@ -154,4 +137,20 @@ class StoreControllerTest extends TestCase
]; ];
} }
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
$this->markTestSkipped('Empty data provider');
}
$route = 'api.v1.webhooks.store';
$this->storeAndCompare($route, $submission);
}
} }

View File

@ -85,24 +85,26 @@ class UpdateControllerTest extends TestCase
{ {
$faker = Factory::create(); $faker = Factory::create();
$set = [ $set = [
'active' => [ 'active' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'active' => ['test_value' => $faker->boolean], 'active' => ['test_value' => $faker->boolean],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'title' => [ 'title' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'title' => ['test_value' => $faker->uuid], 'title' => ['test_value' => $faker->uuid],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'trigger' => [ 'trigger' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'trigger' => ['test_value' => $faker->randomElement(['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION'])], 'trigger' => ['test_value' => $faker->randomElement(
['TRIGGER_STORE_TRANSACTION', 'TRIGGER_UPDATE_TRANSACTION', 'TRIGGER_DESTROY_TRANSACTION']
)],
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
@ -120,7 +122,7 @@ class UpdateControllerTest extends TestCase
], ],
'extra_ignore' => [], 'extra_ignore' => [],
], ],
'url' => [ 'url' => [
'id' => 1, 'id' => 1,
'fields' => [ 'fields' => [
'url' => ['test_value' => str_replace(['http://'], 'https://', $faker->url)], 'url' => ['test_value' => str_replace(['http://'], 'https://', $faker->url)],

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests; namespace Tests;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
/** /**
* Trait CreatesApplication * Trait CreatesApplication
@ -36,7 +37,7 @@ trait CreatesApplication
/** /**
* Creates the application. * Creates the application.
* *
* @return \Illuminate\Foundation\Application * @return Application
*/ */
public function createApplication() public function createApplication()
{ {

View File

@ -12,10 +12,36 @@ class Field
{ {
public ?Closure $expectedReturn; public ?Closure $expectedReturn;
public string $expectedReturnType; public string $expectedReturnType;
public string $fieldPosition;
public string $fieldTitle; public string $fieldTitle;
public string $fieldType; public string $fieldType;
public ?array $ignorableFields; public ?array $ignorableFields;
public string $title; public string $title;
/**
* Field constructor.
*/
public function __construct()
{
$this->expectedReturnType = 'equal'; // or 'callback'
$this->expectedReturn = null; // or the callback
$this->ignorableFields = []; // something like transactions/0/currency_code
//$optionalField->ignorableFields = ['some_field', 'transactions/0/another_field', 'rules/2/another_one',]; // something like transactions/0/currency_code
}
/**
* @param string $title
* @param string $type
*
* @return static
*/
public static function createBasic(string $title, string $type): self
{
$field = new self;
$field->title = $title;
$field->fieldTitle = $title;
$field->fieldType = $type;
return $field;
}
} }

View File

@ -11,46 +11,230 @@ use RuntimeException;
*/ */
class TestConfiguration class TestConfiguration
{ {
public FieldSet $mandatoryFieldSet; public array $mandatoryFieldSets;
public FieldSet $optionalFieldSet; public array $optionalFieldSets;
private array $submission; private array $submission;
protected const MAX_ITERATIONS = 3;
public array $ignores;
/** /**
* TestConfiguration constructor. * TestConfiguration constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->submission = []; $this->submission = [];
$this->mandatoryFieldSets = [];
$this->optionalFieldSets = [];
$this->ignores = [];
}
/**
* @param FieldSet $set
*/
public function addMandatoryFieldSet(FieldSet $set)
{
$this->mandatoryFieldSets[] = $set;
}
public function addOptionalFieldSet(string $key, FieldSet $set)
{
$this->optionalFieldSets[$key] = $set;
}
/**
* @param array $submissions
*
* @return array
*/
public function generateIgnores(array $submissions): array
{
$ignores = [];
// loop each submission and find its expected return and create
// a return array with the expected values.
/** @var array $submission */
foreach ($submissions as $index => $submission) {
$ignores[$index] = [];
// loop each field and use the "name" to find it.
/**
* @var string $fieldName
* @var string $fieldValue
*/
foreach ($submission as $fieldTitle => $fieldValue) {
//echo "Now searching for field $fieldTitle on index $index.\n";
$fieldObject = $this->findField($fieldTitle);
if (null !== $fieldObject) {
if (0 !== count($fieldObject->ignorableFields)) {
/** @var string $ignorableField */
foreach ($fieldObject->ignorableFields as $ignorableField) {
// explode and put in the right position:
$positions = explode('/', $ignorableField);
if (1 === count($positions)) {
$ignores[$index][$ignorableField] = true;
}
if (3 === count($positions)) {
$root = $positions[0];
$index = (int)$positions[1];
$final = $positions[2];
$ignores[$index][$root][$index][$final] = true;
}
}
}
}
if (null === $fieldObject) {
die('null field object :(');
}
}
}
return $ignores;
}
/**
* @param int $index
* @param string $title
*
* @return Field|null
*/
private function findField(string $title): ?Field
{
// since there is no index for optional field sets (they use ID)
// reverse the set and loop them all:
// reason we reverse them is because the last always overrules the first.
$reversed = array_reverse($this->optionalFieldSets);
foreach ($reversed as $fieldSet) {
foreach ($fieldSet->fields as $field) {
if ($title === $field->fieldTitle) {
//echo " found field $title in an optional field set.\n";
return $field;
}
}
}
$reversed = array_reverse($this->mandatoryFieldSets);
foreach ($reversed as $fieldSet) {
foreach ($fieldSet->fields as $field) {
if ($title === $field->fieldTitle) {
//echo " found field $title in a mandatory field set.\n";
return $field;
}
}
}
return null;
}
/**
* @param array $submissions
*
* @return array
*/
public function generateExpected(array $submissions): array
{
$returns = [];
// loop each submission and find its expected return and create
// a return array with the expected values.
/** @var array $submission */
foreach ($submissions as $index => $submission) {
$returns[$index] = [];
// loop each field and use the "name" to find it.
/**
* @var string $fieldName
* @var string $fieldValue
*/
foreach ($submission as $fieldTitle => $fieldValue) {
//echo "Now searching for field $fieldTitle on index $index.\n";
$fieldObject = $this->findField($fieldTitle);
if (null !== $fieldObject) {
if (null === $fieldObject->expectedReturn) {
$returns[$index][$fieldTitle] = $submissions[$index][$fieldTitle];
}
if (null !== $fieldObject->expectedReturn) {
die('cannot handle closure');
}
}
if (null === $fieldObject) {
die('null field object :(');
}
}
}
return $returns;
}
/**
* @param FieldSet $set
*
* @return array
*/
private function toArray(FieldSet $set): array
{
$ignore = [];
$result = [];
/** @var Field $field */
foreach ($set->fields as $field) {
$result = $this->parseField($result, $field);
$ignore = array_unique($ignore + $field->ignorableFields);
}
$this->ignores[] = $ignore;
return $result;
} }
/** /**
* @return array * @return array
*/ */
public function generateSubmission(): array public function generateSubmissions(): array
{ {
// first generate standard submission: // first generate standard submissions:
$this->submission = []; $this->submission = [];
$standard = [];
/** @var Field $field */
foreach ($this->mandatoryFieldSet->fields as $field) {
$standard = $this->parseField($standard, $field);
}
$this->submission[] = $standard;
// expand the standard submission with extra sets from the optional field set. // loop each standard submission:
$optionalCount = count($this->optionalFieldSet->fields); /** @var FieldSet $set */
if (0 !== $optionalCount) { foreach ($this->mandatoryFieldSets as $set) {
$keys = array_keys($this->optionalFieldSet->fields); $this->submission[] = $this->toArray($set);
for ($i = 1; $i <= count($keys); $i++) {
$combinations = $this->combinationsOf($i, $keys);
foreach ($combinations as $combination) { // expand the standard submission with extra sets from the optional field set.
$custom = $standard; $setCount = count($this->optionalFieldSets);
foreach ($combination as $key) { //echo "Just created a standard set\n";
// add field $key to the standard submission. if (0 !== $setCount) {
$custom = $this->parseField($custom, $this->optionalFieldSet->fields[$key]); $keys = array_keys($this->optionalFieldSets);
//echo " keys to consider are: " . join(', ', $keys) . "\n";
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
for ($i = 1; $i <= $maxCount; $i++) {
$combinationSets = $this->combinationsOf($i, $keys);
//echo " will create " . count($combinationSets) . " extra sets.\n";
foreach ($combinationSets as $ii => $combinationSet) {
//echo " Set " . ($ii + 1) . "/" . count($combinationSets) . " will consist of:\n";
// the custom set is born!
$custom = $this->toArray($set);
// echo " refreshed!\n";
// echo " " . json_encode($custom) . "\n";
foreach ($combinationSet as $combination) {
//echo " $combination\n";
// here we start adding stuff to a copy of the standard submission.
/** @var FieldSet $customSet */
$customSet = $this->optionalFieldSets[$combination] ?? false;
// echo " there are " . count(array_keys($customSet->fields)) . " field(s) in this custom set\n";
// loop each field in this custom set and add them, nothing more.
/** @var Field $field */
foreach ($customSet->fields as $field) {
//echo " added field ".$field->fieldTitle." from custom set ".$combination."\n";
$custom = $this->parseField($custom, $field);
// for each field, add the ignores to the current index (+1!) of
// ignores.
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
$count = count($this->submission);
$currentIgnoreSet = $this->ignores[$count] ?? [];
$this->ignores[$count] = array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields)));
}
}
}
$this->submission[] = $custom;
} }
// add custom to $submission:
$this->submission[] = $custom;
} }
} }
} }
@ -58,6 +242,95 @@ class TestConfiguration
return $this->submission; return $this->submission;
} }
/**
* @param array $current
* @param Field $field
*
* @return array
*/
private function parseField(array $current, Field $field): array
{
// fieldTitle indicates the position:
$positions = explode('/', $field->fieldTitle);
$count = count($positions);
if (1 === $count) {
$current[$field->fieldTitle] = $this->generateFieldValue($field->fieldType);
return $current;
}
if (3 === $count) {
$root = $positions[0];
$count = (int)$positions[1];
$final = $positions[2];
$current[$root] = array_key_exists($root, $current) ? $current[$root] : [];
$current[$root][$count] = array_key_exists($count, $current[$root]) ? $current[$root][$count] : [];
$current[$root][$count][$final] = $this->generateFieldValue($final);
return $current;
}
throw new RuntimeException(sprintf('Did not expect count %d from fieldTitle "%s".', $count, $field->fieldTitle));
}
/**
* @param string $type
*
* @return mixed
*/
private function generateFieldValue(string $type)
{
$faker = Factory::create();
switch ($type) {
default:
throw new RuntimeException(sprintf('Cannot handle field "%s"', $type));
case 'uuid':
return $faker->uuid;
case 'static-asset':
return 'asset';
case 'static-expense':
return 'expense';
case 'static-liabilities':
return 'liabilities';
case 'static-ccAsset':
return 'ccAsset';
case 'static-monthlyFull':
return 'monthlyFull';
case 'random-liability-type':
return $faker->randomElement(['loan', 'debt', 'mortgage']);
case 'random-amount':
return number_format($faker->randomFloat(2, 10, 100), 2);
case 'random-percentage':
return $faker->randomFloat(2, 1, 99);
case 'random-interest-period':
return $faker->randomElement(['daily', 'monthly', 'yearly']);
case 'random-past-date':
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
case 'random-asset-accountRole':
return $faker->randomElement(['defaultAsset', 'savingAsset']);
case 'random-transactionType':
return $faker->randomElement(['withdrawal', 'deposit', 'transfer']);
case 'boolean':
return $faker->boolean;
case 'iban':
case 'account_number':
return $faker->iban();
case 'bic':
return $faker->swiftBicNumber;
case 'random-currency-id':
return $faker->numberBetween(1, 10);
case 'random-currency-code':
return $faker->randomElement(['EUR', 'USD', 'HUF', 'GBP']);
case 'order':
return $faker->numberBetween(1, 5);
case 'latitude':
return $faker->latitude;
case 'longitude':
return $faker->longitude;
case 'random-zoom_level':
return $faker->numberBetween(1, 12);
}
}
/** /**
* @param $k * @param $k
* @param $xs * @param $xs
@ -84,53 +357,37 @@ class TestConfiguration
} }
/** /**
* @param string $type * @param FieldSet $optionalFieldSet
*
* @return mixed
*/ */
private function generateFieldValue(string $type) public function setOptionalFieldSet(FieldSet $optionalFieldSet): void
{ {
$faker = Factory::create(); $this->optionalFieldSet = $optionalFieldSet;
switch ($type) {
default:
throw new RuntimeException(sprintf('Cannot handle field "%s"', $type));
case 'uuid':
return $faker->uuid;
case 'static-asset':
return 'asset';
case 'random-asset-accountRole':
return $faker->randomElement(['defaultAsset', 'savingsAsset']);
case 'random-transactionType':
return $faker->randomElement(['withdrawal', 'deposit', 'transfer']);
case 'boolean':
return $faker->boolean;
case 'iban':
return $faker->iban();
}
} }
/** /**
* @param array $current * @param array $existing
* @param Field $field * @param array $config
* *
* @return array * @return array
*/ */
private function parseField(array $current, Field $field): array private function parseIgnorableFields(array $existing, array $config): array
{ {
if ('' === $field->fieldPosition) { foreach ($config as $field) {
$current[$field->fieldTitle] = $this->generateFieldValue($field->fieldType); $parts = explode('/', $field);
} if (1 === count($parts)) {
if ('' !== $field->fieldPosition) { $existing[$parts[0]] = true;
$positions = explode('/', $field->fieldPosition); }
// since the "positions" array is almost 2 indexes deep at best, we can do some manual fiddling. if (3 === count($parts)) {
$root = $positions[0]; $root = $parts[0];
$count = (int)$positions[1]; $index = (int)$parts[1];
$current[$root] = array_key_exists($root, $current) ? $current[$root] : []; $final = $parts[2];
$current[$root][$count] = array_key_exists($count, $current[$root]) ? $current[$root][$count] : []; $existing[$root][$index][$final] = true;
$current[$root][$count][$field->fieldTitle] = $this->generateFieldValue($field->fieldType); }
//if ('' !== $field->fieldPosition) {
//$positions = explode('/', $field->fieldPosition);
} }
return $current; return $existing;
} }
} }

View File

@ -32,6 +32,7 @@ use Tests\Traits\CollectsValues;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
use CreatesApplication, CollectsValues; use CreatesApplication, CollectsValues;
protected const MAX_ITERATIONS = 2; protected const MAX_ITERATIONS = 2;
/** /**

View File

@ -24,18 +24,6 @@ declare(strict_types=1);
namespace Tests\Traits; namespace Tests\Traits;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User; use FireflyIII\User;
/** /**
@ -50,208 +38,208 @@ trait CollectsValues
{ {
return User::where('email', 'james@firefly')->first(); return User::where('email', 'james@firefly')->first();
} }
// //
// /** // /**
// * @return User // * @return User
// */ // */
// public function nonAdminUser(): User // public function nonAdminUser(): User
// { // {
// return User::where('email', 'no_admin@firefly')->first(); // return User::where('email', 'no_admin@firefly')->first();
// } // }
// //
// /** // /**
// * @return Budget // * @return Budget
// */ // */
// public function getRandomBudget(): Budget // public function getRandomBudget(): Budget
// { // {
// return $this->user()->budgets()->inRandomOrder()->first(); // return $this->user()->budgets()->inRandomOrder()->first();
// } // }
// //
// /** // /**
// * @return Category // * @return Category
// */ // */
// public function getRandomCategory(): Category // public function getRandomCategory(): Category
// { // {
// return $this->user()->categories()->inRandomOrder()->first(); // return $this->user()->categories()->inRandomOrder()->first();
// } // }
// //
// /** // /**
// * @return Bill // * @return Bill
// */ // */
// public function getRandomBill(): Bill // public function getRandomBill(): Bill
// { // {
// return $this->user()->bills()->inRandomOrder()->first(); // return $this->user()->bills()->inRandomOrder()->first();
// } // }
// //
// /** // /**
// * @return PiggyBank // * @return PiggyBank
// */ // */
// public function getRandomPiggyBank(): PiggyBank // public function getRandomPiggyBank(): PiggyBank
// { // {
// return $this->user()->piggyBanks()->inRandomOrder()->first(); // return $this->user()->piggyBanks()->inRandomOrder()->first();
// } // }
// //
// //
// /** // /**
// * @return Tag // * @return Tag
// */ // */
// public function getRandomTag(): Tag // public function getRandomTag(): Tag
// { // {
// return $this->user()->tags()->inRandomOrder()->first(); // return $this->user()->tags()->inRandomOrder()->first();
// } // }
// //
// /** // /**
// * @return TransactionJournal // * @return TransactionJournal
// */ // */
// public function getRandomWithdrawal(): TransactionJournal // public function getRandomWithdrawal(): TransactionJournal
// { // {
// return $this->getRandomJournal(TransactionType::WITHDRAWAL); // return $this->getRandomJournal(TransactionType::WITHDRAWAL);
// } // }
// //
// /** // /**
// * @return TransactionJournal // * @return TransactionJournal
// */ // */
// public function getRandomTransfer(): TransactionJournal // public function getRandomTransfer(): TransactionJournal
// { // {
// return $this->getRandomJournal(TransactionType::TRANSFER); // return $this->getRandomJournal(TransactionType::TRANSFER);
// } // }
// //
// /** // /**
// * @return TransactionJournal // * @return TransactionJournal
// */ // */
// public function getRandomDeposit(): TransactionJournal // public function getRandomDeposit(): TransactionJournal
// { // {
// return $this->getRandomJournal(TransactionType::DEPOSIT); // return $this->getRandomJournal(TransactionType::DEPOSIT);
// } // }
// //
// /** // /**
// * @param string $type // * @param string $type
// * // *
// * @return TransactionJournal // * @return TransactionJournal
// * @throws FireflyException // * @throws FireflyException
// */ // */
// private function getRandomJournal(string $type): TransactionJournal // private function getRandomJournal(string $type): TransactionJournal
// { // {
// $query = DB::table('transactions') // $query = DB::table('transactions')
// ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') // ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
// ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') // ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
// ->where('transaction_journals.user_id', $this->user()->id) // ->where('transaction_journals.user_id', $this->user()->id)
// ->whereNull('transaction_journals.deleted_at') // ->whereNull('transaction_journals.deleted_at')
// ->whereNull('transactions.deleted_at') // ->whereNull('transactions.deleted_at')
// ->where('transaction_types.type', $type) // ->where('transaction_types.type', $type)
// ->groupBy('transactions.transaction_journal_id') // ->groupBy('transactions.transaction_journal_id')
// ->having('ct', '=', 2) // ->having('ct', '=', 2)
// ->inRandomOrder()->take(1); // ->inRandomOrder()->take(1);
// $result = $query->get( // $result = $query->get(
// [ // [
// 'transactions.transaction_journal_id', // 'transactions.transaction_journal_id',
// 'transaction_journals.transaction_type_id', // 'transaction_journals.transaction_type_id',
// DB::raw('COUNT(transaction_journal_id) as ct'), // DB::raw('COUNT(transaction_journal_id) as ct'),
// ] // ]
// )->first(); // )->first();
// if (null === $result) { // if (null === $result) {
// throw new FireflyException(sprintf('Cannot find suitable journal "%s" to use.', $type)); // throw new FireflyException(sprintf('Cannot find suitable journal "%s" to use.', $type));
// } // }
// //
// return TransactionJournal::find((int)$result->transaction_journal_id); // return TransactionJournal::find((int)$result->transaction_journal_id);
// //
// } // }
// //
// /** // /**
// * @return TransactionCurrency // * @return TransactionCurrency
// */ // */
// public function getEuro(): TransactionCurrency // public function getEuro(): TransactionCurrency
// { // {
// return TransactionCurrency::whereCode('EUR')->first(); // return TransactionCurrency::whereCode('EUR')->first();
// } // }
// //
// /** // /**
// * @return TransactionCurrency // * @return TransactionCurrency
// */ // */
// public function getRandomCurrency(): TransactionCurrency // public function getRandomCurrency(): TransactionCurrency
// { // {
// return TransactionCurrency::where('code', '!=', 'EUR')->inRandomOrder()->first(); // return TransactionCurrency::where('code', '!=', 'EUR')->inRandomOrder()->first();
// } // }
// //
// /** // /**
// * @return TransactionCurrency // * @return TransactionCurrency
// */ // */
// public function getDollar(): TransactionCurrency // public function getDollar(): TransactionCurrency
// { // {
// return TransactionCurrency::whereCode('USD')->first(); // return TransactionCurrency::whereCode('USD')->first();
// } // }
// //
// /** // /**
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// public function getRandomAsset(?int $except = null): Account // public function getRandomAsset(?int $except = null): Account
// { // {
// return $this->getRandomAccount(AccountType::ASSET, $except); // return $this->getRandomAccount(AccountType::ASSET, $except);
// } // }
// //
// /** // /**
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// public function getRandomDebt(?int $except = null): Account // public function getRandomDebt(?int $except = null): Account
// { // {
// return $this->getRandomAccount(AccountType::DEBT, $except); // return $this->getRandomAccount(AccountType::DEBT, $except);
// } // }
// //
// /** // /**
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// public function getRandomLoan(?int $except = null): Account // public function getRandomLoan(?int $except = null): Account
// { // {
// return $this->getRandomAccount(AccountType::LOAN, $except); // return $this->getRandomAccount(AccountType::LOAN, $except);
// } // }
// //
// /** // /**
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// public function getRandomRevenue(?int $except = null): Account // public function getRandomRevenue(?int $except = null): Account
// { // {
// return $this->getRandomAccount(AccountType::REVENUE, $except); // return $this->getRandomAccount(AccountType::REVENUE, $except);
// } // }
// //
// /** // /**
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// public function getRandomExpense(?int $except = null): Account // public function getRandomExpense(?int $except = null): Account
// { // {
// return $this->getRandomAccount(AccountType::EXPENSE, $except); // return $this->getRandomAccount(AccountType::EXPENSE, $except);
// } // }
// //
// /** // /**
// * @param string $type // * @param string $type
// * // *
// * @param int|null $except // * @param int|null $except
// * // *
// * @return Account // * @return Account
// */ // */
// private function getRandomAccount(string $type, ?int $except): Account // private function getRandomAccount(string $type, ?int $except): Account
// { // {
// $query = Account:: // $query = Account::
// leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') // leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
// ->whereNull('accounts.deleted_at') // ->whereNull('accounts.deleted_at')
// ->where('accounts.user_id', $this->user()->id) // ->where('accounts.user_id', $this->user()->id)
// ->where('account_types.type', $type) // ->where('account_types.type', $type)
// ->inRandomOrder()->take(1); // ->inRandomOrder()->take(1);
// if (null !== $except) { // if (null !== $except) {
// $query->where('accounts.id', '!=', $except); // $query->where('accounts.id', '!=', $except);
// } // }
// //
// return $query->first(['accounts.*']); // return $query->first(['accounts.*']);
// } // }
} }

View File

@ -24,11 +24,11 @@ namespace Tests\Traits;
trait FakeValues trait FakeValues
{ {
// /** // /**
// * @return string // * @return string
// */ // */
// protected function fakeName(): string { // protected function fakeName(): string {
// return ''; // return '';
// } // }
} }

View File

@ -23,25 +23,22 @@ declare(strict_types=1);
namespace Tests\Traits; namespace Tests\Traits;
use FireflyIII\Models\Configuration;
use FireflyConfig;
/** /**
* Trait MocksDefaultValues * Trait MocksDefaultValues
*/ */
trait MocksDefaultValues trait MocksDefaultValues
{ {
// public function mockDefaultConfiguration(): void // public function mockDefaultConfiguration(): void
// { // {
// //
// $falseConfig = new Configuration; // $falseConfig = new Configuration;
// $falseConfig->data = false; // $falseConfig->data = false;
// //
// $idConfig = new Configuration; // $idConfig = new Configuration;
// $idConfig->data = 'abc'; // $idConfig->data = 'abc';
// //
// FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig); // FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig);
// FireflyConfig::shouldReceive('get')->withArgs(['installation_id', null])->andReturn($idConfig); // FireflyConfig::shouldReceive('get')->withArgs(['installation_id', null])->andReturn($idConfig);
// } // }
} }

View File

@ -54,21 +54,12 @@ trait RandomValues
return array_merge($res1, $res2); return array_merge($res1, $res2);
} }
/** /**
* @return string * @return string
*/ */
protected function randomAccountRole(): string protected function getRandomAmount(): string
{ {
return $this->randomFromArray(['defaultAsset', 'sharedAsset', 'savingAsset']); return number_format(rand(1000, 100000) / 100, '2', '.');
}
/**
* @return string
*/
protected function randomLiabilityType(): string
{
return $this->randomFromArray(['loan', 'debt', 'mortgage']);
} }
/** /**
@ -79,14 +70,6 @@ trait RandomValues
return $this->randomFromArray(['EUR', 'USD', 'GBP']); return $this->randomFromArray(['EUR', 'USD', 'GBP']);
} }
/**
* @return string
*/
protected function getRandomAmount(): string
{
return number_format(rand(1000, 100000) / 100, '2', '.');
}
/** /**
* @return string * @return string
*/ */
@ -98,6 +81,14 @@ trait RandomValues
return $date->format('Y-m-d'); return $date->format('Y-m-d');
} }
/**
* @return string
*/
protected function getRandomInterestPeriod(): string
{
return $this->randomFromArray(['daily', 'monthly', 'yearly']);
}
/** /**
* @return string * @return string
*/ */
@ -109,9 +100,9 @@ trait RandomValues
/** /**
* @return string * @return string
*/ */
protected function getRandomInterestPeriod(): string protected function randomAccountRole(): string
{ {
return $this->randomFromArray(['daily', 'monthly', 'yearly']); return $this->randomFromArray(['defaultAsset', 'sharedAsset', 'savingAsset']);
} }
/** /**
@ -123,4 +114,12 @@ trait RandomValues
{ {
return $array[rand(0, count($array) - 1)]; return $array[rand(0, count($array) - 1)];
} }
/**
* @return string
*/
protected function randomLiabilityType(): string
{
return $this->randomFromArray(['loan', 'debt', 'mortgage']);
}
} }

View File

@ -32,6 +32,21 @@ use Log;
*/ */
trait TestHelpers trait TestHelpers
{ {
/**
* @return int
*/
public function randomInt(): int
{
$result = 4;
try {
$result = random_int(1, 100000);
} catch (Exception $e) {
Log::debug(sprintf('Could not generate random number: %s', $e->getMessage()));
}
return $result;
}
/** /**
* @param array $minimalSets * @param array $minimalSets
* @param array $startOptionalSets * @param array $startOptionalSets
@ -105,22 +120,6 @@ trait TestHelpers
return $submissions; return $submissions;
} }
/**
* @return int
*/
public function randomInt(): int
{
$result = 4;
try {
$result = random_int(1, 100000);
} catch (Exception $e) {
Log::debug(sprintf('Could not generate random number: %s', $e->getMessage()));
}
return $result;
}
/** /**
* @param $set * @param $set
* @param $opts * @param $opts
@ -149,6 +148,136 @@ trait TestHelpers
return $set; return $set;
} }
/**
* @param string $route
* @param array $content
*/
protected function updatedStoreAndCompare(string $route, array $content): void
{
$submission = $content['submission'];
$expected = $content['expected'];
$ignore = $content['ignore'];
// submit body
$response = $this->post($route, $submission, ['Accept' => 'application/json']);
$responseBody = $response->content();
$responseJson = json_decode($responseBody, true);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
$response->assertHeader('Content-Type', 'application/vnd.api+json');
// get return and compare each field
$responseAttributes = $responseJson['data']['attributes'];
$this->updatedCompareStorageArray($submission, $responseAttributes, $expected, $ignore);
// ignore fields too!
}
/**
* @param array $submission
* @param array $response
* @param array $expected
* @param array $ignore
*/
protected function updatedCompareStorageArray(array $submission, array $response, array $expected, array $ignore): void
{
foreach ($response as $key => $value) {
if (is_array($value) && array_key_exists($key, $expected) && is_array($expected[$key])) {
$this->updatedCompareStorageArray($submission, $value, $expected[$key], $ignore[$key] ?? []);
}
if (isset($expected[$key])) {
if (in_array($key, $ignore, true)) {
continue;
}
if (!in_array($key, $ignore, true)) {
$message = sprintf(
"Field '%s' with value %s is expected to be %s.\nSubmitted:\n%s\nIgnored: %s\nReturned\n%s",
$key,
var_export($value, true),
var_export($expected[$key], true),
json_encode($submission),
json_encode($ignore),
json_encode($response)
);
$this->assertEquals($value, $expected[$key], $message);
}
// if($value !== $expected[$key]) {
// }
// var_dump($key);
// var_dump($value);
// var_dump($expected[$key]);
// exit;
}
}
}
/**
* @param string $route
* @param array $content
*/
protected function storeAndCompare(string $route, array $content): void
{
$submission = $content['fields'];
$parameters = $content['parameters'];
$ignore = $content['ignore'];
// submit!
$response = $this->post(route($route, $parameters), $submission, ['Accept' => 'application/json']);
$responseBody = $response->content();
$responseJson = json_decode($responseBody, true);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
$response->assertHeader('Content-Type', 'application/vnd.api+json');
// compare results:
foreach ($responseJson['data']['attributes'] as $returnName => $returnValue) {
if (array_key_exists($returnName, $submission) && !in_array($returnName, $ignore, true)) {
// TODO still based on account routine:
if ($this->ignoreCombination($route, $submission['type'] ?? 'blank', $returnName)) {
continue;
}
// check if is array, if so we need something smart:
if (is_array($returnValue) && is_array($submission[$returnName])) {
$this->compareArray($submission, $returnName, $submission[$returnName], $returnValue);
}
if (!is_array($returnValue) && !is_array($submission[$returnName])) {
$message = sprintf(
"Main: Return value '%s' of key '%s' does not match submitted value '%s'.\n%s\n%s", $returnValue, $returnName, $submission[$returnName],
json_encode($submission), $responseBody
);
$this->assertEquals($returnValue, $submission[$returnName], $message);
}
}
}
}
/**
* Some specials:
*
* @param string $area
* @param string $left
* @param string $right
*
* @return bool
*/
protected function ignoreCombination(string $area, string $left, string $right): bool
{
if ('api.v1.accounts.store' === $area) {
if ('expense' === $left
&& in_array($right, ['order', 'virtual_balance', 'opening_balance', 'opening_balance_date'])) {
return true;
}
}
return false;
}
/** /**
* @param string $route * @param string $route
* @param array $submission * @param array $submission
@ -247,47 +376,6 @@ trait TestHelpers
} }
} }
/**
* @param string $route
* @param array $content
*/
protected function storeAndCompare(string $route, array $content): void
{
$submission = $content['fields'];
$parameters = $content['parameters'];
$ignore = $content['ignore'];
// submit!
$response = $this->post(route($route, $parameters), $submission, ['Accept' => 'application/json']);
$responseBody = $response->content();
$responseJson = json_decode($responseBody, true);
$status = $response->getStatusCode();
$this->assertEquals($status, 200, sprintf("Submission:\n%s\nResponse: %s", json_encode($submission), $responseBody));
$response->assertHeader('Content-Type', 'application/vnd.api+json');
// compare results:
foreach ($responseJson['data']['attributes'] as $returnName => $returnValue) {
if (array_key_exists($returnName, $submission) && !in_array($returnName, $ignore, true)) {
// TODO still based on account routine:
if ($this->ignoreCombination($route, $submission['type'] ?? 'blank', $returnName)) {
continue;
}
// check if is array, if so we need something smart:
if (is_array($returnValue) && is_array($submission[$returnName])) {
$this->compareArray($submission, $returnName, $submission[$returnName], $returnValue);
}
if (!is_array($returnValue) && !is_array($submission[$returnName])) {
$message = sprintf(
"Main: Return value '%s' of key '%s' does not match submitted value '%s'.\n%s\n%s", $returnValue, $returnName, $submission[$returnName],
json_encode($submission), $responseBody
);
$this->assertEquals($returnValue, $submission[$returnName], $message);
}
}
}
}
/** /**
* @param array $fullOriginal * @param array $fullOriginal
* @param string $key * @param string $key
@ -297,7 +385,7 @@ trait TestHelpers
protected function compareArray(array $fullOriginal, string $key, array $original, array $returned) protected function compareArray(array $fullOriginal, string $key, array $original, array $returned)
{ {
// TODO this should be configurable but OK // TODO this should be configurable but OK
if(in_array($key, ['transactions','repetitions'], true) && 0 === count($original) && 0 !== count($returned)) { if (in_array($key, ['transactions', 'repetitions'], true) && 0 === count($original) && 0 !== count($returned)) {
// accept this. // accept this.
return; return;
} }
@ -326,25 +414,4 @@ trait TestHelpers
} }
} }
} }
/**
* Some specials:
*
* @param string $area
* @param string $left
* @param string $right
*
* @return bool
*/
protected function ignoreCombination(string $area, string $left, string $right): bool
{
if ('api.v1.accounts.store' === $area) {
if ('expense' === $left
&& in_array($right, ['order', 'virtual_balance', 'opening_balance', 'opening_balance_date'])) {
return true;
}
}
return false;
}
} }