mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix tests for account
This commit is contained in:
@@ -61,9 +61,9 @@ class StoreControllerTest extends TestCase
|
||||
/**
|
||||
* @param array $submission
|
||||
*
|
||||
* newStoreDataProvider / emptyDataProvider
|
||||
* storeDataProvider / emptyDataProvider
|
||||
*
|
||||
* @dataProvider newStoreDataProvider
|
||||
* @dataProvider emptyDataProvider
|
||||
*/
|
||||
public function testStore(array $submission): void
|
||||
{
|
||||
@@ -82,7 +82,7 @@ class StoreControllerTest extends TestCase
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function newStoreDataProvider(): array
|
||||
public function storeDataProvider(): array
|
||||
{
|
||||
// some test configs:
|
||||
$configuration = new TestConfiguration;
|
||||
|
@@ -22,9 +22,11 @@
|
||||
namespace Tests\Api\Models\Account;
|
||||
|
||||
|
||||
use Faker\Factory;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\Objects\Field;
|
||||
use Tests\Objects\FieldSet;
|
||||
use Tests\Objects\TestConfiguration;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CollectsValues;
|
||||
use Tests\Traits\RandomValues;
|
||||
@@ -49,192 +51,176 @@ class UpdateControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider updateDataProvider
|
||||
* @param array $submission
|
||||
*
|
||||
* newStoreDataProvider / emptyDataProvider
|
||||
*
|
||||
* @dataProvider newUpdateDataProvider
|
||||
*/
|
||||
public function testUpdate(array $submission): void
|
||||
{
|
||||
$this->markTestSkipped('Skipped');
|
||||
$ignore = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'currency_code',
|
||||
'currency_symbol',
|
||||
'currency_decimal_places',
|
||||
'current_balance',
|
||||
];
|
||||
$route = route('api.v1.accounts.update', [$submission['id']]);
|
||||
if ([] === $submission) {
|
||||
$this->markTestSkipped('Empty provider.');
|
||||
}
|
||||
Log::debug('testStoreUpdated()');
|
||||
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.accounts.update', $submission['parameters']);
|
||||
$this->updatedUpdateAndCompare($route, $submission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only create optional sets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataProvider(): array
|
||||
public function newUpdateDataProvider(): array
|
||||
{
|
||||
$submissions = [];
|
||||
$all = $this->updateDataSet();
|
||||
foreach ($all as $name => $data) {
|
||||
$submissions[] = [$data];
|
||||
$configuration = new TestConfiguration;
|
||||
|
||||
// optional field sets (for all test configs)
|
||||
$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('iban', 'iban'));
|
||||
$configuration->addOptionalFieldSet('iban', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('bic', 'bic'));
|
||||
$configuration->addOptionalFieldSet('bic', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('account_number', 'iban'));
|
||||
$configuration->addOptionalFieldSet('account_number', $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('include_net_worth', 'boolean'));
|
||||
$configuration->addOptionalFieldSet('include_net_worth', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
|
||||
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('virtual_balance', 'random-amount'));
|
||||
$configuration->addOptionalFieldSet('virtual_balance', $fieldSet);
|
||||
|
||||
$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);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('account_role', 'random-asset-accountRole'));
|
||||
$configuration->addOptionalFieldSet('account_role', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('notes', 'uuid'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('latitude', 'latitude'));
|
||||
$fieldSet->addField(Field::createBasic('longitude', 'longitude'));
|
||||
$fieldSet->addField(Field::createBasic('zoom_level', 'random-zoom_level'));
|
||||
$configuration->addOptionalFieldSet('notes', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [1];
|
||||
$fieldSet->addField(Field::createBasic('opening_balance', 'random-amount'));
|
||||
$fieldSet->addField(Field::createBasic('opening_balance_date', 'random-past-date'));
|
||||
$configuration->addOptionalFieldSet('ob', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [7];
|
||||
$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->addOptionalFieldSet('cc1', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [13];
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'liability_type';
|
||||
$field->fieldType = 'random-liability-type';
|
||||
$field->ignorableFields = ['account_role'];
|
||||
$field->title = 'liability_type';
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('account_role', 'null'));
|
||||
$fieldSet->addField(Field::createBasic('credit_card_type', 'null'));
|
||||
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
|
||||
$configuration->addOptionalFieldSet('liability-1', $fieldSet);
|
||||
|
||||
$fieldSet = new FieldSet;
|
||||
$fieldSet->parameters = [13];
|
||||
$fieldSet->addField(Field::createBasic('interest', 'random-percentage'));
|
||||
$field = new Field;
|
||||
$field->fieldTitle = 'interest_period';
|
||||
$field->fieldType = 'random-interest-period';
|
||||
$field->ignorableFields = ['account_role'];
|
||||
$field->title = 'interest_period';
|
||||
$fieldSet->addField($field);
|
||||
$fieldSet->addField(Field::createBasic('account_role', 'null'));
|
||||
$fieldSet->addField(Field::createBasic('credit_card_type', 'null'));
|
||||
$fieldSet->addField(Field::createBasic('monthly_payment_date', 'null'));
|
||||
$configuration->addOptionalFieldSet('liability-2', $fieldSet);
|
||||
|
||||
// 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 $submissions;
|
||||
return $final;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateDataSet(): array
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$currencies = ['EUR', 'GBP', 'USD', 'HUF'];
|
||||
$currencyCode = $currencies[rand(0, count($currencies) - 1)];
|
||||
|
||||
$accountRoles = ['defaultAsset', 'sharedAsset', 'savingAsset'];
|
||||
$accountRole = $accountRoles[rand(0, count($accountRoles) - 1)];
|
||||
|
||||
$liabilityRoles = ['loan', 'debt', 'mortgage'];
|
||||
$liabilityRole = $liabilityRoles[rand(0, count($liabilityRoles) - 1)];
|
||||
|
||||
$interestPeriods = ['daily', 'monthly', 'yearly'];
|
||||
$interestPeriod = $interestPeriods[rand(0, count($interestPeriods) - 1)];
|
||||
|
||||
$set = [
|
||||
'name' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'name' => ['test_value' => $faker->uuid],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'active' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'active' => ['test_value' => $faker->boolean],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'iban' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'iban' => ['test_value' => $faker->iban()],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'bic' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'bic' => ['test_value' => $faker->swiftBicNumber],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'account_number' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'account_number' => ['test_value' => $faker->iban()],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'order' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'order' => ['test_value' => $faker->numberBetween(1, 10)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'include_net_worth' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'include_net_worth' => ['test_value' => $faker->boolean],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'virtual_balance' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'virtual_balance' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'currency_id' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'currency_id' => ['test_value' => (string)$faker->numberBetween(1, 10)],
|
||||
],
|
||||
'extra_ignore' => ['currency_code'],
|
||||
],
|
||||
'currency_code' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'currency_code' => ['test_value' => $currencyCode],
|
||||
],
|
||||
'extra_ignore' => ['currency_id'],
|
||||
],
|
||||
'account_role' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'account_role' => ['test_value' => $accountRole],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'notes' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'notes' => ['test_value' => join(' ', $faker->words(3))],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'location' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'longitude' => ['test_value' => $faker->longitude],
|
||||
'latitude' => ['test_value' => $faker->latitude],
|
||||
'zoom_level' => ['test_value' => $faker->numberBetween(1, 10)],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'ob' => [
|
||||
'id' => 1,
|
||||
'fields' => [
|
||||
'opening_balance' => ['test_value' => number_format($faker->randomFloat(2, 10, 100), 2)],
|
||||
'opening_balance_date' => ['test_value' => $faker->date('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'cc2' => [
|
||||
'id' => 7,
|
||||
'fields' => [
|
||||
'monthly_payment_date' => ['test_value' => $faker->date('Y-m-d')],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'cc3' => [
|
||||
'id' => 7,
|
||||
'fields' => [
|
||||
'monthly_payment_date' => ['test_value' => $faker->date('Y-m-d')],
|
||||
'credit_card_type' => ['test_value' => 'monthlyFull'],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'liabilityA' => [
|
||||
'id' => 13,
|
||||
'fields' => [
|
||||
'liability_type' => ['test_value' => $liabilityRole],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
'liabilityB' => [
|
||||
'id' => 13,
|
||||
'fields' => [
|
||||
'interest' => ['test_value' => $faker->randomFloat(2, 1, 99)],
|
||||
'interest_period' => ['test_value' => $interestPeriod],
|
||||
],
|
||||
'extra_ignore' => [],
|
||||
],
|
||||
];
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -10,13 +10,15 @@ class FieldSet
|
||||
{
|
||||
public ?array $fields;
|
||||
public string $title;
|
||||
public ?array $parameters;
|
||||
|
||||
/**
|
||||
* FieldSet constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->fields = [];
|
||||
$this->fields = [];
|
||||
$this->parameters = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,7 @@ class TestConfiguration
|
||||
private array $submission;
|
||||
protected const MAX_ITERATIONS = 3;
|
||||
public array $ignores;
|
||||
public array $parameters;
|
||||
|
||||
/**
|
||||
* TestConfiguration constructor.
|
||||
@@ -26,6 +27,7 @@ class TestConfiguration
|
||||
$this->mandatoryFieldSets = [];
|
||||
$this->optionalFieldSets = [];
|
||||
$this->ignores = [];
|
||||
$this->parameters = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +179,8 @@ class TestConfiguration
|
||||
$result = $this->parseField($result, $field);
|
||||
$ignore = array_unique($ignore + $field->ignorableFields);
|
||||
}
|
||||
$this->ignores[] = $ignore;
|
||||
$this->ignores[] = $ignore;
|
||||
$this->parameters[] = $set->parameters ?? [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -227,9 +230,9 @@ class TestConfiguration
|
||||
// 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)));
|
||||
$count = count($this->submission);
|
||||
$currentIgnoreSet = $this->ignores[$count] ?? [];
|
||||
//$this->ignores[$count] = array_unique(array_values(array_merge($currentIgnoreSet, $field->ignorableFields)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,9 +242,87 @@ class TestConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
// no mandatory sets? Loop the optional sets:
|
||||
if (0 === count($this->mandatoryFieldSets)) {
|
||||
// expand the standard submission with extra sets from the optional field set.
|
||||
$setCount = count($this->optionalFieldSets);
|
||||
// echo "there are " . $setCount . " optional sets\n";
|
||||
if (0 !== $setCount) {
|
||||
$keys = array_keys($this->optionalFieldSets);
|
||||
// echo " keys to consider are: " . join(', ', $keys) . "\n";
|
||||
$maxCount = count($keys) > self::MAX_ITERATIONS ? self::MAX_ITERATIONS : count($keys);
|
||||
// echo " max count is " . $maxCount . "\n";
|
||||
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);
|
||||
$custom = [];
|
||||
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)));
|
||||
}
|
||||
}
|
||||
$count = count($this->submission);
|
||||
$this->parameters[$count] = $customSet->parameters ?? [];
|
||||
}
|
||||
$this->submission[] = $custom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 array $current
|
||||
* @param Field $field
|
||||
@@ -328,6 +409,8 @@ class TestConfiguration
|
||||
return $faker->longitude;
|
||||
case 'random-zoom_level':
|
||||
return $faker->numberBetween(1, 12);
|
||||
case 'null':
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -210,7 +210,6 @@ trait TestHelpers
|
||||
// var_dump($expected[$key]);
|
||||
// exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -222,10 +221,9 @@ trait TestHelpers
|
||||
*/
|
||||
protected function storeAndCompare(string $route, array $content): void
|
||||
{
|
||||
$submission = $content['fields'];
|
||||
$parameters = $content['parameters'];
|
||||
$ignore = $content['ignore'];
|
||||
// submit!
|
||||
$submission = $content['fields'];
|
||||
$parameters = $content['parameters'];
|
||||
$ignore = $content['ignore'];
|
||||
$response = $this->post(route($route, $parameters), $submission, ['Accept' => 'application/json']);
|
||||
$responseBody = $response->content();
|
||||
$responseJson = json_decode($responseBody, true);
|
||||
@@ -257,6 +255,62 @@ trait TestHelpers
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $content
|
||||
*/
|
||||
protected function updatedUpdateAndCompare(string $route, array $content): void
|
||||
{
|
||||
$submission = $content['submission'];
|
||||
$ignore = $content['ignore'];
|
||||
$response = $this->put($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->updatedCompareUpdatedArray($route, $submission, $responseAttributes, $ignore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $submission
|
||||
* @param array $response
|
||||
* @param array $ignore
|
||||
*/
|
||||
private function updatedCompareUpdatedArray(string $url, array $submission, array $response, array $ignore): void
|
||||
{
|
||||
|
||||
foreach ($response as $key => $value) {
|
||||
if (is_array($value) && array_key_exists($key, $submission) && is_array($submission[$key])) {
|
||||
$this->updatedCompareUpdatedArray($url, $submission[$key], $value, $ignore[$key] ?? []);
|
||||
}
|
||||
|
||||
if (isset($submission[$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\nURL: %s",
|
||||
$key,
|
||||
var_export($value, true),
|
||||
var_export($submission[$key], true),
|
||||
json_encode($submission),
|
||||
json_encode($ignore),
|
||||
json_encode($response),
|
||||
$url
|
||||
);
|
||||
|
||||
$this->assertEquals($value, $submission[$key], $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some specials:
|
||||
*
|
||||
|
Reference in New Issue
Block a user