mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add data provider and test for form data normalization
Introduced a `dataProviderFormDataToNormalize` method to supply test cases for normalization. Added `testDataNormalization` to validate form data normalization and ensure consistency between normalized and denormalized data.
This commit is contained in:
parent
a2713041da
commit
3f218e7183
@ -134,6 +134,40 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
*/
|
||||
abstract public static function getQueryBuilders();
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
foreach (static::getFormData() as $data) {
|
||||
yield [$data, 1, []];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
||||
{
|
||||
$filter = $this->getFilter();
|
||||
|
||||
$normalized = $filter->normalizeFormData($data);
|
||||
$actual = $filter->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertEqualsCanonicalizing(array_keys($data), array_keys($actual));
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
self::assertArrayHasKey($key, $actual);
|
||||
if (array_key_exists($key, $customAssert)) {
|
||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
||||
} else {
|
||||
self::assertEquals($value, $actual[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare aliases array before and after that filter alter query.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user