From 67dd6a3fd986cae9a90a8c2c526464c06f525863 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 19 Jul 2024 10:08:53 +0200 Subject: [PATCH] fix tests --- .../DataCollector/FormDataExtractorTest.php | 90 +++++++++++++------ 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/Tests/Extension/DataCollector/FormDataExtractorTest.php b/Tests/Extension/DataCollector/FormDataExtractorTest.php index ec01721c7..b8a1fee37 100644 --- a/Tests/Extension/DataCollector/FormDataExtractorTest.php +++ b/Tests/Extension/DataCollector/FormDataExtractorTest.php @@ -26,6 +26,7 @@ use Symfony\Component\Form\ResolvedFormType; use Symfony\Component\Form\ResolvedFormTypeFactory; use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer; +use Symfony\Component\Validator\Constraints\WordCount; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; @@ -300,35 +301,68 @@ public function testExtractSubmittedDataStoresErrorCause() $form->addError(new FormError('Invalid!', null, [], null, $violation)); $origin = spl_object_hash($form); - $this->assertDumpMatchesFormat(<< array:1 [ - "norm" => "Foobar" - ] - "errors" => array:1 [ - 0 => array:3 [ - "message" => "Invalid!" - "origin" => "$origin" - "trace" => array:2 [ - 0 => Symfony\Component\Validator\ConstraintViolation { - -message: "Foo" - -messageTemplate: "Foo" - -parameters: [] - -plural: null - -root: "Root" - -propertyPath: "property.path" - -invalidValue: "Invalid!" - -constraint: null - -code: null - -cause: Exception {%A} + if (class_exists(WordCount::class)) { + $expectedFormat = <<<"EODUMP" + array:3 [ + "submitted_data" => array:1 [ + "norm" => "Foobar" + ] + "errors" => array:1 [ + 0 => array:3 [ + "message" => "Invalid!" + "origin" => "$origin" + "trace" => array:2 [ + 0 => Symfony\Component\Validator\ConstraintViolation { + -message: "Foo" + -messageTemplate: "Foo" + -parameters: [] + -root: "Root" + -propertyPath: "property.path" + -invalidValue: "Invalid!" + -plural: null + -code: null + -constraint: null + -cause: Exception {%A} + } + 1 => Exception {#1} + ] + ] + ] + "synchronized" => true + ] + EODUMP; + } else { + $expectedFormat = <<<"EODUMP" + array:3 [ + "submitted_data" => array:1 [ + "norm" => "Foobar" + ] + "errors" => array:1 [ + 0 => array:3 [ + "message" => "Invalid!" + "origin" => "$origin" + "trace" => array:2 [ + 0 => Symfony\Component\Validator\ConstraintViolation { + -message: "Foo" + -messageTemplate: "Foo" + -parameters: [] + -plural: null + -root: "Root" + -propertyPath: "property.path" + -invalidValue: "Invalid!" + -constraint: null + -code: null + -cause: Exception {%A} + } + 1 => Exception {#1} + ] + ] + ] + "synchronized" => true + ] + EODUMP; } - 1 => Exception {#1} - ] - ] - ] - "synchronized" => true -] -EODUMP + $this->assertDumpMatchesFormat($expectedFormat , $this->dataExtractor->extractSubmittedData($form) );