diff --git a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php index 311bebe..a6d3daa 100644 --- a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php +++ b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php @@ -48,7 +48,8 @@ class SymfonyConstraintAnnotationReader foreach ($annotations as $annotation) { if ($annotation instanceof Assert\NotBlank || $annotation instanceof Assert\NotNull) { - if ($annotation instanceof Assert\NotBlank && $annotation->allowNull) { + // To support symfony/validator < 4.3 + if ($annotation instanceof Assert\NotBlank && \method_exists($annotation, 'allowNull') && $annotation->allowNull) { // The field is optional continue; } diff --git a/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index c781db1..36c5b78 100644 --- a/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -49,6 +49,10 @@ class SymfonyConstraintAnnotationReaderTest extends TestCase public function testOptionalProperty() { + if (!\method_exists(Assert\NotBlank::class, 'allowNull')) { + $this->markTestSkipped('NotBlank::allowNull was added in symfony/validator 4.3.'); + } + $entity = new class() { /** * @Assert\NotBlank(allowNull = true)