From 3f218e718394a53eb619b13d7737336629d8c78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 8 Apr 2025 14:09:26 +0200 Subject: [PATCH] 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. --- .../Test/Export/AbstractFilterTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index f064bae59..c34cfc706 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -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. *