From 6b6dc6293c49407a62e3d4cbb629b3b8105817cf Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 14 Jul 2023 16:12:03 +0200 Subject: [PATCH] [Validator] Deprecate annotations in favor of attributes --- UPGRADE-6.4.md | 8 ++ .../Tests/Validator/DoctrineLoaderTest.php | 6 +- src/Symfony/Bridge/Doctrine/composer.json | 2 - .../FrameworkExtension.php | 3 +- .../CacheWarmer/ValidatorCacheWarmerTest.php | 4 +- .../FrameworkExtensionTestCase.php | 18 ++- .../Tests/Fixtures/Validation/Category.php | 4 +- src/Symfony/Component/Validator/CHANGELOG.md | 4 + .../Validator/Constraints/GroupSequence.php | 5 +- .../Constraints/GroupSequenceProvider.php | 3 +- .../Mapping/Loader/AnnotationLoader.php | 26 +++-- .../Tests/Command/DebugCommandTest.php | 5 +- .../Constraints/ExpressionValidatorTest.php | 2 +- .../Tests/Constraints/ValidValidatorTest.php | 22 +--- .../Validator/Tests/Constraints/WhenTest.php | 19 +++- .../Validator/Tests/Dummy/DummyClassOne.php | 10 +- .../Validator/Tests/Dummy/DummyClassTwo.php | 10 +- .../GroupSequenceProviderChildEntity.php | 2 +- .../Tests/Fixtures/NestedAttribute/Entity.php | 3 +- .../Fixtures/PropertyInfoLoaderEntity.php | 26 ++--- .../PropertyInfoLoaderNoAutoMappingEntity.php | 7 +- .../Tests/Mapping/ClassMetadataTest.php | 9 +- .../LazyLoadingMetadataFactoryTest.php | 4 +- .../Tests/Mapping/GetterMetadataTest.php | 4 +- .../Mapping/Loader/AnnotationLoaderTest.php | 51 ++++----- ...otationLoaderWithHybridAnnotationsTest.php | 82 ++++++++++++++ ...otationLoaderWithLegacyAnnotationsTest.php | 106 ++++++++++++++++++ .../Tests/Mapping/Loader/FilesLoaderTest.php | 2 +- .../Mapping/Loader/PropertyInfoLoaderTest.php | 10 +- .../Mapping/Loader/XmlFileLoaderTest.php | 4 +- .../Mapping/Loader/YamlFileLoaderTest.php | 4 +- .../Tests/Mapping/Loader/bad-format.yml | 2 +- .../Loader/constraint-mapping-non-strings.xml | 2 +- .../Mapping/Loader/constraint-mapping.xml | 4 +- .../Mapping/Loader/constraint-mapping.yml | 4 +- .../Mapping/Loader/mapping-with-constants.yml | 2 +- .../Tests/Mapping/Loader/withdoctype.xml | 2 +- .../Tests/Mapping/MemberMetadataTest.php | 2 +- .../Tests/Mapping/PropertyMetadataTest.php | 4 +- .../Validator/RecursiveValidatorTest.php | 6 +- .../Validator/Tests/ValidatorBuilderTest.php | 20 +++- .../Component/Validator/ValidatorBuilder.php | 8 ++ 42 files changed, 357 insertions(+), 164 deletions(-) create mode 100644 src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithLegacyAnnotationsTest.php diff --git a/UPGRADE-6.4.md b/UPGRADE-6.4.md index 2881c357eadee..7936d9122a472 100644 --- a/UPGRADE-6.4.md +++ b/UPGRADE-6.4.md @@ -77,3 +77,11 @@ Serializer * Deprecate Doctrine annotations support in favor of native attributes * Deprecate passing an annotation reader to the constructor of `AnnotationLoader` + +Validator +--------- + + * Deprecate Doctrine annotations support in favor of native attributes + * Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader` + * Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()` + * Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php index 94f4b0527f0dc..70a30f3173920 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php @@ -28,7 +28,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Mapping\TraversalStrategy; -use Symfony\Component\Validator\Tests\Fixtures\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; use Symfony\Component\Validator\Validation; /** @@ -40,7 +40,6 @@ public function testLoadClassMetadata() { $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}')) ->getValidator() ; @@ -144,7 +143,6 @@ public function testExtractEnum() $validator = Validation::createValidatorBuilder() ->addMethodMapping('loadValidatorMetadata') ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}')) ->getValidator() ; @@ -162,7 +160,6 @@ public function testFieldMappingsConfiguration() { $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() ->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml']) ->addLoader( new DoctrineLoader( @@ -204,7 +201,6 @@ public function testClassNoAutoMapping() { $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}')) ->getValidator(); diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 062528317223a..e12b86af4a75d 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -43,7 +43,6 @@ "symfony/uid": "^5.4|^6.0|^7.0", "symfony/validator": "^5.4.25|~6.2.12|^6.3.1|^7.0", "symfony/var-dumper": "^5.4|^6.0|^7.0", - "doctrine/annotations": "^1.13.1|^2", "doctrine/collections": "^1.0|^2.0", "doctrine/data-fixtures": "^1.1", "doctrine/dbal": "^2.13.1|^3.0", @@ -51,7 +50,6 @@ "psr/log": "^1|^2|^3" }, "conflict": { - "doctrine/annotations": "<1.13.1", "doctrine/dbal": "<2.13.1", "doctrine/lexer": "<1.1", "doctrine/orm": "<2.15", diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 846639ebda2ac..134aa209c4964 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -181,6 +181,7 @@ use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader; use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Validation; +use Symfony\Component\Validator\ValidatorBuilder; use Symfony\Component\Webhook\Controller\WebhookController; use Symfony\Component\WebLink\HttpHeaderSerializer; use Symfony\Component\Workflow; @@ -1609,7 +1610,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) { $validatorBuilder->addMethodCall('enableAnnotationMapping', [true]); - if ($this->isInitializedConfigEnabled('annotations')) { + if ($this->isInitializedConfigEnabled('annotations') && method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) { $validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php index 8a54680c0f557..92ef379b1b819 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php @@ -26,7 +26,7 @@ public function testWarmUp() $validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml'); $validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml'); $validatorBuilder->addMethodMapping('loadValidatorMetadata'); - $validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader(); + $validatorBuilder->enableAnnotationMapping(); $file = sys_get_temp_dir().'/cache-validator.php'; @unlink($file); @@ -46,7 +46,7 @@ public function testWarmUpWithAnnotations() { $validatorBuilder = new ValidatorBuilder(); $validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml'); - $validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader(); + $validatorBuilder->enableAnnotationMapping(); $file = sys_get_temp_dir().'/cache-validator-with-annotations.php'; @unlink($file); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 877d502cdb5ec..dbad832eadb93 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -81,6 +81,7 @@ use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass; use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Symfony\Component\Validator\ValidatorBuilder; use Symfony\Component\Webhook\Client\RequestParser; use Symfony\Component\Webhook\Controller\WebhookController; use Symfony\Component\Workflow; @@ -1308,12 +1309,17 @@ public function testValidationLegacyAnnotations() $this->assertCount(8, $calls); $this->assertSame('enableAnnotationMapping', $calls[4][0]); - $this->assertSame('setDoctrineAnnotationReader', $calls[5][0]); - $this->assertEquals([new Reference('annotation_reader')], $calls[5][1]); - $this->assertSame('addMethodMapping', $calls[6][0]); - $this->assertSame(['loadValidatorMetadata'], $calls[6][1]); - $this->assertSame('setMappingCache', $calls[7][0]); - $this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[7][1]); + if (method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) { + $this->assertSame('setDoctrineAnnotationReader', $calls[5][0]); + $this->assertEquals([new Reference('annotation_reader')], $calls[5][1]); + $i = 6; + } else { + $i = 5; + } + $this->assertSame('addMethodMapping', $calls[$i][0]); + $this->assertSame(['loadValidatorMetadata'], $calls[$i][1]); + $this->assertSame('setMappingCache', $calls[++$i][0]); + $this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[$i][1]); // no cache this time } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php index 6d9539cc58c48..ce1aa8018f3ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php @@ -10,8 +10,6 @@ class Category public $id; - /** - * @Assert\Type("string") - */ + #[Assert\Type('string')] public $name; } diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index b971464397dc6..6d8b2a6c5a998 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -6,6 +6,10 @@ CHANGELOG * Allow single integer for the `versions` option of the `Uuid` constraint * Allow single constraint to be passed to the `constraints` option of the `When` constraint + * Deprecate Doctrine annotations support in favor of native attributes + * Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader` + * Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()` + * Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` 6.3 --- diff --git a/src/Symfony/Component/Validator/Constraints/GroupSequence.php b/src/Symfony/Component/Validator/Constraints/GroupSequence.php index 522c5fdf59d11..57122b02edcb5 100644 --- a/src/Symfony/Component/Validator/Constraints/GroupSequence.php +++ b/src/Symfony/Component/Validator/Constraints/GroupSequence.php @@ -28,9 +28,7 @@ * * When adding metadata to a class, you can override the "Default" group of * that class with a group sequence: - * /** - * * @GroupSequence({"Address", "Strict"}) - * *\/ + * #[GroupSequence(['Address', 'Strict'])] * class Address * { * // ... @@ -47,6 +45,7 @@ * $validator->validate($address, null, "Address") * * @Annotation + * * @Target({"CLASS", "ANNOTATION"}) * * @author Bernhard Schussek diff --git a/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php b/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php index 489a449e83830..9b125470fa47a 100644 --- a/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php +++ b/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php @@ -12,9 +12,10 @@ namespace Symfony\Component\Validator\Constraints; /** - * Annotation to define a group sequence provider. + * Attribute to define a group sequence provider. * * @Annotation + * * @Target({"CLASS", "ANNOTATION"}) * * @author Bernhard Schussek diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php index b0252afc3d208..a3cdfb12047ea 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php @@ -27,10 +27,19 @@ */ class AnnotationLoader implements LoaderInterface { + /** + * @deprecated since Symfony 6.4, this property will be removed in 7.0 + * + * @var Reader|null + */ protected $reader; public function __construct(Reader $reader = null) { + if ($reader) { + trigger_deprecation('symfony/validator', '6.4', 'Passing a "%s" instance as argument 1 to "%s()" is deprecated, pass null or omit the parameter instead.', get_debug_type($reader), __METHOD__); + } + $this->reader = $reader; } @@ -87,10 +96,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool return $success; } - /** - * @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection - */ - private function getAnnotations(object $reflection): iterable + private function getAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflection): iterable { $dedup = []; @@ -112,14 +118,14 @@ private function getAnnotations(object $reflection): iterable $annotations = []; - if ($reflection instanceof \ReflectionClass) { - $annotations = $this->reader->getClassAnnotations($reflection); + if ($reflection instanceof \ReflectionClass && $annotations = $this->reader->getClassAnnotations($reflection)) { + trigger_deprecation('symfony/validator', '6.4', 'Class "%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getName()); } - if ($reflection instanceof \ReflectionMethod) { - $annotations = $this->reader->getMethodAnnotations($reflection); + if ($reflection instanceof \ReflectionMethod && $annotations = $this->reader->getMethodAnnotations($reflection)) { + trigger_deprecation('symfony/validator', '6.4', 'Method "%s::%s()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName(), $reflection->getName()); } - if ($reflection instanceof \ReflectionProperty) { - $annotations = $this->reader->getPropertyAnnotations($reflection); + if ($reflection instanceof \ReflectionProperty && $annotations = $this->reader->getPropertyAnnotations($reflection)) { + trigger_deprecation('symfony/validator', '6.4', 'Property "%s::$%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName(), $reflection->getName()); } foreach ($dedup as $annotation) { diff --git a/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php b/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php index 81dfa30794c63..c245cc80972b7 100644 --- a/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Validator\Tests\Command; -use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Validator\Command\DebugCommand; @@ -27,7 +26,7 @@ class DebugCommandTest extends TestCase { public function testOutputWithClassArgument() { - $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()))); + $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader())); $tester = new CommandTester($command); $tester->execute(['class' => DummyClassOne::class], ['decorated' => false]); @@ -68,7 +67,7 @@ public function testOutputWithClassArgument() public function testOutputWithPathArgument() { - $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()))); + $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader())); $tester = new CommandTester($command); $tester->execute(['class' => __DIR__.'/../Dummy'], ['decorated' => false]); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index b313040e959ab..f427604725a2f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Constraints\ExpressionValidator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; use Symfony\Component\Validator\Tests\Fixtures\ToString; class ExpressionValidatorTest extends ConstraintValidatorTestCase diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php index 2b4dd8d215bee..8c625949feb13 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Component\Validator\Constraints\ValidValidator; use Symfony\Component\Validator\ValidatorBuilder; class ValidValidatorTest extends TestCase @@ -21,7 +20,7 @@ class ValidValidatorTest extends TestCase public function testPropertyPathsArePassedToNestedContexts() { $validatorBuilder = new ValidatorBuilder(); - $validator = $validatorBuilder->enableAnnotationMapping()->addDefaultDoctrineAnnotationReader()->getValidator(); + $validator = $validatorBuilder->enableAnnotationMapping()->getValidator(); $violations = $validator->validate(new Foo(), null, ['nested']); @@ -32,7 +31,7 @@ public function testPropertyPathsArePassedToNestedContexts() public function testNullValues() { $validatorBuilder = new ValidatorBuilder(); - $validator = $validatorBuilder->enableAnnotationMapping()->addDefaultDoctrineAnnotationReader()->getValidator(); + $validator = $validatorBuilder->enableAnnotationMapping()->getValidator(); $foo = new Foo(); $foo->fooBar = null; @@ -40,18 +39,11 @@ public function testNullValues() $this->assertCount(0, $violations); } - - protected function createValidator() - { - return new ValidValidator(); - } } class Foo { - /** - * @Assert\Valid(groups={"nested"}) - */ + #[Assert\Valid(groups: ['nested'])] public $fooBar; public function __construct() @@ -62,9 +54,7 @@ public function __construct() class FooBar { - /** - * @Assert\Valid(groups={"nested"}) - */ + #[Assert\Valid(groups: ['nested'])] public $fooBarBaz; public function __construct() @@ -75,8 +65,6 @@ public function __construct() class FooBarBaz { - /** - * @Assert\NotBlank(groups={"nested"}) - */ + #[Assert\NotBlank(groups: ['nested'])] public $foo; } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php index e057d6b0c43bc..b3305b3c4fe86 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; @@ -25,6 +26,8 @@ final class WhenTest extends TestCase { + use ExpectDeprecationTrait; + public function testMissingOptionsExceptionIsThrown() { $this->expectException(MissingOptionsException::class); @@ -42,11 +45,22 @@ public function testNonConstraintsAreRejected() ]); } + /** + * @group legacy + */ public function testAnnotations() { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $loader = new AnnotationLoader(new AnnotationReader()); $metadata = new ClassMetadata(WhenTestWithAnnotations::class); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Constraints\WhenTestWithAnnotations" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Constraints\WhenTestWithAnnotations::$foo" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Constraints\WhenTestWithAnnotations::$bar" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Constraints\WhenTestWithAnnotations::$qux" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Constraints\WhenTestWithAnnotations::getBaz()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + self::assertTrue($loader->loadClassMetadata($metadata)); [$classConstraint] = $metadata->getConstraints(); @@ -114,12 +128,9 @@ public function testAnnotations() self::assertSame(['Default', 'WhenTestWithAnnotations'], $bazConstraint->groups); } - /** - * @requires PHP 8.1 - */ public function testAttributes() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = new AnnotationLoader(); $metadata = new ClassMetadata(WhenTestWithAttributes::class); self::assertTrue($loader->loadClassMetadata($metadata)); diff --git a/src/Symfony/Component/Validator/Tests/Dummy/DummyClassOne.php b/src/Symfony/Component/Validator/Tests/Dummy/DummyClassOne.php index 92def37e0e9fe..969f5244de21e 100644 --- a/src/Symfony/Component/Validator/Tests/Dummy/DummyClassOne.php +++ b/src/Symfony/Component/Validator/Tests/Dummy/DummyClassOne.php @@ -13,22 +13,18 @@ use Symfony\Component\Validator\Constraints as Assert; -/** - * @Assert\Expression(expression="1 + 1 = 2") - */ +#[Assert\Expression(expression: '1 + 1 = 2')] class DummyClassOne { /** * @var string|null - * - * @Assert\NotBlank */ + #[Assert\NotBlank] public $code; /** * @var string|null - * - * @Assert\Email */ + #[Assert\Email] public $email; } diff --git a/src/Symfony/Component/Validator/Tests/Dummy/DummyClassTwo.php b/src/Symfony/Component/Validator/Tests/Dummy/DummyClassTwo.php index cd136a9dd301e..8c35555da7776 100644 --- a/src/Symfony/Component/Validator/Tests/Dummy/DummyClassTwo.php +++ b/src/Symfony/Component/Validator/Tests/Dummy/DummyClassTwo.php @@ -13,22 +13,18 @@ use Symfony\Component\Validator\Constraints as Assert; -/** - * @Assert\Expression(expression="1 + 1 = 2") - */ +#[Assert\Expression(expression: '1 + 1 = 2')] class DummyClassTwo { /** * @var string|null - * - * @Assert\NotBlank */ + #[Assert\NotBlank] public $code; /** * @var string|null - * - * @Assert\Email */ + #[Assert\Email] public $email; } diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/GroupSequenceProviderChildEntity.php b/src/Symfony/Component/Validator/Tests/Fixtures/GroupSequenceProviderChildEntity.php index ee8f718748d95..cd6ca1ea55f75 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/GroupSequenceProviderChildEntity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/GroupSequenceProviderChildEntity.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Validator\Tests\Fixtures; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity; class GroupSequenceProviderChildEntity extends GroupSequenceProviderEntity { diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php b/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php index 3ab5e012c6841..2384e87344328 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php @@ -13,7 +13,6 @@ use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; -use Symfony\Component\Validator\Tests\Fixtures\Attribute\EntityParent; use Symfony\Component\Validator\Tests\Fixtures\EntityInterfaceB; use Symfony\Component\Validator\Tests\Fixtures\CallbackClass; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; @@ -67,7 +66,7 @@ class Entity extends EntityParent implements EntityInterfaceB new Assert\Range(min: 5), ]), ] - public string $firstName; + public $firstName; #[Assert\Valid] public $childA; #[Assert\Valid] diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php index 2cc46e77de295..174f8ee988431 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php @@ -25,34 +25,24 @@ class PropertyInfoLoaderEntity public $collection; public $collectionOfUnknown; - /** - * @Assert\Type(type="int") - */ + #[Assert\Type(type: 'int')] public $alreadyMappedType; - /** - * @Assert\NotNull - */ + #[Assert\NotNull] public $alreadyMappedNotNull; - /** - * @Assert\NotBlank - */ + #[Assert\NotBlank] public $alreadyMappedNotBlank; - /** - * @Assert\All({ - * @Assert\Type(type="string"), - * @Assert\Iban - * }) - */ + #[Assert\All([ + new Assert\Type(type: 'string'), + new Assert\Iban(), + ])] public $alreadyPartiallyMappedCollection; public $readOnly; - /** - * @Assert\DisableAutoMapping - */ + #[Assert\DisableAutoMapping] public $noAutoMapping; public function setNonExistentField() diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderNoAutoMappingEntity.php b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderNoAutoMappingEntity.php index d14cb7c7c7ca0..3271cf0c84caa 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderNoAutoMappingEntity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderNoAutoMappingEntity.php @@ -14,16 +14,13 @@ use Symfony\Component\Validator\Constraints as Assert; /** - * @Assert\DisableAutoMapping - * * @author Kévin Dunglas */ +#[Assert\DisableAutoMapping] class PropertyInfoLoaderNoAutoMappingEntity { public $string; - /** - * @Assert\EnableAutoMapping - */ + #[Assert\EnableAutoMapping] public $autoMappingExplicitlyEnabled; } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php index 13636dc7b8f40..6e1c95d54bea0 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -21,13 +21,14 @@ use Symfony\Component\Validator\Exception\GroupDefinitionException; use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity; use Symfony\Component\Validator\Tests\Fixtures\CascadingEntity; use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintB; +use Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderChildEntity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity; use Symfony\Component\Validator\Tests\Fixtures\PropertyConstraint; class ClassMetadataTest extends TestCase @@ -35,7 +36,7 @@ class ClassMetadataTest extends TestCase private const CLASSNAME = Entity::class; private const PARENTCLASS = EntityParent::class; private const PROVIDERCLASS = GroupSequenceProviderEntity::class; - private const PROVIDERCHILDCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderChildEntity'; + private const PROVIDERCHILDCLASS = GroupSequenceProviderChildEntity::class; protected $metadata; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php index f9b4381c65fbf..3d10506aea337 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php @@ -20,9 +20,9 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent; use Symfony\Component\Validator\Tests\Fixtures\PropertyGetter; use Symfony\Component\Validator\Tests\Fixtures\PropertyGetterInterface; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php index 3128fbb6b1ab1..2a36605729b90 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/GetterMetadataTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\GetterMetadata; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; class GetterMetadataTest extends TestCase { @@ -62,7 +62,7 @@ public function testGetPropertyValueFromHasser() public function testUndefinedMethodNameThrowsException() { $this->expectException(ValidatorException::class); - $this->expectExceptionMessage('The "hasLastName()" method does not exist in class "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity".'); + $this->expectExceptionMessage('The "hasLastName()" method does not exist in class "Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity".'); new GetterMetadata(self::CLASSNAME, 'lastName', 'hasLastName'); } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php index 7f09a5267947c..474064274bb37 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Validator\Tests\Mapping\Loader; -use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\AtLeastOneOf; @@ -31,34 +30,31 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; class AnnotationLoaderTest extends TestCase { public function testLoadClassMetadataReturnsTrueIfSuccessful() { - $reader = new AnnotationReader(); - $loader = new AnnotationLoader($reader); - $metadata = new ClassMetadata(Entity::class); + $loader = $this->createAnnotationLoader(); + $metadata = new ClassMetadata($this->getFixtureNamespace().'\Entity'); $this->assertTrue($loader->loadClassMetadata($metadata)); } public function testLoadClassMetadataReturnsFalseIfNotSuccessful() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = $this->createAnnotationLoader(); $metadata = new ClassMetadata('\stdClass'); $this->assertFalse($loader->loadClassMetadata($metadata)); } - /** - * @dataProvider provideNamespaces - */ - public function testLoadClassMetadata(string $namespace) + public function testLoadClassMetadata() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = $this->createAnnotationLoader(); + $namespace = $this->getFixtureNamespace(); + $metadata = new ClassMetadata($namespace.'\Entity'); $loader->loadClassMetadata($metadata); @@ -109,12 +105,11 @@ public function testLoadClassMetadata(string $namespace) /** * Test MetaData merge with parent annotation. - * - * @dataProvider provideNamespaces */ - public function testLoadParentClassMetadata(string $namespace) + public function testLoadParentClassMetadata() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = $this->createAnnotationLoader(); + $namespace = $this->getFixtureNamespace(); // Load Parent MetaData $parent_metadata = new ClassMetadata($namespace.'\EntityParent'); @@ -129,12 +124,11 @@ public function testLoadParentClassMetadata(string $namespace) /** * Test MetaData merge with parent annotation. - * - * @dataProvider provideNamespaces */ - public function testLoadClassMetadataAndMerge(string $namespace) + public function testLoadClassMetadataAndMerge() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = $this->createAnnotationLoader(); + $namespace = $this->getFixtureNamespace(); // Load Parent MetaData $parent_metadata = new ClassMetadata($namespace.'\EntityParent'); @@ -201,12 +195,10 @@ public function testLoadClassMetadataAndMerge(string $namespace) $this->assertInstanceOf(NotNull::class, $otherMetadata[1]->getConstraints()[0]); } - /** - * @dataProvider provideNamespaces - */ - public function testLoadGroupSequenceProviderAnnotation(string $namespace) + public function testLoadGroupSequenceProviderAnnotation() { - $loader = new AnnotationLoader(new AnnotationReader()); + $loader = $this->createAnnotationLoader(); + $namespace = $this->getFixtureNamespace(); $metadata = new ClassMetadata($namespace.'\GroupSequenceProviderEntity'); $loader->loadClassMetadata($metadata); @@ -218,10 +210,13 @@ public function testLoadGroupSequenceProviderAnnotation(string $namespace) $this->assertEquals($expected, $metadata); } - public static function provideNamespaces(): iterable + protected function createAnnotationLoader(): AnnotationLoader + { + return new AnnotationLoader(); + } + + protected function getFixtureNamespace(): string { - yield 'annotations' => ['Symfony\Component\Validator\Tests\Fixtures\Annotation']; - yield 'attributes' => ['Symfony\Component\Validator\Tests\Fixtures\Attribute']; - yield 'nested_attributes' => ['Symfony\Component\Validator\Tests\Fixtures\NestedAttribute']; + return 'Symfony\Component\Validator\Tests\Fixtures\NestedAttribute'; } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php new file mode 100644 index 0000000000000..2e34d7d6ea6de --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Mapping\Loader; + +use Doctrine\Common\Annotations\AnnotationReader; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; + +/** + * @group legacy + */ +class AnnotationLoaderWithHybridAnnotationsTest extends AnnotationLoaderTest +{ + use ExpectDeprecationTrait; + + public function testLoadClassMetadataReturnsTrueIfSuccessful() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadataReturnsTrueIfSuccessful(); + } + + public function testLoadClassMetadataReturnsFalseIfNotSuccessful() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + + parent::testLoadClassMetadataReturnsFalseIfNotSuccessful(); + } + + public function testLoadClassMetadata() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadata(); + } + + public function testLoadParentClassMetadata() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + + parent::testLoadParentClassMetadata(); + } + + public function testLoadClassMetadataAndMerge() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Attribute\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadataAndMerge(); + } + + public function testLoadGroupSequenceProviderAnnotation() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + + parent::testLoadGroupSequenceProviderAnnotation(); + } + + protected function createAnnotationLoader(): AnnotationLoader + { + return new AnnotationLoader(new AnnotationReader()); + } + + protected function getFixtureNamespace(): string + { + return 'Symfony\Component\Validator\Tests\Fixtures\Attribute'; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithLegacyAnnotationsTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithLegacyAnnotationsTest.php new file mode 100644 index 0000000000000..821fce12b414c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithLegacyAnnotationsTest.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Mapping\Loader; + +use Doctrine\Common\Annotations\AnnotationReader; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; + +/** + * @group legacy + */ +class AnnotationLoaderWithLegacyAnnotationsTest extends AnnotationLoaderTest +{ + use ExpectDeprecationTrait; + + public function testLoadClassMetadataReturnsTrueIfSuccessful() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childA" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childB" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::getLastName()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::isValid()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::hasPermissions()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMe()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMeStatic()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadataReturnsTrueIfSuccessful(); + } + + public function testLoadClassMetadataReturnsFalseIfNotSuccessful() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + + parent::testLoadClassMetadataReturnsFalseIfNotSuccessful(); + } + + public function testLoadClassMetadata() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childA" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childB" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::getLastName()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::isValid()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::hasPermissions()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMe()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMeStatic()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadata(); + } + + public function testLoadParentClassMetadata() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent::$other" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadParentClassMetadata(); + } + + public function testLoadClassMetadataAndMerge() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent::$other" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$firstName" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childA" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Property "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::$childB" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::getLastName()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::isValid()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::hasPermissions()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMe()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity::validateMeStatic()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadClassMetadataAndMerge(); + } + + public function testLoadGroupSequenceProviderAnnotation() + { + $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.'); + $this->expectDeprecation('Since symfony/validator 6.4: Class "Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.'); + + parent::testLoadGroupSequenceProviderAnnotation(); + } + + protected function createAnnotationLoader(): AnnotationLoader + { + return new AnnotationLoader(new AnnotationReader()); + } + + protected function getFixtureNamespace(): string + { + return 'Symfony\Component\Validator\Tests\Fixtures\Annotation'; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php index ea5e947be880b..43863edcbccc7 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php @@ -14,8 +14,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; use Symfony\Component\Validator\Tests\Fixtures\FilesLoader; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; class FilesLoaderTest extends TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index f41d4c55443a9..95cdee8c7dde0 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -23,7 +23,7 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader; use Symfony\Component\Validator\Mapping\PropertyMetadata; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; use Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderEntity; use Symfony\Component\Validator\Tests\Fixtures\PropertyInfoLoaderNoAutoMappingEntity; use Symfony\Component\Validator\Validation; @@ -92,8 +92,7 @@ public function testLoadClassMetadata() $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() + ->enableAnnotationMapping() ->addLoader($propertyInfoLoader) ->getValidator() ; @@ -205,7 +204,7 @@ public function testClassValidator(bool $expected, string $classValidatorRegexp $this->assertSame($expected, $propertyInfoLoader->loadClassMetadata($classMetadata)); } - public static function regexpProvider() + public static function regexpProvider(): array { return [ [false, null], @@ -231,8 +230,7 @@ public function testClassNoAutoMapping() $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() + ->enableAnnotationMapping() ->addLoader($propertyInfoLoader) ->getValidator() ; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php index 792b775fd32a0..48533e6e4311d 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php @@ -24,12 +24,12 @@ use Symfony\Component\Validator\Exception\MappingException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintB; use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithRequiredArgument; use Symfony\Component\Validator\Tests\Fixtures\Entity_81; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity; class XmlFileLoaderTest extends TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php index cf3dd46d8634d..faaf64dbc8ce0 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php @@ -21,8 +21,8 @@ use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintB; use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithRequiredArgument; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml index 8709d232715c8..46d09d746d4d4 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/bad-format.yml @@ -1,7 +1,7 @@ namespaces: custom: Symfony\Component\Validator\Tests\Fixtures\ -Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity: +Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity: constraints: # Custom constraint - Symfony\Component\Validator\Tests\Fixtures\ConstraintA: ~ diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping-non-strings.xml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping-non-strings.xml index 02fbeb431151e..406aaad7644be 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping-non-strings.xml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping-non-strings.xml @@ -6,7 +6,7 @@ Symfony\Component\Validator\Tests\Fixtures\ - + diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.xml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.xml index 114d7fc34e453..0b949554025df 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.xml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.xml @@ -6,7 +6,7 @@ Symfony\Component\Validator\Tests\Fixtures\ - + Foo @@ -115,7 +115,7 @@ - + diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.yml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.yml index 5a62b38334d35..4d2a694c3de86 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.yml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/constraint-mapping.yml @@ -1,7 +1,7 @@ namespaces: custom: Symfony\Component\Validator\Tests\Fixtures\ -Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity: +Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity: group_sequence: - Foo - Entity @@ -58,5 +58,5 @@ Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity: permissions: - "IsTrue": ~ -Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity: +Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity: group_sequence_provider: true diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/mapping-with-constants.yml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/mapping-with-constants.yml index afdda0478554a..97f8805989080 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/mapping-with-constants.yml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/mapping-with-constants.yml @@ -1,7 +1,7 @@ namespaces: custom: Symfony\Component\Validator\Tests\Fixtures\ -Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity: +Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity: properties: firstName: - Range: diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/withdoctype.xml b/src/Symfony/Component/Validator/Tests/Mapping/Loader/withdoctype.xml index ae7037c562e9a..db4529482e038 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/withdoctype.xml +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/withdoctype.xml @@ -3,5 +3,5 @@ - + diff --git a/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php index 701741e011d34..f115251690d85 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/MemberMetadataTest.php @@ -18,7 +18,7 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Mapping\MemberMetadata; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintB; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php index 85f580cff533f..883ef41eed46b 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php @@ -14,8 +14,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\PropertyMetadata; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent; use Symfony\Component\Validator\Tests\Fixtures\Entity_74; use Symfony\Component\Validator\Tests\Fixtures\Entity_74_Proxy; diff --git a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php index 010536e661f19..469d73bfb08f8 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php @@ -44,9 +44,9 @@ use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA; use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\EntityParent; -use Symfony\Component\Validator\Tests\Fixtures\Annotation\GroupSequenceProviderEntity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent; +use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity; use Symfony\Component\Validator\Tests\Fixtures\CascadedChild; use Symfony\Component\Validator\Tests\Fixtures\CascadingEntity; use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods; diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php index 5ac368119a7fd..9d0b1b5140bda 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\Annotations\Reader; use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\ObjectInitializerInterface; @@ -24,10 +25,9 @@ class ValidatorBuilderTest extends TestCase { - /** - * @var ValidatorBuilder - */ - protected $builder; + use ExpectDeprecationTrait; + + private ValidatorBuilder $builder; protected function setUp(): void { @@ -36,7 +36,7 @@ protected function setUp(): void protected function tearDown(): void { - $this->builder = null; + unset($this->builder); } public function testAddObjectInitializer() @@ -81,9 +81,14 @@ public function testAddMethodMappings() $this->assertSame($this->builder, $this->builder->addMethodMappings([])); } + /** + * @group legacy + */ public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() { $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); + + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.'); $this->assertSame($this->builder, $this->builder->addDefaultDoctrineAnnotationReader()); $loaders = $this->builder->getLoaders(); @@ -95,11 +100,16 @@ public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() $this->assertInstanceOf(PsrCachedReader::class, $r->getValue($loaders[0])); } + /** + * @group legacy + */ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader() { $reader = $this->createMock(Reader::class); $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); + + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::setDoctrineAnnotationReader()" is deprecated without replacement.'); $this->assertSame($this->builder, $this->builder->setDoctrineAnnotationReader($reader)); $loaders = $this->builder->getLoaders(); diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index fc2a5e30cebbb..88fd21645c180 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -216,20 +216,28 @@ public function disableAnnotationMapping(): static } /** + * @deprecated since Symfony 6.4 without replacement + * * @return $this */ public function setDoctrineAnnotationReader(?Reader $reader): static { + trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated without replacement.', __METHOD__); + $this->annotationReader = $reader; return $this; } /** + * @deprecated since Symfony 6.4 without replacement + * * @return $this */ public function addDefaultDoctrineAnnotationReader(): static { + trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated without replacement.', __METHOD__); + $this->annotationReader = $this->createAnnotationReader(); return $this;