diff --git a/src/Symfony/Component/Validator/ConstraintViolation.php b/src/Symfony/Component/Validator/ConstraintViolation.php index 7eec001587..e65cb4906a 100644 --- a/src/Symfony/Component/Validator/ConstraintViolation.php +++ b/src/Symfony/Component/Validator/ConstraintViolation.php @@ -84,7 +84,7 @@ class ConstraintViolation implements ConstraintViolationInterface $class .= '.'; } - if ('' !== $code = $this->code) { + if ('' !== $code = (string) $this->code) { $code = ' (code '.$code.')'; } diff --git a/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php b/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php index d38431b640..3b9690b8d0 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php @@ -109,10 +109,6 @@ EOF; $this->assertSame($expected, (string) $violation); } - /** - * @group legacy - * @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\ConstraintViolation::__construct() is deprecated since Symfony 4.4. A type-hint will be added in 5.0. - */ public function testNonStringCode() { $violation = new ConstraintViolation( @@ -126,6 +122,6 @@ EOF; 42 ); - self::assertSame(42, $violation->getCode()); + self::assertSame('42', $violation->getCode()); } } diff --git a/src/Symfony/Component/Validator/Tests/Violation/ConstraintViolationBuilderTest.php b/src/Symfony/Component/Validator/Tests/Violation/ConstraintViolationBuilderTest.php index 622bcbd8c9..c82f2a1d9f 100644 --- a/src/Symfony/Component/Validator/Tests/Violation/ConstraintViolationBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/Violation/ConstraintViolationBuilderTest.php @@ -19,11 +19,6 @@ use Symfony\Component\Validator\Violation\ConstraintViolationBuilder; class ConstraintViolationBuilderTest extends TestCase { - /** - * @group legacy - * @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\Violation\ConstraintViolationBuilder::setCode() is deprecated since Symfony 4.4. A type-hint will be added in 5.0. - * @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\ConstraintViolation::__construct() is deprecated since Symfony 4.4. A type-hint will be added in 5.0. - */ public function testNonStringCode() { $constraintViolationList = new ConstraintViolationList(); @@ -31,6 +26,6 @@ class ConstraintViolationBuilderTest extends TestCase ->setCode(42) ->addViolation(); - self::assertSame(42, $constraintViolationList->get(0)->getCode()); + self::assertSame('42', $constraintViolationList->get(0)->getCode()); } }