Skip to content

Commit 848ff37

Browse files
committed
[BUGFIX] Adjust Symfony Validator tests for 7.4 compatibility
The number of arguments passed to error messages has been raised in Symfony Validator 7.4 and thus no longer meets the hard-coded structure in the test. The tests are now adjusted to only test for the rendered error message, making it independant from argument order and count. Resolves: #108356 Related: #106945 Releases: main Change-Id: Id4e541715accc8f5571409b4ab6c6825bc26eb89 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/91927 Tested-by: Simon Schaufelberger <[email protected]> Reviewed-by: Markus Klein <[email protected]> Tested-by: Garvin Hicking <[email protected]> Reviewed-by: Garvin Hicking <[email protected]> Reviewed-by: Simon Schaufelberger <[email protected]> Tested-by: Markus Klein <[email protected]> Tested-by: core-ci <[email protected]> Tested-by: Stefan Bürk <[email protected]> Reviewed-by: Stefan Bürk <[email protected]>
1 parent a89df97 commit 848ff37

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

typo3/sysext/extbase/Tests/Functional/Validation/ValidatorResolverTest.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use PHPUnit\Framework\Attributes\DataProvider;
2121
use PHPUnit\Framework\Attributes\Test;
22-
use TYPO3\CMS\Core\Imaging\IconFactory;
2322
use TYPO3\CMS\Extbase\Error\Error;
2423
use TYPO3\CMS\Extbase\Error\Result;
2524
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
@@ -282,23 +281,14 @@ public function SymfonyValidatorsCanBeValidated(): void
282281

283282
$expectation = new Result();
284283
$expectation->addError(new Error('Your foo must be at least %2$s characters long', 286244044, ['""', 1, 0]));
285-
self::assertEquals(
286-
$propertyValidator->validate(''),
287-
$expectation,
288-
);
284+
$this->assertErrorObjectsAreSame([$expectation], [$propertyValidator->validate('')]);
289285

290286
$expectation = new Result();
291-
self::assertEquals(
292-
$propertyValidator->validate('success'),
293-
$expectation,
294-
);
287+
$this->assertErrorObjectsAreSame([$expectation], [$propertyValidator->validate('success')]);
295288

296289
$expectation = new Result();
297290
$expectation->addError(new Error('Your foo cannot be longer than %2$s characters', 1497521431, ['"failure because too long"', 10, 24]));
298-
self::assertEquals(
299-
$propertyValidator->validate('failure because too long'),
300-
$expectation,
301-
);
291+
$this->assertErrorObjectsAreSame([$expectation], [$propertyValidator->validate('failure because too long')]);
302292
}
303293

304294
public static function SymfonyAndExtbaseValidatorsDataProvider(): \Generator
@@ -359,6 +349,27 @@ public function SymfonyValidatorsCanBeMixedWithExtbaseValidators(string $input,
359349
foreach ($fooPropertyValidators as $fooPropertyValidator) {
360350
$results[] = $fooPropertyValidator->validate($input);
361351
}
362-
self::assertEquals($results, $expectedErrorResults);
352+
$this->assertErrorObjectsAreSame($expectedErrorResults, $results);
353+
}
354+
355+
private function assertErrorObjectsAreSame(array $expectedErrorResults, array $results): void
356+
{
357+
self::assertCount(count($expectedErrorResults), $results);
358+
/** @var Result $expectedErrorResult */
359+
foreach ($expectedErrorResults as $resultIndex => $expectedErrorResult) {
360+
self::assertSame($expectedErrorResult->hasErrors(), $results[$resultIndex]->hasErrors());
361+
if (!$expectedErrorResult->hasErrors()) {
362+
continue;
363+
}
364+
365+
$resultErrors = $results[$resultIndex]->getErrors();
366+
$expectedErrors = $expectedErrorResult->getErrors();
367+
self::assertCount(count($expectedErrors), $resultErrors);
368+
foreach ($expectedErrors as $errorIndex => $error) {
369+
$msgExpected = sprintf($error->getMessage(), ...$error->getArguments());
370+
$msgActual = sprintf($resultErrors[$errorIndex]->getMessage(), ...$resultErrors[$errorIndex]->getArguments());
371+
self::assertSame($msgExpected, $msgActual);
372+
}
373+
}
363374
}
364375
}

0 commit comments

Comments
 (0)