mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Expand test cases.
This commit is contained in:
@@ -73,14 +73,18 @@ class StoreController extends Controller
|
|||||||
|
|
||||||
// currency is not mandatory:
|
// currency is not mandatory:
|
||||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||||
$factory = app(TransactionCurrencyFactory::class);
|
$factory = app(TransactionCurrencyFactory::class);
|
||||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||||
$data['currency_id'] = $currency->id;
|
$data['currency_id'] = $currency->id;
|
||||||
unset($data['currency_code']);
|
unset($data['currency_code']);
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('currency_id', $data)) {
|
||||||
|
$currency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
||||||
|
$data['currency_id'] = $currency->id;
|
||||||
|
}
|
||||||
|
|
||||||
$availableBudget = $this->abRepository->store($data);
|
$availableBudget = $this->abRepository->store($data);
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
|
||||||
/** @var AvailableBudgetTransformer $transformer */
|
/** @var AvailableBudgetTransformer $transformer */
|
||||||
$transformer = app(AvailableBudgetTransformer::class);
|
$transformer = app(AvailableBudgetTransformer::class);
|
||||||
|
24
phpunit.xml
24
phpunit.xml
@@ -35,29 +35,9 @@
|
|||||||
</include>
|
</include>
|
||||||
</coverage>
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="ApiAccount">
|
<testsuite name="Api">
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Account</directory>
|
<directory suffix="Test.php">./tests/Api/Models</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="ApiAttachment">
|
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Attachment</directory>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="ApiAb">
|
|
||||||
<directory suffix="Test.php">./tests/Api/Models/AvailableBudget</directory>
|
|
||||||
</testsuite>
|
|
||||||
<testsuite name="ApiBill">
|
|
||||||
<directory suffix="Test.php">./tests/Api/Models/Bill</directory>
|
|
||||||
</testsuite>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<testsuite name="Api">
|
|
||||||
<directory suffix="Test.php">./tests/Api</directory>
|
|
||||||
</testsuite>
|
|
||||||
|
|
||||||
|
|
||||||
<testsuite name="Unit">
|
|
||||||
<directory suffix="Test.php">./tests/Unit</directory>
|
|
||||||
</testsuite>
|
|
||||||
-->
|
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
|
@@ -50,9 +50,9 @@ class StoreControllerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* @ data Provider storeDataProvider
|
* @dataProvider storeDataProvider
|
||||||
*
|
*
|
||||||
* @dataProvider emptyDataProvider
|
* @ data Provider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
@@ -193,6 +193,7 @@ class StoreControllerTest extends TestCase
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'asset' => [
|
'asset' => [
|
||||||
|
'parameters' => [],
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => $faker->name . join(' ', $faker->words(2)),
|
'name' => $faker->name . join(' ', $faker->words(2)),
|
||||||
'type' => 'asset',
|
'type' => 'asset',
|
||||||
@@ -200,12 +201,14 @@ class StoreControllerTest extends TestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
'expense' => [
|
'expense' => [
|
||||||
|
'parameters' => [],
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => $faker->name,
|
'name' => $faker->name,
|
||||||
'type' => 'expense',
|
'type' => 'expense',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'liability' => [
|
'liability' => [
|
||||||
|
'parameters' => [],
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => $faker->name,
|
'name' => $faker->name,
|
||||||
'type' => 'liabilities',
|
'type' => 'liabilities',
|
||||||
|
@@ -51,8 +51,8 @@ class StoreControllerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* @dataProvider storeDataProvider
|
* @ data Provider storeDataProvider
|
||||||
* @ data Provider emptyDataProvider
|
* @dataProvider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
@@ -105,7 +105,8 @@ class StoreControllerTest extends TestCase
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'default_file' => [
|
'default_file' => [
|
||||||
'fields' => [
|
'parameters' => [],
|
||||||
|
'fields' => [
|
||||||
'filename' => join(' ', $faker->words(3)),
|
'filename' => join(' ', $faker->words(3)),
|
||||||
'attachable_type' => $type,
|
'attachable_type' => $type,
|
||||||
'attachable_id' => '1',
|
'attachable_id' => '1',
|
||||||
@@ -119,7 +120,8 @@ class StoreControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
private function optionalSets(): array
|
private function optionalSets(): array
|
||||||
{
|
{
|
||||||
$faker = Factory::create();
|
$faker = Factory::create();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => [
|
'title' => [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
|
@@ -51,8 +51,8 @@ class StoreControllerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* @ data Provider storeDataProvider
|
* @dataProvider storeDataProvider
|
||||||
* @dataProvider emptyDataProvider
|
* @ data Provider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
|
@@ -51,8 +51,8 @@ class StoreControllerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @param array $submission
|
* @param array $submission
|
||||||
*
|
*
|
||||||
* @ data Provider storeDataProvider
|
* @dataProvider storeDataProvider
|
||||||
* @dataProvider emptyDataProvider
|
* @ data Provider emptyDataProvider
|
||||||
*/
|
*/
|
||||||
public function testStore(array $submission): void
|
public function testStore(array $submission): void
|
||||||
{
|
{
|
||||||
|
@@ -98,11 +98,8 @@ class StoreControllerTest extends TestCase
|
|||||||
private function minimalSets(): array
|
private function minimalSets(): array
|
||||||
{
|
{
|
||||||
$faker = Factory::create();
|
$faker = Factory::create();
|
||||||
$repeatFreqs = ['yearly', 'weekly', 'monthly'];
|
|
||||||
$repeatFreq = $repeatFreqs[rand(0, count($repeatFreqs) - 1)];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'default_bill' => [
|
'default_budget' => [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => join(',', $faker->words(5)),
|
'name' => join(',', $faker->words(5)),
|
||||||
],
|
],
|
||||||
|
163
tests/Api/Models/BudgetLimit/StoreControllerTest.php
Normal file
163
tests/Api/Models/BudgetLimit/StoreControllerTest.php
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* StoreControllerTest.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\Models\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use Faker\Factory;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Tests\Traits\CollectsValues;
|
||||||
|
use Tests\Traits\RandomValues;
|
||||||
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class StoreControllerTest
|
||||||
|
*/
|
||||||
|
class StoreControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RandomValues, TestHelpers, CollectsValues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Passport::actingAs($this->user());
|
||||||
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $submission
|
||||||
|
*
|
||||||
|
* @dataProvider storeDataProvider
|
||||||
|
* @ data Provider emptyDataProvider
|
||||||
|
*/
|
||||||
|
public function testStore(array $submission): void
|
||||||
|
{
|
||||||
|
if ([] === $submission) {
|
||||||
|
$this->markTestSkipped('Empty data provider');
|
||||||
|
}
|
||||||
|
// run account store with a minimal data set:
|
||||||
|
$route = 'api.v1.budgets.limits.store';
|
||||||
|
$this->storeAndCompare($route, $submission);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function emptyDataProvider(): array
|
||||||
|
{
|
||||||
|
return [[[]]];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function storeDataProvider(): array
|
||||||
|
{
|
||||||
|
$minimalSets = $this->minimalSets();
|
||||||
|
$optionalSets = $this->optionalSets();
|
||||||
|
$regenConfig = [
|
||||||
|
'start' => function () {
|
||||||
|
$faker = Factory::create();
|
||||||
|
|
||||||
|
return $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d');
|
||||||
|
},
|
||||||
|
'end' => function () {
|
||||||
|
$faker = Factory::create();
|
||||||
|
|
||||||
|
return $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d');
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function minimalSets(): array
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'default_bl' => [
|
||||||
|
'parameters' => [1],
|
||||||
|
'fields' => [
|
||||||
|
'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'),
|
||||||
|
'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
||||||
|
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \array[][]
|
||||||
|
*/
|
||||||
|
private function optionalSets(): array
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
$currencies = [
|
||||||
|
1 => 'EUR',
|
||||||
|
2 => 'HUF',
|
||||||
|
3 => 'GBP',
|
||||||
|
4 => 'UAH',
|
||||||
|
];
|
||||||
|
$rand = rand(1, 4);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'currency_id' => [
|
||||||
|
'fields' => [
|
||||||
|
'currency_id' => $rand,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'currency_code' => [
|
||||||
|
'fields' => [
|
||||||
|
'currency_code' => $currencies[$rand],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'start' => [
|
||||||
|
'fields' => [
|
||||||
|
'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'end' => [
|
||||||
|
'fields' => [
|
||||||
|
'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'amount' => [
|
||||||
|
'fields' => [
|
||||||
|
'amount' => number_format($faker->randomFloat(2, 10, 100), 2),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
118
tests/Api/Models/BudgetLimit/UpdateControllerTest.php
Normal file
118
tests/Api/Models/BudgetLimit/UpdateControllerTest.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* UpdateControllerTest.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\Models\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use Faker\Factory;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Tests\Traits\CollectsValues;
|
||||||
|
use Tests\Traits\RandomValues;
|
||||||
|
use Tests\Traits\TestHelpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UpdateControllerTest
|
||||||
|
*/
|
||||||
|
class UpdateControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RandomValues, TestHelpers, CollectsValues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Passport::actingAs($this->user());
|
||||||
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider updateDataProvider
|
||||||
|
*/
|
||||||
|
public function testUpdate(array $submission): void
|
||||||
|
{
|
||||||
|
$ignore = [
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
$route = route('api.v1.budgets.limits.update', [$submission['id'], $submission['bl_id']]);
|
||||||
|
|
||||||
|
$this->updateAndCompare($route, $submission, $ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function updateDataProvider(): array
|
||||||
|
{
|
||||||
|
$submissions = [];
|
||||||
|
$all = $this->updateDataSet();
|
||||||
|
foreach ($all as $name => $data) {
|
||||||
|
$submissions[] = [$data];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $submissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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,
|
||||||
|
'bl_id' => 1,
|
||||||
|
'fields' => [
|
||||||
|
'amount' => ['test_value' => number_format($faker->randomFloat(2,10,100), 2)],
|
||||||
|
],
|
||||||
|
'extra_ignore' => [],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -48,12 +48,11 @@ trait TestHelpers
|
|||||||
$body[$field] = $value;
|
$body[$field] = $value;
|
||||||
}
|
}
|
||||||
// minimal set is part of all submissions:
|
// minimal set is part of all submissions:
|
||||||
$submissions[] = [$body];
|
$submissions[] = [['fields' => $body, 'parameters' => $set['parameters'] ?? []]];
|
||||||
|
|
||||||
// then loop and add fields:
|
// then loop and add fields:
|
||||||
$optionalSets = $startOptionalSets;
|
$optionalSets = $startOptionalSets;
|
||||||
$keys = array_keys($optionalSets);
|
$keys = array_keys($optionalSets);
|
||||||
$submissions = [];
|
|
||||||
for ($i = 1; $i <= count($keys); $i++) {
|
for ($i = 1; $i <= count($keys); $i++) {
|
||||||
$combinations = $this->combinationsOf($i, $keys);
|
$combinations = $this->combinationsOf($i, $keys);
|
||||||
// expand body with N extra fields:
|
// expand body with N extra fields:
|
||||||
@@ -67,12 +66,11 @@ trait TestHelpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
$second = $this->regenerateValues($second, $regenConfig);
|
$second = $this->regenerateValues($second, $regenConfig);
|
||||||
$submissions[] = [$second];
|
$submissions[] = [['fields' => $second, 'parameters' => $set['parameters'] ?? []]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($second);
|
unset($second);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $submissions;
|
return $submissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,71 +193,25 @@ trait TestHelpers
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if (!compareResult($uValue, $currentProperties[$uKey]) && !in_array($uKey, $fieldsToUpdate)) {
|
|
||||||
// if (!is_array($currentProperties[$uKey]) && !is_array($uValue)) {
|
|
||||||
// $log->warning(
|
|
||||||
// sprintf('Field %s is updated from <code>%s</code> to <code>%s</code> but shouldnt be.', $uKey, $currentProperties[$uKey], $uValue)
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// $log->warning(
|
|
||||||
// sprintf('Field %s is updated from <code>(array)</code> to <code>(array)</code> but shouldnt be.', $uKey)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// $log->debug(json_encode($currentProperties));
|
|
||||||
// $log->debug(json_encode($updatedAttributes));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (in_array($uKey, $fieldsToUpdate) && compareResult($uValue, $testBody[$uKey])) {
|
|
||||||
// $log->debug(sprintf('Field %s is updated and this is OK.', $uKey));
|
|
||||||
// }
|
|
||||||
// if (in_array($uKey, $fieldsToUpdate) && !compareResult($uValue, $testBody[$uKey])) {
|
|
||||||
// if (!is_array($uValue) && !is_array($testBody[$uKey])) {
|
|
||||||
// $log->warning(sprintf('Field "%s" is different: %s but must be %s!', $uKey, var_export($uValue, true), var_export($testBody[$uKey], true)));
|
|
||||||
// $log->debug(json_encode($currentProperties));
|
|
||||||
// $log->debug(json_encode($updatedAttributes));
|
|
||||||
// } else {
|
|
||||||
// $log->warning(sprintf('Field "%s" is different!', $uKey));
|
|
||||||
// $log->debug(json_encode(filterArray($currentProperties)));
|
|
||||||
// $log->debug(json_encode(filterArray($updatedAttributes)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// // OLD
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// $updatedResponseBody = json_decode($updateResponse->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
|
||||||
// $updatedAttributes = $updatedResponseBody['data']['attributes'];
|
|
||||||
// if (array_key_exists('key', $endpoint) && array_key_exists('level', $endpoint)) {
|
|
||||||
// $key = $endpoint['key'];
|
|
||||||
// $level = $endpoint['level'];
|
|
||||||
// $updatedAttributes = $updatedResponseBody['data']['attributes'][$key][$level];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // END OLD
|
|
||||||
//
|
|
||||||
// var_dump($submissionJson);
|
|
||||||
// exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param array $submission
|
* @param array $content
|
||||||
*/
|
*/
|
||||||
protected function storeAndCompare(string $route, array $submission, ?array $ignore = null): void
|
protected function storeAndCompare(string $route, array $content, ?array $ignore = null): void
|
||||||
{
|
{
|
||||||
$ignore = $ignore ?? [];
|
$ignore = $ignore ?? [];
|
||||||
|
$submission = $content['fields'];
|
||||||
|
$parameters = $content['parameters'];
|
||||||
// submit!
|
// submit!
|
||||||
$response = $this->post(route($route), $submission, ['Accept' => 'application/json']);
|
$response = $this->post(route($route, $parameters), $submission, ['Accept' => 'application/json']);
|
||||||
$responseBody = $response->content();
|
$responseBody = $response->content();
|
||||||
$responseJson = json_decode($responseBody, true);
|
$responseJson = json_decode($responseBody, true);
|
||||||
$status = $response->getStatusCode();
|
$status = $response->getStatusCode();
|
||||||
$this->assertEquals($status, 200, sprintf("Submission: %s\nResponse: %s", json_encode($submission), $responseBody));
|
$this->assertEquals($status, 200, sprintf("Submission: %s\nResponse: %s", json_encode($submission), $responseBody));
|
||||||
|
|
||||||
|
|
||||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||||
|
|
||||||
// compare results:
|
// compare results:
|
||||||
|
Reference in New Issue
Block a user