From 5b764c2ebd8baab43faf14feb7e9a1942af63f10 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 18:29:25 +0200 Subject: [PATCH] work around ConstraintValidatorTestCase --- src/Model/Route.php | 2 +- .../Constraints/RouteDefaultsTwigValidatorTest.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Model/Route.php b/src/Model/Route.php index 01bbffbe..941b415e 100644 --- a/src/Model/Route.php +++ b/src/Model/Route.php @@ -26,7 +26,7 @@ class Route extends SymfonyRoute implements RouteObjectInterface /** * Unique id of this route. */ - protected string|int|null $id; + protected string|int|null $id = null; /** * The referenced content object. diff --git a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php index 3d0c8941..9182ef13 100644 --- a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php +++ b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php @@ -15,8 +15,10 @@ use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaults; use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaultsTwigValidator; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; +use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; +use Symfony\Component\Validator\Test\ConstraintViolationAssertion; use Twig\Loader\LoaderInterface; class RouteDefaultsTwigValidatorTest extends ConstraintValidatorTestCase @@ -66,7 +68,7 @@ public function testControllerPathViolation(): void $this->validator->validate(['_controller' => 'NotExistingBundle:Foo:bar'], new RouteDefaults()); - $this->buildViolation('Invalid controller')->assertRaised(); + (new ConstraintViolationAssertion($this->context, 'Invalid controller', new NotNull()))->assertRaised(); } public function testCorrectTemplate(): void @@ -94,8 +96,9 @@ public function testTemplateViolation(): void new RouteDefaults(['message' => 'my message']) ); - $this->buildViolation('my message') + (new ConstraintViolationAssertion($this->context, 'my message', new NotNull())) ->setParameter('%name%', 'NotExistingBundle:Foo:bar.html.twig') - ->assertRaised(); + ->assertRaised() + ; } }