mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Make sure expectations work.
This commit is contained in:
@@ -394,6 +394,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function update(Budget $budget, array $data): Budget
|
public function update(Budget $budget, array $data): Budget
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in update()');
|
||||||
|
// TODO update rules
|
||||||
$oldName = $budget->name;
|
$oldName = $budget->name;
|
||||||
if (array_key_exists('name', $data)) {
|
if (array_key_exists('name', $data)) {
|
||||||
$budget->name = $data['name'];
|
$budget->name = $data['name'];
|
||||||
@@ -421,16 +423,21 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (null === $autoBudget
|
if (null === $autoBudget
|
||||||
&& array_key_exists('auto_budget_type', $data)
|
&& array_key_exists('auto_budget_type', $data)
|
||||||
&& array_key_exists('auto_budget_amount', $data)
|
&& array_key_exists('auto_budget_amount', $data)
|
||||||
&& 0 !== $data['auto_budget_type']
|
&& 0 !== $data['auto_budget_type']
|
||||||
|
&& 'none' !== $data['auto_budget_type']
|
||||||
) {
|
) {
|
||||||
// only create if all are here:
|
// only create if all are here:
|
||||||
$autoBudget = new AutoBudget;
|
$autoBudget = new AutoBudget;
|
||||||
$autoBudget->budget_id = $budget->id;
|
$autoBudget->budget_id = $budget->id;
|
||||||
$autoBudget->transaction_currency_id = $currency->id;
|
$autoBudget->transaction_currency_id = $currency->id;
|
||||||
}
|
}
|
||||||
|
if (null !== $autoBudget && null !== $currency) {
|
||||||
|
$autoBudget->transaction_currency_id = $currency->id;
|
||||||
|
}
|
||||||
|
|
||||||
// update existing type
|
// update existing type
|
||||||
if (array_key_exists('auto_budget_type', $data) && 0 !== $data['auto_budget_type']) {
|
if (array_key_exists('auto_budget_type', $data) && 0 !== $data['auto_budget_type']) {
|
||||||
@@ -441,7 +448,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
if ('rollover' === $autoBudgetType) {
|
if ('rollover' === $autoBudgetType) {
|
||||||
$autoBudget->auto_budget_type = AutoBudget::AUTO_BUDGET_ROLLOVER;
|
$autoBudget->auto_budget_type = AutoBudget::AUTO_BUDGET_ROLLOVER;
|
||||||
}
|
}
|
||||||
if ('none' === $autoBudgetType && null !== $autoBudget->id) {
|
if ('none' === $autoBudgetType && null !== $autoBudget) {
|
||||||
$autoBudget->delete();
|
$autoBudget->delete();
|
||||||
|
|
||||||
return $budget;
|
return $budget;
|
||||||
|
@@ -176,23 +176,7 @@ class StoreControllerTest extends TestCase
|
|||||||
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
|
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
|
||||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||||
|
|
||||||
|
return $configuration->generateAll();
|
||||||
// generate submissions
|
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -171,24 +171,7 @@ class UpdateControllerTest extends TestCase
|
|||||||
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
|
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
|
||||||
$configuration->addOptionalFieldSet('liability-2', $fieldSet);
|
$configuration->addOptionalFieldSet('liability-2', $fieldSet);
|
||||||
|
|
||||||
// generate submissions
|
return $configuration->generateAll();
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$parameters = $configuration->parameters;
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index] ?? [],
|
|
||||||
'parameters' => $parameters[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -102,23 +102,6 @@ class StoreControllerTest extends TestCase
|
|||||||
$fieldSet = new FieldSet;
|
$fieldSet = new FieldSet;
|
||||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||||
|
return $configuration->generateAll();
|
||||||
|
|
||||||
// generate submissions
|
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -97,24 +97,6 @@ class UpdateControllerTest extends TestCase
|
|||||||
$fieldSet->addField(Field::createBasic('attachable_type', 'static-journal-type'));
|
$fieldSet->addField(Field::createBasic('attachable_type', 'static-journal-type'));
|
||||||
$fieldSet->addField(Field::createBasic('attachable_id', 'random-journal-id'));
|
$fieldSet->addField(Field::createBasic('attachable_id', 'random-journal-id'));
|
||||||
$configuration->addOptionalFieldSet('attachable_type', $fieldSet);
|
$configuration->addOptionalFieldSet('attachable_type', $fieldSet);
|
||||||
|
return $configuration->generateAll();
|
||||||
// generate submissions
|
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$parameters = $configuration->parameters;
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index] ?? [],
|
|
||||||
'parameters' => $parameters[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -22,7 +22,6 @@
|
|||||||
namespace Tests\Api\Models\AvailableBudget;
|
namespace Tests\Api\Models\AvailableBudget;
|
||||||
|
|
||||||
|
|
||||||
use Faker\Factory;
|
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
use Tests\Objects\Field;
|
use Tests\Objects\Field;
|
||||||
@@ -30,7 +29,6 @@ use Tests\Objects\FieldSet;
|
|||||||
use Tests\Objects\TestConfiguration;
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +74,7 @@ class StoreControllerTest extends TestCase
|
|||||||
$configuration->addMandatoryFieldSet($defaultAssetSet);
|
$configuration->addMandatoryFieldSet($defaultAssetSet);
|
||||||
|
|
||||||
// optional field sets
|
// optional field sets
|
||||||
$fieldSet = new FieldSet;
|
$fieldSet = new FieldSet;
|
||||||
$field = new Field;
|
$field = new Field;
|
||||||
$field->fieldTitle = 'currency_id';
|
$field->fieldTitle = 'currency_id';
|
||||||
$field->fieldType = 'random-currency-id';
|
$field->fieldType = 'random-currency-id';
|
||||||
@@ -85,7 +83,7 @@ class StoreControllerTest extends TestCase
|
|||||||
$fieldSet->addField($field);
|
$fieldSet->addField($field);
|
||||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||||
|
|
||||||
$fieldSet = new FieldSet;
|
$fieldSet = new FieldSet;
|
||||||
$field = new Field;
|
$field = new Field;
|
||||||
$field->fieldTitle = 'currency_code';
|
$field->fieldTitle = 'currency_code';
|
||||||
$field->fieldType = 'random-currency-code';
|
$field->fieldType = 'random-currency-code';
|
||||||
@@ -94,22 +92,7 @@ class StoreControllerTest extends TestCase
|
|||||||
$fieldSet->addField($field);
|
$fieldSet->addField($field);
|
||||||
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||||
|
|
||||||
// generate submissions
|
return $configuration->generateAll();
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +115,5 @@ class StoreControllerTest extends TestCase
|
|||||||
// run account store with a minimal data set:
|
// run account store with a minimal data set:
|
||||||
$address = route('api.v1.available_budgets.store');
|
$address = route('api.v1.available_budgets.store');
|
||||||
$this->assertPOST($address, $submission);
|
$this->assertPOST($address, $submission);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -30,7 +30,6 @@ use Tests\Objects\FieldSet;
|
|||||||
use Tests\Objects\TestConfiguration;
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +52,7 @@ class UpdateControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
|
*
|
||||||
* @dataProvider updateDataProvider
|
* @dataProvider updateDataProvider
|
||||||
*/
|
*/
|
||||||
public function testUpdate(array $submission): void
|
public function testUpdate(array $submission): void
|
||||||
@@ -79,8 +79,8 @@ class UpdateControllerTest extends TestCase
|
|||||||
$configuration = new TestConfiguration;
|
$configuration = new TestConfiguration;
|
||||||
|
|
||||||
// optional field sets (for all test configs)
|
// optional field sets (for all test configs)
|
||||||
$fieldSet = new FieldSet;
|
$fieldSet = new FieldSet;
|
||||||
$fieldSet->parameters = [1];
|
$fieldSet->parameters = [1];
|
||||||
$field = new Field;
|
$field = new Field;
|
||||||
$field->fieldTitle = 'currency_id';
|
$field->fieldTitle = 'currency_id';
|
||||||
$field->fieldType = 'random-currency-id';
|
$field->fieldType = 'random-currency-id';
|
||||||
@@ -89,8 +89,8 @@ class UpdateControllerTest extends TestCase
|
|||||||
$fieldSet->addField($field);
|
$fieldSet->addField($field);
|
||||||
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
$configuration->addOptionalFieldSet('currency_id', $fieldSet);
|
||||||
|
|
||||||
$fieldSet = new FieldSet;
|
$fieldSet = new FieldSet;
|
||||||
$fieldSet->parameters = [1];
|
$fieldSet->parameters = [1];
|
||||||
$field = new Field;
|
$field = new Field;
|
||||||
$field->fieldTitle = 'currency_code';
|
$field->fieldTitle = 'currency_code';
|
||||||
$field->fieldType = 'random-currency-code';
|
$field->fieldType = 'random-currency-code';
|
||||||
@@ -119,25 +119,7 @@ class UpdateControllerTest extends TestCase
|
|||||||
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
|
$fieldSet->addField(Field::createBasic('start', 'random-date-two-year'));
|
||||||
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
|
$fieldSet->addField(Field::createBasic('end', 'random-date-one-year'));
|
||||||
$configuration->addOptionalFieldSet('both', $fieldSet);
|
$configuration->addOptionalFieldSet('both', $fieldSet);
|
||||||
|
return $configuration->generateAll();
|
||||||
// generate submissions
|
|
||||||
$array = $configuration->generateSubmissions();
|
|
||||||
$expected = $configuration->generateExpected($array);
|
|
||||||
$parameters = $configuration->parameters;
|
|
||||||
$ignored = $configuration->ignores;
|
|
||||||
|
|
||||||
// now create a combination for each submission and associated data:
|
|
||||||
$final = [];
|
|
||||||
foreach ($array as $index => $submission) {
|
|
||||||
$final[] = [[
|
|
||||||
'submission' => $submission,
|
|
||||||
'expected' => $expected[$index],
|
|
||||||
'ignore' => $ignored[$index] ?? [],
|
|
||||||
'parameters' => $parameters[$index],
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,12 +22,13 @@
|
|||||||
namespace Tests\Api\Models\Bill;
|
namespace Tests\Api\Models\Bill;
|
||||||
|
|
||||||
|
|
||||||
use Faker\Factory;
|
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,122 +62,102 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
public function storeDataProvider(): array
|
||||||
{
|
{
|
||||||
$minimalSets = $this->minimalSets();
|
// some test configs:
|
||||||
$optionalSets = $this->optionalSets();
|
$configuration = new TestConfiguration;
|
||||||
$regenConfig = [
|
|
||||||
'name' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return join(' ', $faker->words(5));
|
// default asset account test set:
|
||||||
},
|
$defaultAssetSet = new FieldSet();
|
||||||
];
|
$defaultAssetSet->title = 'default_file';
|
||||||
|
$defaultAssetSet->addField(Field::createBasic('name', 'uuid'));
|
||||||
|
$defaultAssetSet->addField(Field::createBasic('amount_min', 'random-amount-min'));
|
||||||
|
$defaultAssetSet->addField(Field::createBasic('amount_max', 'random-amount-max'));
|
||||||
|
$defaultAssetSet->addField(Field::createBasic('date', 'random-past-date'));
|
||||||
|
$defaultAssetSet->addField(Field::createBasic('repeat_freq', 'random-bill-repeat-freq'));
|
||||||
|
$configuration->addMandatoryFieldSet($defaultAssetSet);
|
||||||
|
|
||||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
// optional field sets
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'currency_code';
|
||||||
|
$field->fieldType = 'random-currency-code';
|
||||||
|
$field->ignorableFields = ['currency_id'];
|
||||||
|
$field->title = 'currency_code';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||||
|
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('amount_min', 'random-amount-min'));
|
||||||
|
$configuration->addOptionalFieldSet('amount_min', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('amount_max', 'random-amount-max'));
|
||||||
|
$configuration->addOptionalFieldSet('amount_max', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('date', 'random-past-date'));
|
||||||
|
$configuration->addOptionalFieldSet('date', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('repeat_freq', 'random-bill-repeat-freq'));
|
||||||
|
$configuration->addOptionalFieldSet('repeat_freq', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('skip', 'random-skip'));
|
||||||
|
$configuration->addOptionalFieldSet('skip', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('active', 'boolean'));
|
||||||
|
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||||
|
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||||
|
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'object_group_id';
|
||||||
|
$field->fieldType = 'random-og-id';
|
||||||
|
$field->ignorableFields = ['object_group_title', 'object_group_order'];
|
||||||
|
$field->title = 'object_group_id';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'object_group_title';
|
||||||
|
$field->fieldType = 'uuid';
|
||||||
|
$field->ignorableFields = ['object_group_id', 'object_group_order'];
|
||||||
|
$field->title = 'object_group_title';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
|
||||||
|
|
||||||
|
return $configuration->generateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function minimalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
$repeatFreqs = ['yearly', 'weekly', 'monthly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
|
|
||||||
return [
|
|
||||||
'default_bill' => [
|
|
||||||
'fields' => [
|
|
||||||
'name' => $faker->uuid,
|
|
||||||
'amount_min' => number_format($faker->randomFloat(2, 10, 50), 2),
|
|
||||||
'amount_max' => number_format($faker->randomFloat(2, 60, 90), 2),
|
|
||||||
'date' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
|
||||||
'repeat_freq' => $repeatFreq,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \array[][]
|
|
||||||
*/
|
|
||||||
private function optionalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
$repeatFreqs = ['weekly', 'monthly', 'yearly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
$currencies = [
|
|
||||||
1 => 'EUR',
|
|
||||||
2 => 'HUF',
|
|
||||||
3 => 'GBP',
|
|
||||||
4 => 'UAH',
|
|
||||||
];
|
|
||||||
$rand = rand(1, 4);
|
|
||||||
$objectGroupId = $faker->numberBetween(1, 2);
|
|
||||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'currency_by_id' => [
|
|
||||||
'fields' => [
|
|
||||||
'currency_id' => $rand,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'currency_by_code' => [
|
|
||||||
'fields' => [
|
|
||||||
'currency_code' => $currencies[$rand],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'name' => [
|
|
||||||
'fields' => [
|
|
||||||
'name' => $faker->uuid,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'amount_min' => [
|
|
||||||
'fields' => [
|
|
||||||
'amount_min' => number_format($faker->randomFloat(2, 10, 50), 2),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'amount_max' => [
|
|
||||||
'fields' => [
|
|
||||||
'amount_max' => number_format($faker->randomFloat(2, 60, 590), 2),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'date' => [
|
|
||||||
'fields' => [
|
|
||||||
'date' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'repeat_freq' => [
|
|
||||||
'fields' => [
|
|
||||||
'repeat_freq' => $repeatFreq,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'skip' => [
|
|
||||||
'fields' => [
|
|
||||||
'skip' => $faker->numberBetween(0, 5),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'active' => [
|
|
||||||
'fields' => [
|
|
||||||
'active' => $faker->boolean,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'notes' => [
|
|
||||||
'fields' => [
|
|
||||||
'notes' => join(' ', $faker->words(5)),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'object_group_id' => [
|
|
||||||
'fields' => [
|
|
||||||
'object_group_id' => $objectGroupId,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'object_group_title' => [
|
|
||||||
'fields' => [
|
|
||||||
'object_group_title' => $objectGroupName,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
@@ -188,11 +169,15 @@ class StoreControllerTest extends TestCase
|
|||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
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.bills.store';
|
$address = route('api.v1.bills.store');
|
||||||
$this->storeAndCompare($route, $submission);
|
$this->assertPOST($address, $submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -22,12 +22,13 @@
|
|||||||
namespace Tests\Api\Models\Bill;
|
namespace Tests\Api\Models\Bill;
|
||||||
|
|
||||||
|
|
||||||
use Faker\Factory;
|
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,13 +54,17 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(array $submission): void
|
public function testUpdate(array $submission): void
|
||||||
{
|
{
|
||||||
$ignore = [
|
if ([] === $submission) {
|
||||||
'created_at',
|
$this->markTestSkipped('Empty provider.');
|
||||||
'updated_at',
|
}
|
||||||
];
|
Log::debug('testStoreUpdated()');
|
||||||
$route = route('api.v1.bills.update', [$submission['id']]);
|
Log::debug('submission :', $submission['submission']);
|
||||||
|
Log::debug('expected :', $submission['expected']);
|
||||||
|
Log::debug('ignore :', $submission['ignore']);
|
||||||
|
Log::debug('parameters :', $submission['parameters']);
|
||||||
|
|
||||||
$this->updateAndCompare($route, $submission, $ignore);
|
$route = route('api.v1.bills.update', $submission['parameters']);
|
||||||
|
$this->assertPUT($route, $submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,125 +73,94 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function updateDataProvider(): array
|
public function updateDataProvider(): array
|
||||||
{
|
{
|
||||||
$submissions = [];
|
$configuration = new TestConfiguration;
|
||||||
$all = $this->updateDataSet();
|
|
||||||
foreach ($all as $name => $data) {
|
|
||||||
$submissions[] = [$data];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $submissions;
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||||
|
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('amount_min', 'random-amount-min'));
|
||||||
|
$configuration->addOptionalFieldSet('amount_min', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('amount_max', 'random-amount-max'));
|
||||||
|
$configuration->addOptionalFieldSet('amount_max', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('date', 'random-past-date'));
|
||||||
|
$configuration->addOptionalFieldSet('date', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('repeat_freq', 'random-bill-repeat-freq'));
|
||||||
|
$configuration->addOptionalFieldSet('repeat_freq', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('skip', 'random-skip'));
|
||||||
|
$configuration->addOptionalFieldSet('skip', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||||
|
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('active', 'boolean'));
|
||||||
|
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||||
|
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'object_group_id';
|
||||||
|
$field->fieldType = 'random-og-id';
|
||||||
|
$field->ignorableFields = ['object_group_title', 'object_group_order'];
|
||||||
|
$field->title = 'object_group_id';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('object_group_id', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'object_group_title';
|
||||||
|
$field->fieldType = 'uuid';
|
||||||
|
$field->ignorableFields = ['object_group_id', 'object_group_order'];
|
||||||
|
$field->title = 'object_group_title';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('object_group_title', $fieldSet);
|
||||||
|
|
||||||
|
// optional field sets
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'currency_code';
|
||||||
|
$field->fieldType = 'random-currency-code';
|
||||||
|
$field->ignorableFields = ['currency_id'];
|
||||||
|
$field->title = 'currency_code';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('currency_code', $fieldSet);
|
||||||
|
|
||||||
|
return $configuration->generateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function updateDataSet(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
$currencies = [
|
|
||||||
1 => 'EUR',
|
|
||||||
2 => 'HUF',
|
|
||||||
3 => 'GBP',
|
|
||||||
4 => 'UAH',
|
|
||||||
];
|
|
||||||
$repeatFreqs = ['yearly', 'weekly', 'monthly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
$objectGroupId = $faker->numberBetween(1, 2);
|
|
||||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
|
||||||
$rand = rand(1, 4);
|
|
||||||
$set = [
|
|
||||||
'name' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'name' => ['test_value' => $faker->uuid],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'amount_min' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'amount_min' => ['test_value' => number_format($faker->randomFloat(2, 10, 50), 2)],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'amount_max' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'amount_max' => ['test_value' => number_format($faker->randomFloat(2, 60, 90), 2)],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'date' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'date' => ['test_value' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d')],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
|
|
||||||
'repeat_freq' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'repeat_freq' => ['test_value' => $repeatFreq],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'skip' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'skip' => ['test_value' => $faker->numberBetween(1, 10)],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
|
|
||||||
'active' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'active' => ['test_value' => $faker->boolean],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'notes' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'notes' => ['test_value' => join(' ', $faker->words(5))],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'object_group_id' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'object_group_id' => ['test_value' => (string)$objectGroupId],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['object_group_order', 'object_group_title'],
|
|
||||||
],
|
|
||||||
'object_group_title' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'object_group_title' => ['test_value' => $objectGroupName],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['object_group_order', 'object_group_id'],
|
|
||||||
],
|
|
||||||
'currency_id' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'currency_id' => ['test_value' => (string)$rand],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['currency_code', 'currency_symbol'],
|
|
||||||
],
|
|
||||||
'currency_code' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'currency_code' => ['test_value' => $currencies[$rand]],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['currency_id', 'currency_symbol'],
|
|
||||||
],
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -25,6 +25,9 @@ namespace Tests\Api\Models\Budget;
|
|||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
@@ -61,97 +64,76 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function storeDataProvider(): array
|
public function storeDataProvider(): array
|
||||||
{
|
{
|
||||||
$minimalSets = $this->minimalSets();
|
return [[[]]];
|
||||||
$optionalSets = $this->optionalSets();
|
// some test configs:
|
||||||
$regenConfig = [
|
$configuration = new TestConfiguration;
|
||||||
'name' => function () {
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return join(' ', $faker->words(5));
|
// default test set:
|
||||||
},
|
$defaultSet = new FieldSet();
|
||||||
];
|
$defaultSet->title = 'default_budget';
|
||||||
|
$defaultSet->addField(Field::createBasic('name', 'uuid'));
|
||||||
|
$configuration->addMandatoryFieldSet($defaultSet);
|
||||||
|
|
||||||
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
// optional sets:
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('active', 'boolean'));
|
||||||
|
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'auto_budget_currency_id';
|
||||||
|
$field->fieldType = 'random-currency-id';
|
||||||
|
$field->ignorableFields = ['auto_budget_currency_code'];
|
||||||
|
$field->title = 'auto_budget_currency_id';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
|
||||||
|
$configuration->addOptionalFieldSet('auto-id', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'auto_budget_currency_code';
|
||||||
|
$field->fieldType = 'random-currency-code';
|
||||||
|
$field->ignorableFields = ['auto_budget_currency_id'];
|
||||||
|
$field->title = 'auto_budget_currency_code';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
|
||||||
|
$configuration->addOptionalFieldSet('auto-code', $fieldSet);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $configuration->generateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function minimalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'default_budget' => [
|
|
||||||
'fields' => [
|
|
||||||
'name' => $faker->uuid,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \array[][]
|
|
||||||
*/
|
|
||||||
private function optionalSets(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
$repeatFreqs = ['weekly', 'monthly', 'yearly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
$currencies = [
|
|
||||||
1 => 'EUR',
|
|
||||||
2 => 'HUF',
|
|
||||||
3 => 'GBP',
|
|
||||||
4 => 'UAH',
|
|
||||||
];
|
|
||||||
$rand = rand(1, 4);
|
|
||||||
$objectGroupId = $faker->numberBetween(1, 2);
|
|
||||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
|
||||||
|
|
||||||
$autoBudgetTypes = ['reset', 'rollover'];
|
|
||||||
$autoBudgetType = $autoBudgetTypes[rand(0, count($autoBudgetTypes) - 1)];
|
|
||||||
|
|
||||||
return [
|
|
||||||
'active' => [
|
|
||||||
'fields' => [
|
|
||||||
'active' => $faker->boolean,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'auto_budget_id' => [
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_type' => $autoBudgetType,
|
|
||||||
'auto_budget_currency_id' => $rand,
|
|
||||||
'auto_budget_amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
|
||||||
'auto_budget_period' => $repeatFreq,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'auto_budget_code' => [
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_type' => $autoBudgetType,
|
|
||||||
'auto_budget_currency_code' => $currencies[$rand],
|
|
||||||
'auto_budget_amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
|
||||||
'auto_budget_period' => $repeatFreq,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* emptyDataProvider / storeDataProvider
|
* emptyDataProvider / storeDataProvider
|
||||||
*
|
*
|
||||||
* @dataProvider storeDataProvider
|
* @dataProvider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
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.budgets.store';
|
$address = route('api.v1.budgets.store');
|
||||||
$this->storeAndCompare($route, $submission);
|
$this->assertPOST($address, $submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -22,12 +22,13 @@
|
|||||||
namespace Tests\Api\Models\Budget;
|
namespace Tests\Api\Models\Budget;
|
||||||
|
|
||||||
|
|
||||||
use Faker\Factory;
|
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Tests\Objects\Field;
|
||||||
|
use Tests\Objects\FieldSet;
|
||||||
|
use Tests\Objects\TestConfiguration;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CollectsValues;
|
use Tests\Traits\CollectsValues;
|
||||||
|
|
||||||
use Tests\Traits\TestHelpers;
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,13 +54,18 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(array $submission): void
|
public function testUpdate(array $submission): void
|
||||||
{
|
{
|
||||||
$ignore = [
|
if ([] === $submission) {
|
||||||
'created_at',
|
$this->markTestSkipped('Empty provider.');
|
||||||
'updated_at',
|
}
|
||||||
];
|
Log::debug('testStoreUpdated()');
|
||||||
$route = route('api.v1.budgets.update', [$submission['id']]);
|
Log::debug('submission :', $submission['submission']);
|
||||||
|
Log::debug('expected :', $submission['expected']);
|
||||||
|
Log::debug('ignore :', $submission['ignore']);
|
||||||
|
Log::debug('parameters :', $submission['parameters']);
|
||||||
|
|
||||||
|
$route = route('api.v1.budgets.update', $submission['parameters']);
|
||||||
|
$this->assertPUT($route, $submission);
|
||||||
|
|
||||||
$this->updateAndCompare($route, $submission, $ignore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,109 +74,64 @@ class UpdateControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function updateDataProvider(): array
|
public function updateDataProvider(): array
|
||||||
{
|
{
|
||||||
$submissions = [];
|
$configuration = new TestConfiguration;
|
||||||
$all = $this->updateDataSet();
|
|
||||||
foreach ($all as $name => $data) {
|
|
||||||
$submissions[] = [$data];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $submissions;
|
$fieldSet = new FieldSet;
|
||||||
}
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('name', 'uuid'));
|
||||||
|
$configuration->addOptionalFieldSet('name', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('active', 'boolean'));
|
||||||
|
$configuration->addOptionalFieldSet('active', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$fieldSet->addField(Field::createBasic('order', 'order'));
|
||||||
|
$configuration->addOptionalFieldSet('order', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'auto_budget_currency_id';
|
||||||
|
$field->fieldType = 'random-currency-id';
|
||||||
|
$field->ignorableFields = ['auto_budget_currency_code', 'a'];
|
||||||
|
$field->title = 'auto_budget_currency_id';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
|
||||||
|
$configuration->addOptionalFieldSet('auto_budget_id', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'auto_budget_currency_code';
|
||||||
|
$field->fieldType = 'random-currency-code';
|
||||||
|
$field->ignorableFields = ['auto_budget_currency_id', 'b'];
|
||||||
|
$field->title = 'auto_budget_currency_code';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_type', 'random-auto-type'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_amount', 'random-amount'));
|
||||||
|
$fieldSet->addField(Field::createBasic('auto_budget_period', 'random-auto-period'));
|
||||||
|
$configuration->addOptionalFieldSet('auto_budget_code', $fieldSet);
|
||||||
|
|
||||||
|
$fieldSet = new FieldSet;
|
||||||
|
$fieldSet->parameters = [1];
|
||||||
|
$field = new Field;
|
||||||
|
$field->fieldTitle = 'auto_budget_type';
|
||||||
|
$field->fieldType = 'static-auto-none';
|
||||||
|
$field->ignorableFields = ['auto_budget_currency_code', 'auto_budget_currency_id', 'c','auto_budget_period','auto_budget_amount'];
|
||||||
|
$field->expectedReturn = function ($value) {
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
$field->title = 'auto_budget_type';
|
||||||
|
$fieldSet->addField($field);
|
||||||
|
$configuration->addOptionalFieldSet('none', $fieldSet);
|
||||||
|
|
||||||
|
|
||||||
/**
|
return $configuration->generateAll();
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function updateDataSet(): array
|
|
||||||
{
|
|
||||||
$faker = Factory::create();
|
|
||||||
$currencies = [
|
|
||||||
1 => 'EUR',
|
|
||||||
2 => 'HUF',
|
|
||||||
3 => 'GBP',
|
|
||||||
4 => 'UAH',
|
|
||||||
];
|
|
||||||
$repeatFreqs = ['yearly', 'weekly', 'monthly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
$objectGroupId = $faker->numberBetween(1, 2);
|
|
||||||
$objectGroupName = sprintf('Object group %d', $objectGroupId);
|
|
||||||
$rand = rand(1, 4);
|
|
||||||
|
|
||||||
$autoBudgetTypes = ['reset', 'rollover'];
|
|
||||||
$autoBudgetType = $autoBudgetTypes[rand(0, count($autoBudgetTypes) - 1)];
|
|
||||||
|
|
||||||
$set = [
|
|
||||||
'name' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'name' => ['test_value' => $faker->uuid],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'active' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'active' => ['test_value' => $faker->boolean],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'order' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'order' => ['test_value' => $faker->numberBetween(1, 5)],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'auto_budget' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_type' => ['test_value' => $autoBudgetType],
|
|
||||||
'auto_budget_currency_id' => ['test_value' => (string)$rand],
|
|
||||||
'auto_budget_currency_code' => ['test_value' => $currencies[$rand]],
|
|
||||||
'auto_budget_amount' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
|
|
||||||
'auto_budget_period' => ['test_value' => $repeatFreq],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'auto_budget_currency_id' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_currency_id' => ['test_value' => (string)$rand],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['auto_budget_currency_code'],
|
|
||||||
],
|
|
||||||
|
|
||||||
'auto_budget_currency_code' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_currency_code' => ['test_value' => $currencies[$rand]],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['auto_budget_currency_id'],
|
|
||||||
],
|
|
||||||
'auto_budget_amount' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_amount' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'auto_budget_period' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_period' => ['test_value' => $repeatFreq],
|
|
||||||
],
|
|
||||||
'extra_ignore' => [],
|
|
||||||
],
|
|
||||||
'auto_budget_reset' => [
|
|
||||||
'id' => 1,
|
|
||||||
'fields' => [
|
|
||||||
'auto_budget_type' => ['test_value' => 'none'],
|
|
||||||
],
|
|
||||||
'extra_ignore' => ['auto_budget_type', 'auto_budget_period', 'auto_budget_currency_id', 'auto_budget_currency_code', 'auto_budget_amount'],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,8 +9,8 @@ namespace Tests\Objects;
|
|||||||
class FieldSet
|
class FieldSet
|
||||||
{
|
{
|
||||||
public ?array $fields;
|
public ?array $fields;
|
||||||
public string $title;
|
|
||||||
public ?array $parameters;
|
public ?array $parameters;
|
||||||
|
public string $title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FieldSet constructor.
|
* FieldSet constructor.
|
||||||
|
@@ -11,12 +11,14 @@ use RuntimeException;
|
|||||||
*/
|
*/
|
||||||
class TestConfiguration
|
class TestConfiguration
|
||||||
{
|
{
|
||||||
|
protected const MAX_ITERATIONS = 3;
|
||||||
|
public const SHOW_DEBUG = false;
|
||||||
|
public array $ignores;
|
||||||
public array $mandatoryFieldSets;
|
public array $mandatoryFieldSets;
|
||||||
public array $optionalFieldSets;
|
public array $optionalFieldSets;
|
||||||
|
public array $parameters;
|
||||||
|
private array $expected;
|
||||||
private array $submission;
|
private array $submission;
|
||||||
protected const MAX_ITERATIONS = 3;
|
|
||||||
public array $ignores;
|
|
||||||
public array $parameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestConfiguration constructor.
|
* TestConfiguration constructor.
|
||||||
@@ -28,6 +30,7 @@ class TestConfiguration
|
|||||||
$this->optionalFieldSets = [];
|
$this->optionalFieldSets = [];
|
||||||
$this->ignores = [];
|
$this->ignores = [];
|
||||||
$this->parameters = [];
|
$this->parameters = [];
|
||||||
|
$this->expected = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,157 +46,40 @@ class TestConfiguration
|
|||||||
$this->optionalFieldSets[$key] = $set;
|
$this->optionalFieldSets[$key] = $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function generateAll(): array
|
||||||
* @param array $submissions
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function generateIgnores(array $submissions): array
|
|
||||||
{
|
{
|
||||||
$ignores = [];
|
$this->debugMsg('Now in generateAll()');
|
||||||
// loop each submission and find its expected return and create
|
// generate submissions
|
||||||
// a return array with the expected values.
|
$array = $this->generateSubmissions();
|
||||||
/** @var array $submission */
|
//$expected = $this->generateExpected($array);
|
||||||
foreach ($submissions as $index => $submission) {
|
$parameters = $this->parameters;
|
||||||
$ignores[$index] = [];
|
$ignored = $this->ignores;
|
||||||
// loop each field and use the "name" to find it.
|
$expected = $this->expected;
|
||||||
/**
|
|
||||||
* @var string $fieldName
|
// now create a combination for each submission and associated data:
|
||||||
* @var string $fieldValue
|
$final = [];
|
||||||
*/
|
foreach ($array as $index => $submission) {
|
||||||
foreach ($submission as $fieldTitle => $fieldValue) {
|
$final[] = [[
|
||||||
//echo "Now searching for field $fieldTitle on index $index.\n";
|
'submission' => $submission,
|
||||||
$fieldObject = $this->findField($fieldTitle);
|
'expected' => $expected[$index] ?? $submission,
|
||||||
if (null !== $fieldObject) {
|
'ignore' => $ignored[$index] ?? [],
|
||||||
if (0 !== count($fieldObject->ignorableFields)) {
|
'parameters' => $parameters[$index] ?? [],
|
||||||
/** @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;
|
return $final;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
$this->parameters[] = $set->parameters ?? [];
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function generateSubmissions(): array
|
private function generateSubmissions(): array
|
||||||
{
|
{
|
||||||
|
$this->debugMsg('Now in generateSubmissions()');
|
||||||
// first generate standard submissions:
|
// first generate standard submissions:
|
||||||
$this->submission = [];
|
$this->submission = [];
|
||||||
|
|
||||||
// loop each standard submission:
|
// loop each standard submission:
|
||||||
|
$this->debugMsg(sprintf('There are %d mandatory field sets', count($this->mandatoryFieldSets)));
|
||||||
/** @var FieldSet $set */
|
/** @var FieldSet $set */
|
||||||
foreach ($this->mandatoryFieldSets as $set) {
|
foreach ($this->mandatoryFieldSets as $set) {
|
||||||
$this->submission[] = $this->toArray($set);
|
$this->submission[] = $this->toArray($set);
|
||||||
@@ -234,31 +120,34 @@ class TestConfiguration
|
|||||||
// of the submission in the array
|
// of the submission in the array
|
||||||
$index = count($this->submission) - 1;
|
$index = count($this->submission) - 1;
|
||||||
$this->updateIgnorables($index, $customFields);
|
$this->updateIgnorables($index, $customFields);
|
||||||
|
$this->updateExpected($index, $customFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
// no mandatory sets? Loop the optional sets:
|
// no mandatory sets? Loop the optional sets:
|
||||||
if (0 === count($this->mandatoryFieldSets)) {
|
if (0 === count($this->mandatoryFieldSets)) {
|
||||||
// expand the standard submission with extra sets from the optional field set.
|
// expand the standard submission with extra sets from the optional field set.
|
||||||
$setCount = count($this->optionalFieldSets);
|
$setCount = count($this->optionalFieldSets);
|
||||||
// echo "there are " . $setCount . " optional sets\n";
|
$this->debugMsg(sprintf('there are %d optional field sets', $setCount));
|
||||||
if (0 !== $setCount) {
|
if (0 !== $setCount) {
|
||||||
$keys = array_keys($this->optionalFieldSets);
|
$keys = array_keys($this->optionalFieldSets);
|
||||||
// echo " keys to consider are: " . join(', ', $keys) . "\n";
|
$this->debugMsg(sprintf(' keys to consider are: %s', join(', ', $keys)));
|
||||||
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
|
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
|
||||||
// echo " max count is " . $maxCount . "\n";
|
$this->debugMsg(sprintf(' max count is %d', $maxCount));
|
||||||
for ($i = 1; $i <= $maxCount; $i++) {
|
for ($i = 1; $i <= $maxCount; $i++) {
|
||||||
$combinationSets = $this->combinationsOf($i, $keys);
|
$combinationSets = $this->combinationsOf($i, $keys);
|
||||||
// echo " will create " . count($combinationSets) . " extra sets.\n";
|
$this->debugMsg(sprintf(' will create %d extra sets.', count($combinationSets)));
|
||||||
foreach ($combinationSets as $ii => $combinationSet) {
|
foreach ($combinationSets as $ii => $combinationSet) {
|
||||||
// echo " Set " . ($ii + 1) . "/" . count($combinationSets) . " will consist of:\n";
|
$totalCount++;
|
||||||
|
$this->debugMsg(sprintf(' Set #%d will consist of:', $totalCount));
|
||||||
// the custom set is born!
|
// the custom set is born!
|
||||||
//$custom = $this->toArray($set);
|
$custom = [];
|
||||||
$custom = [];
|
$expected = [];
|
||||||
foreach ($combinationSet as $combination) {
|
foreach ($combinationSet as $combination) {
|
||||||
// echo " $combination\n";
|
$this->debugMsg(sprintf(' %s', $combination));
|
||||||
// here we start adding stuff to a copy of the standard submission.
|
// here we start adding stuff to a copy of the standard submission.
|
||||||
/** @var FieldSet $customSet */
|
/** @var FieldSet $customSet */
|
||||||
$customSet = $this->optionalFieldSets[$combination] ?? false;
|
$customSet = $this->optionalFieldSets[$combination] ?? false;
|
||||||
@@ -266,74 +155,63 @@ class TestConfiguration
|
|||||||
// loop each field in this custom set and add them, nothing more.
|
// loop each field in this custom set and add them, nothing more.
|
||||||
/** @var Field $field */
|
/** @var Field $field */
|
||||||
foreach ($customSet->fields as $field) {
|
foreach ($customSet->fields as $field) {
|
||||||
// echo " added field " . $field->fieldTitle . " from custom set " . $combination . "\n";
|
$this->debugMsg(sprintf(' added field %s from custom set %s', $field->fieldTitle, $combination));
|
||||||
$custom = $this->parseField($custom, $field);
|
$custom = $this->parseField($custom, $field);
|
||||||
|
$expected = $this->parseExpected($expected, $field, $custom);
|
||||||
// for each field, add the ignores to the current index (+1!) of
|
// for each field, add the ignores to the current index (+1!) of
|
||||||
// ignores.
|
// ignores.
|
||||||
|
$count = count($this->submission);
|
||||||
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
|
if (null !== $field->ignorableFields && count($field->ignorableFields) > 0) {
|
||||||
$count = count($this->submission);
|
|
||||||
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
||||||
$this->ignores[$count] = array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields)));
|
$this->ignores[$count] = array_values(array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields))));
|
||||||
}
|
}
|
||||||
|
$this->expected[$count] = $expected;
|
||||||
}
|
}
|
||||||
$count = count($this->submission);
|
$count = count($this->submission);
|
||||||
$this->parameters[$count] = $customSet->parameters ?? [];
|
$this->parameters[$count] = $customSet->parameters ?? [];
|
||||||
}
|
}
|
||||||
|
$count = count($this->submission);
|
||||||
$this->submission[] = $custom;
|
$this->submission[] = $custom;
|
||||||
|
$this->debugMsg(sprintf(' Created set #%d', $totalCount));
|
||||||
|
$this->debugMsg(sprintf(' Will submit: %s', json_encode($custom)));
|
||||||
|
$this->debugMsg(sprintf(' Will ignore: %s', json_encode($this->ignores[$count] ?? [])));
|
||||||
|
$this->debugMsg(sprintf(' Will expect: %s', json_encode($this->expected[$count] ?? [])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->debugMsg('Done!');
|
||||||
|
|
||||||
return $this->submission;
|
return $this->submission;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $index
|
* @param FieldSet $set
|
||||||
* @param array $customFields
|
|
||||||
*/
|
|
||||||
function updateIgnorables(int $index, array $customFields): void
|
|
||||||
{
|
|
||||||
if (count($customFields) > 0) {
|
|
||||||
/** @var Field $field */
|
|
||||||
foreach ($customFields as $field) {
|
|
||||||
if (0 !== count($field->ignorableFields)) {
|
|
||||||
$this->ignores[$index] = array_unique(array_values(array_merge($this->ignores[$index], $field->ignorableFields)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $submissions
|
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function generateParameters(array $submissions): array
|
private function toArray(FieldSet $set): array
|
||||||
{
|
{
|
||||||
$params = [];
|
$ignore = [];
|
||||||
$index = 0;
|
$result = [];
|
||||||
/** @var array $submission */
|
$expected = [];
|
||||||
foreach ($submissions as $submission) {
|
/** @var Field $field */
|
||||||
// last one defined param
|
foreach ($set->fields as $field) {
|
||||||
$submission = array_reverse($submission);
|
// this is what we will submit:
|
||||||
foreach ($submission as $key => $value) {
|
$result = $this->parseField($result, $field);
|
||||||
if (array_key_exists($key, $this->optionalFieldSets)) {
|
$expected = $this->parseExpected($expected, $field, $result);
|
||||||
/** @var FieldSet $fieldSet */
|
|
||||||
$fieldSet = $this->optionalFieldSets[$key];
|
|
||||||
if (null !== $fieldSet->parameters) {
|
|
||||||
$params[$index] = $fieldSet->parameters;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (null !== $fieldSet->parameters) {
|
|
||||||
$params[$index] = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $params;
|
// this is what we will ignore:
|
||||||
|
$newIgnore = array_unique($ignore + $field->ignorableFields);
|
||||||
|
$ignore = $newIgnore;
|
||||||
|
$this->debugMsg(sprintf('Merged! ignores %s + %s = %s', json_encode($ignore), json_encode($field->ignorableFields), json_encode($newIgnore)));
|
||||||
|
|
||||||
|
}
|
||||||
|
$this->ignores[] = array_values($ignore);
|
||||||
|
$this->expected[] = $expected;
|
||||||
|
$this->parameters[] = $set->parameters ?? [];
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,6 +281,8 @@ class TestConfiguration
|
|||||||
return $faker->randomFloat(2, 1, 99);
|
return $faker->randomFloat(2, 1, 99);
|
||||||
case 'random-interest-period':
|
case 'random-interest-period':
|
||||||
return $faker->randomElement(['daily', 'monthly', 'yearly']);
|
return $faker->randomElement(['daily', 'monthly', 'yearly']);
|
||||||
|
case 'random-bill-repeat-freq':
|
||||||
|
return $faker->randomElement(['half-year', 'weekly', 'monthly', 'yearly']);
|
||||||
case 'random-past-date':
|
case 'random-past-date':
|
||||||
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
|
return $faker->dateTimeBetween('-3 years', '-1 years')->format('Y-m-d');
|
||||||
case 'random-date-two-year':
|
case 'random-date-two-year':
|
||||||
@@ -436,9 +316,69 @@ class TestConfiguration
|
|||||||
return null;
|
return null;
|
||||||
case 'random-attachment-type':
|
case 'random-attachment-type':
|
||||||
return $faker->randomElement(['Account', 'Budget', 'Bill', 'TransactionJournal', 'PiggyBank', 'Tag',]);
|
return $faker->randomElement(['Account', 'Budget', 'Bill', 'TransactionJournal', 'PiggyBank', 'Tag',]);
|
||||||
|
case 'random-amount-min':
|
||||||
|
return number_format($faker->randomFloat(2, 10, 50), 2);
|
||||||
|
case 'random-amount-max':
|
||||||
|
return number_format($faker->randomFloat(2, 50, 100), 2);
|
||||||
|
case 'random-skip':
|
||||||
|
return $faker->numberBetween(0, 4);
|
||||||
|
case 'random-og-id':
|
||||||
|
return $faker->numberBetween(1, 2);
|
||||||
|
case 'random-auto-type':
|
||||||
|
return $faker->randomElement(['rollover', 'reset']);
|
||||||
|
case 'random-auto-period':
|
||||||
|
return $faker->randomElement(['weekly', 'monthly', 'yearly']);
|
||||||
|
case 'static-auto-none':
|
||||||
|
return 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $expected
|
||||||
|
* @param Field $field
|
||||||
|
* @param array $result
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function parseExpected(array $expected, Field $field, array $result): array
|
||||||
|
{
|
||||||
|
// fieldTitle indicates the position:
|
||||||
|
$positions = explode('/', $field->fieldTitle);
|
||||||
|
$count = count($positions);
|
||||||
|
|
||||||
|
if (1 === $count && null === $field->expectedReturn) {
|
||||||
|
$expected[$field->fieldTitle] = $result[$field->fieldTitle];
|
||||||
|
$this->debugMsg(sprintf(' Expected result of field "%s" = "%s"', $field->fieldTitle, $expected[$field->fieldTitle]));
|
||||||
|
|
||||||
|
return $expected;
|
||||||
|
}
|
||||||
|
if (1 === $count && null !== $field->expectedReturn) {
|
||||||
|
// call the closure!
|
||||||
|
$expected[$field->fieldTitle] = ($field->expectedReturn)($result[$field->fieldTitle]);
|
||||||
|
|
||||||
|
return $expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (3 === $count) {
|
||||||
|
$root = $positions[0];
|
||||||
|
$count = (int)$positions[1];
|
||||||
|
$final = $positions[2];
|
||||||
|
$expected[$root] = array_key_exists($root, $expected) ? $expected[$root] : [];
|
||||||
|
$expected[$root][$count] = array_key_exists($count, $expected[$root]) ? $expected[$root][$count] : [];
|
||||||
|
$expected[$root][$count][$final] = null;
|
||||||
|
|
||||||
|
if (null === $field->expectedReturn) {
|
||||||
|
$expected[$root][$count][$final] = $result[$root][$count][$final] ?? false;
|
||||||
|
}
|
||||||
|
if (null !== $field->expectedReturn) {
|
||||||
|
$expected[$root][$count][$final] = ($field->expectedReturn)($result[$root][$count][$final] ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $expected;
|
||||||
|
}
|
||||||
|
throw new RuntimeException(sprintf('Did not expect count %d from fieldTitle "%s".', $count, $field->fieldTitle));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $k
|
* @param $k
|
||||||
* @param $xs
|
* @param $xs
|
||||||
@@ -464,6 +404,122 @@ class TestConfiguration
|
|||||||
return array_merge($res1, $res2);
|
return array_merge($res1, $res2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $index
|
||||||
|
* @param array $customFields
|
||||||
|
*/
|
||||||
|
function updateIgnorables(int $index, array $customFields): void
|
||||||
|
{
|
||||||
|
if (count($customFields) > 0) {
|
||||||
|
/** @var Field $field */
|
||||||
|
foreach ($customFields as $field) {
|
||||||
|
if (0 !== count($field->ignorableFields)) {
|
||||||
|
$this->ignores[$index] = array_values(array_unique(array_values(array_merge($this->ignores[$index], $field->ignorableFields))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $index
|
||||||
|
* @param array $customFields
|
||||||
|
*/
|
||||||
|
function updateExpected(int $index, array $customFields): void
|
||||||
|
{
|
||||||
|
if (count($customFields) > 0) {
|
||||||
|
/** @var Field $field */
|
||||||
|
foreach ($customFields as $field) {
|
||||||
|
if (null === $field->expectedReturn) {
|
||||||
|
$this->expected[$index][$field->fieldTitle] = $this->submission[$index][$field->fieldTitle];
|
||||||
|
}
|
||||||
|
if (null !== $field->expectedReturn) {
|
||||||
|
$this->expected[$index][$field->fieldTitle] = ($field->expectedReturn)($this->submission[$index][$field->fieldTitle]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 array $submissions
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function generateParameters(array $submissions): array
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$index = 0;
|
||||||
|
/** @var array $submission */
|
||||||
|
foreach ($submissions as $submission) {
|
||||||
|
// last one defined param
|
||||||
|
$submission = array_reverse($submission);
|
||||||
|
foreach ($submission as $key => $value) {
|
||||||
|
if (array_key_exists($key, $this->optionalFieldSets)) {
|
||||||
|
/** @var FieldSet $fieldSet */
|
||||||
|
$fieldSet = $this->optionalFieldSets[$key];
|
||||||
|
if (null !== $fieldSet->parameters) {
|
||||||
|
$params[$index] = $fieldSet->parameters;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (null !== $fieldSet->parameters) {
|
||||||
|
$params[$index] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FieldSet $optionalFieldSet
|
* @param FieldSet $optionalFieldSet
|
||||||
*/
|
*/
|
||||||
@@ -472,6 +528,90 @@ class TestConfiguration
|
|||||||
$this->optionalFieldSet = $optionalFieldSet;
|
$this->optionalFieldSet = $optionalFieldSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
*/
|
||||||
|
private function debugMsg(string $message): void
|
||||||
|
{
|
||||||
|
if (true === self::SHOW_DEBUG) {
|
||||||
|
echo sprintf("%s\n", $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $submissions
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private 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) {
|
||||||
|
$returns[$index][$fieldTitle] = 'hi there';//($fieldObject->expectedReturn)($submissions[$index][$fieldTitle]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null === $fieldObject) {
|
||||||
|
die('null field object :(');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $returns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 $existing
|
* @param array $existing
|
||||||
* @param array $config
|
* @param array $config
|
||||||
|
@@ -96,6 +96,7 @@ trait TestHelpers
|
|||||||
{
|
{
|
||||||
$submission = $content['submission'];
|
$submission = $content['submission'];
|
||||||
$ignore = $content['ignore'];
|
$ignore = $content['ignore'];
|
||||||
|
$expected = $content['expected'];
|
||||||
$response = $this->put($route, $submission, ['Accept' => 'application/json']);
|
$response = $this->put($route, $submission, ['Accept' => 'application/json']);
|
||||||
$responseBody = $response->content();
|
$responseBody = $response->content();
|
||||||
$responseJson = json_decode($responseBody, true);
|
$responseJson = json_decode($responseBody, true);
|
||||||
@@ -105,21 +106,22 @@ trait TestHelpers
|
|||||||
|
|
||||||
// get return and compare each field
|
// get return and compare each field
|
||||||
$responseAttributes = $responseJson['data']['attributes'];
|
$responseAttributes = $responseJson['data']['attributes'];
|
||||||
$this->comparePUTArray($route, $submission, $responseAttributes, $ignore);
|
$this->comparePUTArray($route, $submission, $responseAttributes, $expected, $ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
* @param array $response
|
* @param array $response
|
||||||
|
* @param array $expected
|
||||||
* @param array $ignore
|
* @param array $ignore
|
||||||
*/
|
*/
|
||||||
private function comparePUTArray(string $url, array $submission, array $response, array $ignore): void
|
private function comparePUTArray(string $url, array $submission, array $response, array $expected, array $ignore): void
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($response as $key => $value) {
|
foreach ($response as $key => $value) {
|
||||||
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
|
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
|
||||||
$this->comparePUTArray($url, $submission[$key], $value, $ignore[$key] ?? []);
|
$this->comparePUTArray($url, $submission[$key], $value, $expected[$key], $ignore[$key] ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($submission[$key])) {
|
if (isset($submission[$key])) {
|
||||||
@@ -128,17 +130,18 @@ trait TestHelpers
|
|||||||
}
|
}
|
||||||
if (!in_array($key, $ignore, true)) {
|
if (!in_array($key, $ignore, true)) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
"Field '%s' with value %s is expected to be %s.\nSubmitted:\n%s\nIgnored: %s\nReturned\n%s\nURL: %s",
|
"Field '%s' with value %s is expected to be %s.\nSubmitted: %s\nIgnored: %s\nExpected: %s\nReturned: %s\nURL: %s",
|
||||||
$key,
|
$key,
|
||||||
var_export($value, true),
|
var_export($value, true),
|
||||||
var_export($submission[$key], true),
|
var_export($expected[$key], true),
|
||||||
json_encode($submission),
|
json_encode($submission),
|
||||||
json_encode($ignore),
|
json_encode($ignore),
|
||||||
|
json_encode($expected),
|
||||||
json_encode($response),
|
json_encode($response),
|
||||||
$url
|
$url
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($value, $submission[$key], $message);
|
$this->assertEquals($value, $expected[$key], $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user