diff --git a/UPGRADE-6.4.md b/UPGRADE-6.4.md index 43a7fe911713c..f4124a85799e7 100644 --- a/UPGRADE-6.4.md +++ b/UPGRADE-6.4.md @@ -93,6 +93,8 @@ FrameworkBundle * Deprecate not setting the `framework.uid.default_uuid_version` config option; it will default to `7` in 7.0 * Deprecate not setting the `framework.uid.time_based_uuid_version` config option; it will default to `7` in 7.0 * Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0 + * Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead + * Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead HttpFoundation -------------- @@ -157,3 +159,6 @@ Validator * Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader` * Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()` * Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` + * Deprecate `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead + * Deprecate `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead + * Deprecate `AnnotationLoader`, use `AttributeLoader` instead diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php index 9e334e8ff1dbb..4380bba494bba 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php @@ -14,14 +14,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class UniqueEntityTest extends TestCase { public function testAttributeWithDefaultProperty() { $metadata = new ClassMetadata(UniqueEntityDummyOne::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); /** @var UniqueEntity $constraint */ @@ -35,7 +35,7 @@ public function testAttributeWithDefaultProperty() public function testAttributeWithCustomizedService() { $metadata = new ClassMetadata(UniqueEntityDummyTwo::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); /** @var UniqueEntity $constraint */ @@ -50,7 +50,7 @@ public function testAttributeWithCustomizedService() public function testAttributeWithGroupsAndPaylod() { $metadata = new ClassMetadata(UniqueEntityDummyThree::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); /** @var UniqueEntity $constraint */ diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php index 70a30f3173920..383f11c26f9a9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php @@ -39,7 +39,7 @@ class DoctrineLoaderTest extends TestCase public function testLoadClassMetadata() { $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) + ->enableAttributeMapping() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}')) ->getValidator() ; @@ -142,7 +142,7 @@ public function testExtractEnum() { $validator = Validation::createValidatorBuilder() ->addMethodMapping('loadValidatorMetadata') - ->enableAnnotationMapping(true) + ->enableAttributeMapping() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}')) ->getValidator() ; @@ -159,7 +159,7 @@ public function testExtractEnum() public function testFieldMappingsConfiguration() { $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) + ->enableAttributeMapping() ->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml']) ->addLoader( new DoctrineLoader( @@ -200,7 +200,7 @@ public static function regexpProvider(): array public function testClassNoAutoMapping() { $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) + ->enableAttributeMapping() ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}')) ->getValidator(); diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 491ec1d1822d7..ada1e1ef14145 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -41,7 +41,7 @@ "symfony/stopwatch": "^5.4|^6.0|^7.0", "symfony/translation": "^5.4|^6.0|^7.0", "symfony/uid": "^5.4|^6.0|^7.0", - "symfony/validator": "^5.4.25|~6.2.12|^6.3.1|^7.0", + "symfony/validator": "^6.4|^7.0", "symfony/var-dumper": "^5.4|^6.0|^7.0", "doctrine/collections": "^1.0|^2.0", "doctrine/data-fixtures": "^1.1", @@ -63,7 +63,7 @@ "symfony/property-info": "<5.4", "symfony/security-bundle": "<5.4", "symfony/security-core": "<6.4", - "symfony/validator": "<5.4.25|>=6,<6.2.12|>=6.3,<6.3.1" + "symfony/validator": "<6.4" }, "autoload": { "psr-4": { "Symfony\\Bridge\\Doctrine\\": "" }, diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index b4cc211287bcf..ffc92d16f7b70 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -21,6 +21,8 @@ CHANGELOG * Deprecate not setting the `framework.uid.default_uuid_version` config option; it will default to `7` in 7.0 * Deprecate not setting the `framework.uid.time_based_uuid_version` config option; it will default to `7` in 7.0 * Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0 + * Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead + * Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead 6.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index b5756e7fe7ab6..a9c4e90882a0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1024,6 +1024,14 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e trigger_deprecation('symfony/framework-bundle', '6.4', 'Not setting the "framework.validation.email_validation_mode" config option is deprecated. It will default to "html5" in 7.0.'); } + if (isset($v['enable_annotations'])) { + trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.validation" is deprecated. Use the "enable_attributes" option instead.'); + + if (!isset($v['enable_attributes'])) { + $v['enable_attributes'] = $v['enable_annotations']; + } + } + return $v; }) ->end() @@ -1033,7 +1041,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ->{$enableIfStandalone('symfony/validator', Validation::class)}() ->children() ->scalarNode('cache')->end() - ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() + ->booleanNode('enable_annotations')->end() + ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->arrayNode('static_method') ->defaultValue(['loadValidatorMetadata']) ->prototype('scalar')->end() @@ -1139,10 +1148,23 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e $rootNode ->children() ->arrayNode('serializer') + ->validate() + ->always(function ($v) { + if (isset($v['enable_annotations'])) { + trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.serializer" is deprecated. Use the "enable_attributes" option instead.'); + + if (!isset($v['enable_attributes'])) { + $v['enable_attributes'] = $v['enable_annotations']; + } + } + + return $v; + })->end() ->info('serializer configuration') ->{$enableIfStandalone('symfony/serializer', Serializer::class)}() ->children() - ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() + ->booleanNode('enable_annotations')->end() + ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->scalarNode('name_converter')->end() ->scalarNode('circular_reference_handler')->end() ->scalarNode('max_depth_handler')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 559b549380fbc..759131bd61edc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1657,8 +1657,8 @@ private function registerValidationConfiguration(array $config, ContainerBuilder $definition = $container->findDefinition('validator.email'); $definition->replaceArgument(0, $config['email_validation_mode']); - if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) { - $validatorBuilder->addMethodCall('enableAnnotationMapping', [true]); + if (\array_key_exists('enable_attributes', $config) && $config['enable_attributes']) { + $validatorBuilder->addMethodCall('enableAttributeMapping', [true]); if ($this->isInitializedConfigEnabled('annotations') && method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) { $validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]); } @@ -1930,7 +1930,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder } $serializerLoaders = []; - if (isset($config['enable_annotations']) && $config['enable_annotations']) { + if (isset($config['enable_attributes']) && $config['enable_attributes']) { if ($container->getParameter('kernel.debug')) { $container->removeDefinition('serializer.mapping.cache_class_metadata_factory'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 324c41b3e705d..61494cfd3be69 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -269,6 +269,7 @@ + @@ -322,6 +323,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php index 92ef379b1b819..cc471e43fc685 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(); + $validatorBuilder->enableAttributeMapping(); $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(); + $validatorBuilder->enableAttributeMapping(); $file = sys_get_temp_dir().'/cache-validator-with-annotations.php'; @unlink($file); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 63b6f9e992d5d..55020f78cf655 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -591,7 +591,7 @@ protected static function getBundleDefaultConfig() ], 'validation' => [ 'enabled' => !class_exists(FullStack::class), - 'enable_annotations' => !class_exists(FullStack::class), + 'enable_attributes' => !class_exists(FullStack::class), 'static_method' => ['loadValidatorMetadata'], 'translation_domain' => 'validators', 'mapping' => [ @@ -612,7 +612,7 @@ protected static function getBundleDefaultConfig() 'serializer' => [ 'default_context' => ['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => true], 'enabled' => true, - 'enable_annotations' => !class_exists(FullStack::class), + 'enable_attributes' => !class_exists(FullStack::class), 'mapping' => ['paths' => []], ], 'property_access' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index b480ef9f0e3b6..b5d8061e4d0af 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -63,7 +63,7 @@ 'annotations' => false, 'serializer' => [ 'enabled' => true, - 'enable_annotations' => true, + 'enable_attributes' => true, 'name_converter' => 'serializer.name_converter.camel_case_to_snake_case', 'circular_reference_handler' => 'my.circular.reference.handler', 'max_depth_handler' => 'my.max.depth.handler', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php index c6a1636dbb31d..1e3d1ab2b9cf3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php @@ -6,7 +6,7 @@ 'php_errors' => ['log' => true], 'annotations' => false, 'serializer' => [ - 'enable_annotations' => true, + 'enable_attributes' => true, 'mapping' => [ 'paths' => [ '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping_without_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping_without_annotations.php index 8f86200686b6a..3e203028ce2ac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping_without_annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping_without_annotations.php @@ -6,7 +6,7 @@ 'handle_all_throwables' => true, 'php_errors' => ['log' => true], 'serializer' => [ - 'enable_annotations' => false, + 'enable_attributes' => false, 'mapping' => [ 'paths' => [ '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_attributes.php similarity index 91% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_attributes.php index f8298cc05f0c1..3e6ae75473060 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_attributes.php @@ -8,7 +8,7 @@ 'secret' => 's3cr3t', 'validation' => [ 'enabled' => true, - 'enable_annotations' => true, + 'enable_attributes' => true, 'email_validation_mode' => 'html5', ], ]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php index 82c47cdced33c..5261809727490 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php @@ -10,7 +10,7 @@ 'secret' => 's3cr3t', 'validation' => [ 'enabled' => true, - 'enable_annotations' => true, + 'enable_attributes' => true, 'email_validation_mode' => 'html5', ], ]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 88baf0d046beb..92e4405a003fd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -34,7 +34,7 @@ - + true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml index f3598b2a0e2e9..165669fe6d1de 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml @@ -7,7 +7,7 @@ - + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping_without_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping_without_annotations.xml index b33f7b3136d01..bb8dccf9c3d62 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping_without_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping_without_annotations.xml @@ -7,7 +7,7 @@ - + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_attributes.xml similarity index 88% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_attributes.xml index 8c7bbd02baf21..fe269612a75be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_attributes.xml @@ -9,7 +9,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml index 562e0e7282b70..71e3e7eb5c265 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml @@ -9,7 +9,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 9353e070670aa..883e9d6c20ebb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -53,7 +53,7 @@ framework: annotations: false serializer: enabled: true - enable_annotations: true + enable_attributes: true name_converter: serializer.name_converter.camel_case_to_snake_case circular_reference_handler: my.circular.reference.handler max_depth_handler: my.max.depth.handler diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml index 421103a21fc6b..b2966b0edc86e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml @@ -5,7 +5,7 @@ framework: log: true annotations: false serializer: - enable_annotations: true + enable_attributes: true mapping: paths: - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping_without_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping_without_annotations.yml index c946d26439294..46425dc942932 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping_without_annotations.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping_without_annotations.yml @@ -5,7 +5,7 @@ framework: php_errors: log: true serializer: - enable_annotations: false + enable_attributes: false mapping: paths: - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_attributes.yml similarity index 90% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_attributes.yml index 0c09405533e75..2b62f8a3ec976 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_attributes.yml @@ -7,7 +7,7 @@ framework: secret: s3cr3t validation: enabled: true - enable_annotations: true + enable_attributes: true email_validation_mode: html5 services: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml index 0f0a126edb171..8da9b008ff730 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml @@ -8,7 +8,7 @@ framework: secret: s3cr3t validation: enabled: true - enable_annotations: true + enable_attributes: true email_validation_mode: html5 services: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 867b25b501ca9..611d36240e5ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1241,7 +1241,7 @@ public function testValidation() $this->assertSame([$xmlMappings], $calls[3][1]); $i = 3; if ($annotations) { - $this->assertSame('enableAnnotationMapping', $calls[++$i][0]); + $this->assertSame('enableAttributeMapping', $calls[++$i][0]); } $this->assertSame('addMethodMapping', $calls[++$i][0]); $this->assertSame(['loadValidatorMetadata'], $calls[$i][1]); @@ -1251,7 +1251,7 @@ public function testValidation() public function testValidationService() { - $container = $this->createContainerFromFile('validation_annotations', ['kernel.charset' => 'UTF-8'], false); + $container = $this->createContainerFromFile('validation_attributes', ['kernel.charset' => 'UTF-8'], false); $this->assertInstanceOf(ValidatorInterface::class, $container->get('validator.alias')); } @@ -1282,14 +1282,14 @@ public function testFileLinkFormat() $this->assertEquals('file%link%format', $container->getParameter('debug.file_link_format')); } - public function testValidationAnnotations() + public function testValidationAttributes() { - $container = $this->createContainerFromFile('validation_annotations'); + $container = $this->createContainerFromFile('validation_attributes'); $calls = $container->getDefinition('validator.builder')->getMethodCalls(); $this->assertCount(7, $calls); - $this->assertSame('enableAnnotationMapping', $calls[4][0]); + $this->assertSame('enableAttributeMapping', $calls[4][0]); $this->assertSame('addMethodMapping', $calls[5][0]); $this->assertSame(['loadValidatorMetadata'], $calls[5][1]); $this->assertSame('setMappingCache', $calls[6][0]); @@ -1309,7 +1309,7 @@ public function testValidationLegacyAnnotations() $calls = $container->getDefinition('validator.builder')->getMethodCalls(); $this->assertCount(8, $calls); - $this->assertSame('enableAnnotationMapping', $calls[4][0]); + $this->assertSame('enableAttributeMapping', $calls[4][0]); if (method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) { $this->assertSame('setDoctrineAnnotationReader', $calls[5][0]); $this->assertEquals([new Reference('annotation_reader')], $calls[5][1]); @@ -1328,7 +1328,7 @@ public function testValidationPaths() { require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php'; - $container = $this->createContainerFromFile('validation_annotations', [ + $container = $this->createContainerFromFile('validation_attributes', [ 'kernel.bundles' => ['TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'], 'kernel.bundles_metadata' => ['TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle']], ]); @@ -1338,7 +1338,7 @@ public function testValidationPaths() $this->assertCount(8, $calls); $this->assertSame('addXmlMappings', $calls[3][0]); $this->assertSame('addYamlMappings', $calls[4][0]); - $this->assertSame('enableAnnotationMapping', $calls[5][0]); + $this->assertSame('enableAttributeMapping', $calls[5][0]); $this->assertSame('addMethodMapping', $calls[6][0]); $this->assertSame(['loadValidatorMetadata'], $calls[6][1]); $this->assertSame('setMappingCache', $calls[7][0]); @@ -1364,7 +1364,7 @@ public function testValidationPathsUsingCustomBundlePath() { require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php'; - $container = $this->createContainerFromFile('validation_annotations', [ + $container = $this->createContainerFromFile('validation_attributes', [ 'kernel.bundles' => ['CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'], 'kernel.bundles_metadata' => ['TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/CustomPathBundle']], ]); @@ -1399,7 +1399,7 @@ public function testValidationNoStaticMethod() $this->assertSame('addXmlMappings', $calls[3][0]); $i = 3; if ($annotations) { - $this->assertSame('enableAnnotationMapping', $calls[++$i][0]); + $this->assertSame('enableAttributeMapping', $calls[++$i][0]); } $this->assertSame('setMappingCache', $calls[++$i][0]); $this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[$i][1]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml index bfd6e1b5a94f2..1eaee513c899b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml @@ -4,7 +4,7 @@ framework: handle_all_throwables: true secret: test router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml", utf8: true } - validation: { enabled: true, enable_annotations: true, email_validation_mode: html5 } + validation: { enabled: true, enable_attributes: true, email_validation_mode: html5 } csrf_protection: true form: enabled: true diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index a4525d9724a4d..c190985c22cab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -64,7 +64,7 @@ "symfony/string": "^5.4|^6.0|^7.0", "symfony/translation": "^6.2.8|^7.0", "symfony/twig-bundle": "^5.4|^6.0|^7.0", - "symfony/validator": "^6.3|^7.0", + "symfony/validator": "^6.4|^7.0", "symfony/workflow": "^5.4|^6.0|^7.0", "symfony/yaml": "^5.4|^6.0|^7.0", "symfony/property-info": "^5.4|^6.0|^7.0", diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml index e7fbaa4adde07..9d6b4caee1707 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml @@ -4,7 +4,7 @@ framework: handle_all_throwables: true secret: test router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml", utf8: true } - validation: { enabled: true, enable_annotations: true, email_validation_mode: html5 } + validation: { enabled: true, enable_attributes: true, email_validation_mode: html5 } csrf_protection: true form: enabled: true diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml index 7ef9642b7daab..c197fcaa4c25e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml @@ -4,7 +4,7 @@ framework: handle_all_throwables: true secret: test router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml", utf8: true } - validation: { enabled: true, enable_annotations: true, email_validation_mode: html5 } + validation: { enabled: true, enable_attributes: true, email_validation_mode: html5 } assets: ~ csrf_protection: true form: diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index f2d689f0737e0..5ac676066c012 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -39,7 +39,7 @@ "symfony/dom-crawler": "^5.4|^6.0|^7.0", "symfony/expression-language": "^5.4|^6.0|^7.0", "symfony/form": "^5.4|^6.0|^7.0", - "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", "symfony/http-client": "^5.4|^6.0|^7.0", "symfony/ldap": "^5.4|^6.0|^7.0", "symfony/process": "^5.4|^6.0|^7.0", @@ -48,7 +48,7 @@ "symfony/translation": "^5.4|^6.0|^7.0", "symfony/twig-bundle": "^5.4|^6.0|^7.0", "symfony/twig-bridge": "^5.4|^6.0|^7.0", - "symfony/validator": "^5.4|^6.0|^7.0", + "symfony/validator": "^6.4|^7.0", "symfony/yaml": "^5.4|^6.0|^7.0", "twig/twig": "^2.13|^3.0.4", "web-token/jwt-checker": "^3.1", @@ -61,7 +61,7 @@ "conflict": { "symfony/browser-kit": "<5.4", "symfony/console": "<5.4", - "symfony/framework-bundle": "<6.3", + "symfony/framework-bundle": "<6.4", "symfony/http-client": "<5.4", "symfony/ldap": "<5.4", "symfony/twig-bundle": "<5.4" diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php index 9eda13abf48d2..326551d87b57e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php @@ -521,7 +521,7 @@ public function testValidationGroupsPassed(string $method, ValueResolver $attrib $payload->title = 'A long title, so the validation passes'; $serializer = new Serializer([new ObjectNormalizer()]); - $validator = (new ValidatorBuilder())->enableAnnotationMapping()->getValidator(); + $validator = (new ValidatorBuilder())->enableAttributeMapping()->getValidator(); $resolver = new RequestPayloadValueResolver($serializer, $validator); $request = Request::create('/', $method, $input); @@ -547,7 +547,7 @@ public function testValidationGroupsNotPassed(string $method, ValueResolver $att $input = ['price' => '50', 'title' => 'Too short']; $serializer = new Serializer([new ObjectNormalizer()]); - $validator = (new ValidatorBuilder())->enableAnnotationMapping()->getValidator(); + $validator = (new ValidatorBuilder())->enableAttributeMapping()->getValidator(); $resolver = new RequestPayloadValueResolver($serializer, $validator); $argument = new ArgumentMetadata('valid', RequestPayload::class, false, false, null, false, [ diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index eb86f75bf6321..9c06fea35c96b 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -43,7 +43,7 @@ "symfony/translation": "^5.4|^6.0|^7.0", "symfony/translation-contracts": "^2.5|^3", "symfony/uid": "^5.4|^6.0|^7.0", - "symfony/validator": "^6.3|^7.0", + "symfony/validator": "^6.4|^7.0", "symfony/var-exporter": "^6.2|^7.0", "psr/cache": "^1.0|^2.0|^3.0", "twig/twig": "^2.13|^3.0.4" diff --git a/src/Symfony/Component/Routing/Loader/DirectoryLoader.php b/src/Symfony/Component/Routing/Loader/DirectoryLoader.php index 5f241bffeb6b1..4ea7c6ba41a5a 100644 --- a/src/Symfony/Component/Routing/Loader/DirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/DirectoryLoader.php @@ -45,7 +45,7 @@ public function load(mixed $file, string $type = null): mixed public function supports(mixed $resource, string $type = null): bool { - // only when type is forced to directory, not to conflict with AnnotationLoader + // only when type is forced to directory, not to conflict with AttributeLoader return 'directory' === $type; } diff --git a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordTest.php b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordTest.php index fae450b6842f5..46728aeab64d9 100644 --- a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class UserPasswordTest extends TestCase { @@ -40,7 +41,7 @@ public static function provideServiceValidatedConstraints(): iterable yield 'named arguments' => [new UserPassword(service: 'my_service')]; $metadata = new ClassMetadata(UserPasswordDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); yield 'attribute' => [$metadata->properties['b']->constraints[0]]; } @@ -48,7 +49,7 @@ public static function provideServiceValidatedConstraints(): iterable public function testAttributes() { $metadata = new ClassMetadata(UserPasswordDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); self::assertSame('myMessage', $bConstraint->message); diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 86da5aeba183d..3f1883b481194 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -12,6 +12,9 @@ CHANGELOG * Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` * Add `number`, `finite-number` and `finite-float` types to `Type` constraint * Add the `withSeconds` option to the `Time` constraint that allows to pass time without seconds + * Deprecate `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead + * Deprecate `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead + * Deprecate `AnnotationLoader`, use `AttributeLoader` instead 6.3 --- diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php index a3cdfb12047ea..4c801103f97a3 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php @@ -22,6 +22,8 @@ /** * Loads validation metadata using a Doctrine annotation {@link Reader} or using PHP 8 attributes. * + * @deprecated since Symfony 6.4, use {@see AttributeLoader} instead + * * @author Bernhard Schussek * @author Alexander M. Turek */ diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php new file mode 100644 index 0000000000000..9674122b64115 --- /dev/null +++ b/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Mapping\Loader; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\Constraints\GroupSequence; +use Symfony\Component\Validator\Constraints\GroupSequenceProvider; +use Symfony\Component\Validator\Exception\MappingException; +use Symfony\Component\Validator\Mapping\ClassMetadata; + +/** + * Loads validation metadata using PHP attributes. + * + * @author Bernhard Schussek + * @author Alexander M. Turek + * @author Alexandre Daubois + */ +class AttributeLoader implements LoaderInterface +{ + public function loadClassMetadata(ClassMetadata $metadata): bool + { + $reflClass = $metadata->getReflectionClass(); + $className = $reflClass->name; + $success = false; + + foreach ($this->getAttributes($reflClass) as $constraint) { + if ($constraint instanceof GroupSequence) { + $metadata->setGroupSequence($constraint->groups); + } elseif ($constraint instanceof GroupSequenceProvider) { + $metadata->setGroupSequenceProvider(true); + } elseif ($constraint instanceof Constraint) { + $metadata->addConstraint($constraint); + } + + $success = true; + } + + foreach ($reflClass->getProperties() as $property) { + if ($property->getDeclaringClass()->name === $className) { + foreach ($this->getAttributes($property) as $constraint) { + if ($constraint instanceof Constraint) { + $metadata->addPropertyConstraint($property->name, $constraint); + } + + $success = true; + } + } + } + + foreach ($reflClass->getMethods() as $method) { + if ($method->getDeclaringClass()->name === $className) { + foreach ($this->getAttributes($method) as $constraint) { + if ($constraint instanceof Callback) { + $constraint->callback = $method->getName(); + + $metadata->addConstraint($constraint); + } elseif ($constraint instanceof Constraint) { + if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) { + $metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint); + } else { + throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name)); + } + } + + $success = true; + } + } + } + + return $success; + } + + private function getAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflection): iterable + { + foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) { + yield $attribute->newInstance(); + } + foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) { + yield $attribute->newInstance(); + } + foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + yield $attribute->newInstance(); + } + } +} diff --git a/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php b/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php index 41eab9d8f2e21..46f9d1f14101e 100644 --- a/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Dummy\DummyClassOne; /** @@ -26,7 +27,7 @@ class DebugCommandTest extends TestCase { public function testOutputWithClassArgument() { - $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader())); + $command = new DebugCommand(new LazyLoadingMetadataFactory(new AttributeLoader())); $tester = new CommandTester($command); $tester->execute(['class' => DummyClassOne::class], ['decorated' => false]); @@ -82,7 +83,7 @@ public function testOutputWithClassArgument() public function testOutputWithPathArgument() { - $command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader())); + $command = new DebugCommand(new LazyLoadingMetadataFactory(new AttributeLoader())); $tester = new CommandTester($command); $tester->execute(['class' => __DIR__.'/../Dummy'], ['decorated' => false]); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php index c6b474ad3ee8c..1456fa5fcdd59 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class BicValidatorTest extends ConstraintValidatorTestCase @@ -74,7 +75,7 @@ public function testInvalidComparisonToPropertyPath() public function testInvalidComparisonToPropertyPathFromAttribute() { $classMetadata = new ClassMetadata(BicDummy::class); - (new AnnotationLoader())->loadClassMetadata($classMetadata); + (new AttributeLoader())->loadClassMetadata($classMetadata); [$constraint] = $classMetadata->properties['bic1']->constraints; @@ -116,7 +117,7 @@ public function testInvalidComparisonToValue() public function testInvalidComparisonToValueFromAttribute() { $classMetadata = new ClassMetadata(BicDummy::class); - (new AnnotationLoader())->loadClassMetadata($classMetadata); + (new AttributeLoader())->loadClassMetadata($classMetadata); [$constraint] = $classMetadata->properties['bic1']->constraints; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeTest.php index e57481917a7b5..b77d035223f9c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\CardScheme; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CardSchemeTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(CardSchemeDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CascadeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CascadeTest.php index d2ac6a2059e4d..e7334d00c798e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CascadeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CascadeTest.php @@ -16,13 +16,14 @@ use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CascadeTest extends TestCase { public function testCascadeAttribute() { $metadata = new ClassMetadata(CascadeDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertSame(CascadingStrategy::NONE, $metadata->getCascadingStrategy()); self::assertTrue($loader->loadClassMetadata($metadata)); self::assertSame(CascadingStrategy::CASCADE, $metadata->getCascadingStrategy()); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceTest.php index cbdaf3f8e8aa4..210a62891ce38 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Fixtures\ConstraintChoiceWithPreset; class ChoiceTest extends TestCase @@ -29,7 +30,7 @@ public function testSetDefaultPropertyChoice() public function testAttributes() { $metadata = new ClassMetadata(ChoiceDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); /** @var Choice $aConstraint */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CidrTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CidrTest.php index 33ce5bdc73ec3..735945c7cefe2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CidrTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CidrTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CidrTest extends TestCase { @@ -123,7 +124,7 @@ public static function getValidMinMaxValues(): array public function testAttributes() { $metadata = new ClassMetadata(CidrDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountTest.php index 1493cbf763f6f..f2f9aa58b0703 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Count; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CountTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(CountDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryTest.php index 19f5978d43710..0eb1762c9f790 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Country; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CountryTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(CountryDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CssColorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CssColorTest.php index ae34c3201d55f..ed2cb233f1660 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CssColorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CssColorTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\CssColor; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Mathieu Santostefano @@ -24,7 +25,7 @@ final class CssColorTest extends TestCase public function testAttributes() { $metadata = new ClassMetadata(CssColorDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyTest.php index 883e78b488503..0d304f281acd4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Currency; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class CurrencyTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(CurrencyDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTest.php index 22b318ef30be3..2aad95bafa182 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Date; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class DateTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(DateDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeTest.php index e93870f623722..bb48ea9839ecd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class DateTimeTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(DateTimeDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DisableAutoMappingTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DisableAutoMappingTest.php index 63b2aaf457358..2adfabf80653d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DisableAutoMappingTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DisableAutoMappingTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Kévin Dunglas @@ -34,7 +35,7 @@ public function testGroups() public function testDisableAutoMappingAttribute() { $metadata = new ClassMetadata(DisableAutoMappingDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertSame(AutoMappingStrategy::NONE, $metadata->getAutoMappingStrategy()); self::assertTrue($loader->loadClassMetadata($metadata)); self::assertSame(AutoMappingStrategy::DISABLED, $metadata->getAutoMappingStrategy()); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByTest.php index 7388bc71733b9..9a7ed8473de85 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\DivisibleBy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class DivisibleByTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(DivisibleByDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php index b181e61edec7c..b30fead083a7e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class EmailTest extends TestCase { @@ -64,7 +65,7 @@ public function testInvalidNormalizerObjectThrowsException() public function testAttribute() { $metadata = new ClassMetadata(EmailDummy::class); - (new AnnotationLoader())->loadClassMetadata($metadata); + (new AttributeLoader())->loadClassMetadata($metadata); [$aConstraint] = $metadata->properties['a']->constraints; self::assertNull($aConstraint->mode); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EnableAutoMappingTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EnableAutoMappingTest.php index db09c8ad3e02d..073708c38bf9c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EnableAutoMappingTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EnableAutoMappingTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Mapping\AutoMappingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Kévin Dunglas @@ -34,7 +35,7 @@ public function testGroups() public function testDisableAutoMappingAttribute() { $metadata = new ClassMetadata(EnableAutoMappingDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertSame(AutoMappingStrategy::NONE, $metadata->getAutoMappingStrategy()); self::assertTrue($loader->loadClassMetadata($metadata)); self::assertSame(AutoMappingStrategy::ENABLED, $metadata->getAutoMappingStrategy()); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EqualToTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EqualToTest.php index d63be4af6ecd9..4109598ea3abd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EqualToTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EqualToTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\EqualTo; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class EqualToTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(EqualToDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxTest.php index 2fb8bf15500d0..620b5769a178c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Constraints\ExpressionLanguageSyntaxValidator; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @group legacy @@ -44,7 +45,7 @@ public static function provideServiceValidatedConstraints(): iterable yield 'named arguments' => [new ExpressionLanguageSyntax(service: 'my_service')]; $metadata = new ClassMetadata(ExpressionLanguageSyntaxDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); yield 'attribute' => [$metadata->properties['b']->constraints[0]]; } @@ -52,7 +53,7 @@ public static function provideServiceValidatedConstraints(): iterable public function testAttributes() { $metadata = new ClassMetadata(ExpressionLanguageSyntaxDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertNull($aConstraint->service); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionSyntaxTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionSyntaxTest.php index 7f319f23d5ef1..c16b95939e830 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionSyntaxTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionSyntaxTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Constraints\ExpressionSyntaxValidator; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class ExpressionSyntaxTest extends TestCase { @@ -41,7 +42,7 @@ public static function provideServiceValidatedConstraints(): iterable yield 'named arguments' => [new ExpressionSyntax(service: 'my_service')]; $metadata = new ClassMetadata(ExpressionSyntaxDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); yield 'attribute' => [$metadata->properties['b']->constraints[0]]; } @@ -49,7 +50,7 @@ public static function provideServiceValidatedConstraints(): iterable public function testAttributes() { $metadata = new ClassMetadata(ExpressionSyntaxDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertNull($aConstraint->service); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionTest.php index 08d4b5ffb2e85..2b66def1d5d45 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class ExpressionTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(ExpressionDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertSame('value == "1"', $aConstraint->expression); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php index c9a36d020f226..169d0791f0c04 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class FileTest extends TestCase { @@ -144,7 +145,7 @@ public static function provideFormats() public function testAttributes() { $metadata = new ClassMetadata(FileDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertNull($aConstraint->maxSize); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualTest.php index f997d3821c2a2..dc2b354ef7e11 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class GreaterThanOrEqualTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(GreaterThanOrEqualDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanTest.php index 848db00204b93..9f01ca9e81e7e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class GreaterThanTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(GreaterThanDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/HostnameTest.php b/src/Symfony/Component/Validator/Tests/Constraints/HostnameTest.php index ed682747ba67f..9cc9983c2db72 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/HostnameTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/HostnameTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Hostname; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class HostnameTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(HostnameDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index ef8f208753f24..b69e7c555ebb5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\IbanValidator; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class IbanValidatorTest extends ConstraintValidatorTestCase @@ -439,7 +440,7 @@ public function testIbansWithInvalidCountryCode($iban) public function testLoadFromAttribute() { $classMetadata = new ClassMetadata(IbanDummy::class); - (new AnnotationLoader())->loadClassMetadata($classMetadata); + (new AttributeLoader())->loadClassMetadata($classMetadata); [$constraint] = $classMetadata->properties['iban']->constraints; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToTest.php index fa550497d1ed7..35478c29ec0e9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\IdenticalTo; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class IdenticalToTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(IdenticalToDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ImageTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ImageTest.php index 9e6d57144c6b1..664b6f1b12c8d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ImageTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ImageTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class ImageTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(ImageDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpTest.php index 0854e53ebc38c..d723745acf933 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Renan Taranto @@ -46,7 +47,7 @@ public function testInvalidNormalizerObjectThrowsException() public function testAttributes() { $metadata = new ClassMetadata(IpDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsbnTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsbnTest.php index 305d3fec0e80d..23763fee02d9a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsbnTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsbnTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Isbn; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class IsbnTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(IsbnDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsinTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsinTest.php index 89aaecc764e9e..523486b0fbbe7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsinTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsinTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Isin; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class IsinTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(IsinDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IssnTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IssnTest.php index cd4085bf0f43f..f0175246e1de8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IssnTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IssnTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Issn; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class IssnTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(IssnDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/JsonTest.php b/src/Symfony/Component/Validator/Tests/Constraints/JsonTest.php index 15cd3c6942ae7..22cd26546a750 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/JsonTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/JsonTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Json; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class JsonTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(JsonDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageTest.php index ebeaa2e76f913..85c3a4a27a2ce 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Language; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class LanguageTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(LanguageDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php index c3b8606c3d994..52bbc1c75a956 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Renan Taranto @@ -82,7 +83,7 @@ public function testConstraintAnnotationDefaultOption() public function testAttributes() { $metadata = new ClassMetadata(LengthDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualTest.php index 77a12e1e95ee1..8eb5eb12ccbf0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\LessThanOrEqual; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class LessThanOrEqualTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(LessThanOrEqualDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanTest.php index 025c5069898af..6079611d353c4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\LessThan; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class LessThanTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(LessThanDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleTest.php index d2e048a4d3f5f..e1962f04b2d84 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Locale; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class LocaleTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(LocaleDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LuhnTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LuhnTest.php index 4f381b3f62495..324615bfdef12 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LuhnTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LuhnTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Luhn; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class LuhnTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(LuhnDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NegativeOrZeroTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NegativeOrZeroTest.php index 625dc436c8490..93682b754daa3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NegativeOrZeroTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NegativeOrZeroTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\NegativeOrZero; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class NegativeOrZeroTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(NegativeOrZeroDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NegativeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NegativeTest.php index a4b8f6a53c1ee..41e75625bdbae 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NegativeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NegativeTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Negative; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class NegativeTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(NegativeDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankTest.php index d6d03c036d5c0..4edb5c1487405 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Renan Taranto @@ -32,7 +33,7 @@ public function testNormalizerCanBeSet() public function testAttributes() { $metadata = new ClassMetadata(NotBlankDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php index 622d86dbfb759..2ddfdd1ee7ecf 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\NotCompromisedPassword; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Kévin Dunglas @@ -31,7 +32,7 @@ public function testDefaultValues() public function testAttributes() { $metadata = new ClassMetadata(NotCompromisedPasswordDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToTest.php index 0da3c5874b248..e8dc9e010dfca 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\NotEqualTo; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class NotEqualToTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(NotEqualToDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToTest.php index 7d561e60c42e9..ec99c03a385f6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\NotIdenticalTo; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class NotIdenticalToTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(NotIdenticalToDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/PositiveOrZeroTest.php b/src/Symfony/Component/Validator/Tests/Constraints/PositiveOrZeroTest.php index e68b5a7fc4d30..355bb2ea268fd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/PositiveOrZeroTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/PositiveOrZeroTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\PositiveOrZero; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class PositiveOrZeroTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(PositiveOrZeroDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/PositiveTest.php b/src/Symfony/Component/Validator/Tests/Constraints/PositiveTest.php index 4a56243fc9e3f..faa086ec36fb2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/PositiveTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/PositiveTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Positive; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class PositiveTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(PositiveDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php index 74fbec23b9333..c5a19e1e1e5ca 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Bernhard Schussek @@ -113,7 +114,7 @@ public function testInvalidNormalizerObjectThrowsException() public function testAttributes() { $metadata = new ClassMetadata(RegexDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeTest.php index ba63e3187ec5e..5fccc47e9ffac 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Time; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class TimeTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(TimeDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php index 90291c5763944..ab53d991e5672 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimezoneTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Javier Spagnoletti @@ -69,7 +70,7 @@ public static function provideInvalidZones(): iterable public function testAttributes() { $metadata = new ClassMetadata(TimezoneDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertSame(\DateTimeZone::ALL, $aConstraint->zone); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TraverseTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TraverseTest.php index efa42005bd126..a3ce76c093a0e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TraverseTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TraverseTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Traverse; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Mapping\TraversalStrategy; class TraverseTest extends TestCase @@ -22,7 +23,7 @@ class TraverseTest extends TestCase public function testPositiveAttributes() { $metadata = new ClassMetadata(TraverseDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); self::assertSame(TraversalStrategy::TRAVERSE, $metadata->getTraversalStrategy()); } @@ -30,7 +31,7 @@ public function testPositiveAttributes() public function testNegativeAttribute() { $metadata = new ClassMetadata(DoNotTraverseMe::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); self::assertSame(TraversalStrategy::NONE, $metadata->getTraversalStrategy()); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeTest.php index f081110a7f382..3af8d374207b3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Type; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class TypeTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(TypeDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertSame('integer', $aConstraint->type); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UlidTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UlidTest.php index 74fcc30083f9c..790eed6406b95 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UlidTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UlidTest.php @@ -15,13 +15,14 @@ use Symfony\Component\Validator\Constraints\Ulid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class UlidTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(UlidDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php index c8327e3c2fc9a..7420a5bf5e787 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php @@ -16,13 +16,14 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; class UniqueTest extends TestCase { public function testAttributes() { $metadata = new ClassMetadata(UniqueDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlTest.php index 8196a6284b6d3..477335cc03ca0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Renan Taranto @@ -46,7 +47,7 @@ public function testInvalidNormalizerObjectThrowsException() public function testAttributes() { $metadata = new ClassMetadata(UrlDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertSame(['http', 'https'], $aConstraint->protocols); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UuidTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UuidTest.php index ecb7aee326a14..abc504f8b6c35 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UuidTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UuidTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Renan Taranto @@ -46,7 +47,7 @@ public function testInvalidNormalizerObjectThrowsException() public function testAttributes() { $metadata = new ClassMetadata(UuidDummy::class); - self::assertTrue((new AnnotationLoader())->loadClassMetadata($metadata)); + self::assertTrue((new AttributeLoader())->loadClassMetadata($metadata)); [$aConstraint] = $metadata->properties['a']->getConstraints(); self::assertSame(Uuid::ALL_VERSIONS, $aConstraint->versions); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php index e84dbd71d8fd6..3a4364922af43 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; /** * @author Bernhard Schussek @@ -38,7 +39,7 @@ public function testGroupsAreNullByDefault() public function testAttributes() { $metadata = new ClassMetaData(ValidDummy::class); - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); [$bConstraint] = $metadata->properties['b']->getConstraints(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php index 8c625949feb13..a3765172b1d8e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php @@ -20,7 +20,7 @@ class ValidValidatorTest extends TestCase public function testPropertyPathsArePassedToNestedContexts() { $validatorBuilder = new ValidatorBuilder(); - $validator = $validatorBuilder->enableAnnotationMapping()->getValidator(); + $validator = $validatorBuilder->enableAttributeMapping()->getValidator(); $violations = $validator->validate(new Foo(), null, ['nested']); @@ -31,7 +31,7 @@ public function testPropertyPathsArePassedToNestedContexts() public function testNullValues() { $validatorBuilder = new ValidatorBuilder(); - $validator = $validatorBuilder->enableAnnotationMapping()->getValidator(); + $validator = $validatorBuilder->enableAttributeMapping()->getValidator(); $foo = new Foo(); $foo->fooBar = null; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php index b3305b3c4fe86..8bf2a64cded0b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php @@ -22,6 +22,7 @@ use Symfony\Component\Validator\Exception\MissingOptionsException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Constraints\Fixtures\WhenTestWithAttributes; final class WhenTest extends TestCase @@ -130,7 +131,7 @@ public function testAnnotations() public function testAttributes() { - $loader = new AnnotationLoader(); + $loader = new AttributeLoader(); $metadata = new ClassMetadata(WhenTestWithAttributes::class); self::assertTrue($loader->loadClassMetadata($metadata)); diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php index 474064274bb37..401798b79daad 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php @@ -30,6 +30,7 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; class AnnotationLoaderTest extends TestCase diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php new file mode 100644 index 0000000000000..e663c8b3b2cd6 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php @@ -0,0 +1,223 @@ + + * + * 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 PHPUnit\Framework\TestCase; +use Symfony\Component\Validator\Constraints\All; +use Symfony\Component\Validator\Constraints\AtLeastOneOf; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\Constraints\Choice; +use Symfony\Component\Validator\Constraints\Collection; +use Symfony\Component\Validator\Constraints\Email; +use Symfony\Component\Validator\Constraints\Expression; +use Symfony\Component\Validator\Constraints\IsTrue; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\NotNull; +use Symfony\Component\Validator\Constraints\Optional; +use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\Required; +use Symfony\Component\Validator\Constraints\Sequentially; +use Symfony\Component\Validator\Constraints\Type; +use Symfony\Component\Validator\Constraints\Valid; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; +use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; + +class AttributeLoaderTest extends TestCase +{ + public function testLoadClassMetadataReturnsTrueIfSuccessful() + { + $loader = $this->createAttributeLoader(); + $metadata = new ClassMetadata($this->getFixtureNamespace().'\Entity'); + + $this->assertTrue($loader->loadClassMetadata($metadata)); + } + + public function testLoadClassMetadataReturnsFalseIfNotSuccessful() + { + $loader = $this->createAttributeLoader(); + $metadata = new ClassMetadata('\stdClass'); + + $this->assertFalse($loader->loadClassMetadata($metadata)); + } + + public function testLoadClassMetadata() + { + $loader = $this->createAttributeLoader(); + $namespace = $this->getFixtureNamespace(); + + $metadata = new ClassMetadata($namespace.'\Entity'); + + $loader->loadClassMetadata($metadata); + + $expected = new ClassMetadata($namespace.'\Entity'); + $expected->setGroupSequence(['Foo', 'Entity']); + $expected->addConstraint(new ConstraintA()); + $expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback'])); + $expected->addConstraint(new Sequentially([ + new Expression('this.getFirstName() != null'), + ])); + $expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo'])); + $expected->addConstraint(new Callback('validateMeStatic')); + $expected->addPropertyConstraint('firstName', new NotNull()); + $expected->addPropertyConstraint('firstName', new Range(['min' => 3])); + $expected->addPropertyConstraint('firstName', new All([new NotNull(), new Range(['min' => 3])])); + $expected->addPropertyConstraint('firstName', new All(['constraints' => [new NotNull(), new Range(['min' => 3])]])); + $expected->addPropertyConstraint('firstName', new Collection([ + 'foo' => [new NotNull(), new Range(['min' => 3])], + 'bar' => new Range(['min' => 5]), + 'baz' => new Required([new Email()]), + 'qux' => new Optional([new NotBlank()]), + ], null, null, true)); + $expected->addPropertyConstraint('firstName', new Choice([ + 'message' => 'Must be one of %choices%', + 'choices' => ['A', 'B'], + ])); + $expected->addPropertyConstraint('firstName', new AtLeastOneOf([ + new NotNull(), + new Range(['min' => 3]), + ], null, null, 'foo', null, false)); + $expected->addPropertyConstraint('firstName', new Sequentially([ + new NotBlank(), + new Range(['min' => 5]), + ])); + $expected->addPropertyConstraint('childA', new Valid()); + $expected->addPropertyConstraint('childB', new Valid()); + $expected->addGetterConstraint('lastName', new NotNull()); + $expected->addGetterMethodConstraint('valid', 'isValid', new IsTrue()); + $expected->addGetterConstraint('permissions', new IsTrue()); + $expected->addPropertyConstraint('other', new Type('integer')); + + // load reflection class so that the comparison passes + $expected->getReflectionClass(); + + $this->assertEquals($expected, $metadata); + } + + /** + * Test MetaData merge with parent annotation. + */ + public function testLoadParentClassMetadata() + { + $loader = $this->createAttributeLoader(); + $namespace = $this->getFixtureNamespace(); + + // Load Parent MetaData + $parent_metadata = new ClassMetadata($namespace.'\EntityParent'); + $loader->loadClassMetadata($parent_metadata); + + $expected_parent = new ClassMetadata($namespace.'\EntityParent'); + $expected_parent->addPropertyConstraint('other', new NotNull()); + $expected_parent->getReflectionClass(); + + $this->assertEquals($expected_parent, $parent_metadata); + } + + /** + * Test MetaData merge with parent annotation. + */ + public function testLoadClassMetadataAndMerge() + { + $loader = $this->createAttributeLoader(); + $namespace = $this->getFixtureNamespace(); + + // Load Parent MetaData + $parent_metadata = new ClassMetadata($namespace.'\EntityParent'); + $loader->loadClassMetadata($parent_metadata); + + $metadata = new ClassMetadata($namespace.'\Entity'); + $loader->loadClassMetadata($metadata); + + // Merge parent metaData. + $metadata->mergeConstraints($parent_metadata); + + $expected_parent = new ClassMetadata($namespace.'\EntityParent'); + $expected_parent->addPropertyConstraint('other', new NotNull()); + $expected_parent->getReflectionClass(); + + $expected = new ClassMetadata($namespace.'\Entity'); + + $expected->setGroupSequence(['Foo', 'Entity']); + $expected->addConstraint(new ConstraintA()); + $expected->addConstraint(new Callback(['Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback'])); + $expected->addConstraint(new Sequentially([ + new Expression('this.getFirstName() != null'), + ])); + $expected->addConstraint(new Callback(['callback' => 'validateMe', 'payload' => 'foo'])); + $expected->addConstraint(new Callback('validateMeStatic')); + $expected->addPropertyConstraint('firstName', new NotNull()); + $expected->addPropertyConstraint('firstName', new Range(['min' => 3])); + $expected->addPropertyConstraint('firstName', new All([new NotNull(), new Range(['min' => 3])])); + $expected->addPropertyConstraint('firstName', new All(['constraints' => [new NotNull(), new Range(['min' => 3])]])); + $expected->addPropertyConstraint('firstName', new Collection([ + 'foo' => [new NotNull(), new Range(['min' => 3])], + 'bar' => new Range(['min' => 5]), + 'baz' => new Required([new Email()]), + 'qux' => new Optional([new NotBlank()]), + ], null, null, true)); + $expected->addPropertyConstraint('firstName', new Choice([ + 'message' => 'Must be one of %choices%', + 'choices' => ['A', 'B'], + ])); + $expected->addPropertyConstraint('firstName', new AtLeastOneOf([ + new NotNull(), + new Range(['min' => 3]), + ], null, null, 'foo', null, false)); + $expected->addPropertyConstraint('firstName', new Sequentially([ + new NotBlank(), + new Range(['min' => 5]), + ])); + $expected->addPropertyConstraint('childA', new Valid()); + $expected->addPropertyConstraint('childB', new Valid()); + $expected->addGetterConstraint('lastName', new NotNull()); + $expected->addGetterMethodConstraint('valid', 'isValid', new IsTrue()); + $expected->addGetterConstraint('permissions', new IsTrue()); + $expected->addPropertyConstraint('other', new Type('integer')); + + // load reflection class so that the comparison passes + $expected->getReflectionClass(); + $expected->mergeConstraints($expected_parent); + + $this->assertEquals($expected, $metadata); + + $otherMetadata = $metadata->getPropertyMetadata('other'); + $this->assertCount(2, $otherMetadata); + $this->assertInstanceOf(Type::class, $otherMetadata[0]->getConstraints()[0]); + $this->assertInstanceOf(NotNull::class, $otherMetadata[1]->getConstraints()[0]); + } + + public function testLoadGroupSequenceProviderAnnotation() + { + $loader = $this->createAttributeLoader(); + $namespace = $this->getFixtureNamespace(); + + $metadata = new ClassMetadata($namespace.'\GroupSequenceProviderEntity'); + $loader->loadClassMetadata($metadata); + + $expected = new ClassMetadata($namespace.'\GroupSequenceProviderEntity'); + $expected->setGroupSequenceProvider(true); + $expected->getReflectionClass(); + + $this->assertEquals($expected, $metadata); + } + + protected function createAttributeLoader(): AttributeLoader + { + return new AttributeLoader(); + } + + protected function getFixtureNamespace(): string + { + return 'Symfony\Component\Validator\Tests\Fixtures\NestedAttribute'; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index 95cdee8c7dde0..d2f205d5177ac 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -92,7 +92,7 @@ public function testLoadClassMetadata() $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping() + ->enableAttributeMapping() ->addLoader($propertyInfoLoader) ->getValidator() ; @@ -230,7 +230,7 @@ public function testClassNoAutoMapping() $propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}'); $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping() + ->enableAttributeMapping() ->addLoader($propertyInfoLoader) ->getValidator() ; diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php index 5d844031b3522..94b5c97da5441 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php @@ -81,6 +81,7 @@ public function testAddMethodMappings() */ public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() { + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.'); $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.'); @@ -102,6 +103,7 @@ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader() { $reader = $this->createMock(Reader::class); + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.'); $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::setDoctrineAnnotationReader()" is deprecated without replacement.'); @@ -116,11 +118,29 @@ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader() $this->assertSame($reader, $r->getValue($loaders[0])); } - public function testDisableAnnotationMapping() + /** + * @group legacy + */ + public function testExpectDeprecationWhenEnablingAnnotationMapping() { + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.'); + $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); + } + + /** + * @group legacy + */ + public function testExpectDeprecationWhenDisablingAnnotationMapping() + { + $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::disableAnnotationMapping()" is deprecated, use "disableAttributeMapping()" instead.'); $this->assertSame($this->builder, $this->builder->disableAnnotationMapping()); } + public function testDisableAttributeMapping() + { + $this->assertSame($this->builder, $this->builder->disableAttributeMapping()); + } + public function testSetMappingCache() { $this->assertSame($this->builder, $this->builder->setMappingCache($this->createMock(CacheItemPoolInterface::class))); diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 88fd21645c180..571956369774e 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -22,6 +22,7 @@ use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Mapping\Loader\LoaderChain; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader; @@ -49,6 +50,10 @@ class ValidatorBuilder private array $yamlMappings = []; private array $methodMappings = []; private ?Reader $annotationReader = null; + private bool $enableAttributeMapping = false; + /** + * @deprecated since Symfony 6.4 + */ private bool $enableAnnotationMapping = false; private ?MetadataFactoryInterface $metadataFactory = null; private ConstraintValidatorFactoryInterface $validatorFactory; @@ -187,31 +192,58 @@ public function addMethodMappings(array $methodNames): static } /** - * Enables annotation and attribute based constraint mapping. + * @deprecated since Symfony 6.4, use "enableAttributeMapping()" instead. * * @return $this */ public function enableAnnotationMapping(): static + { + trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated, use "enableAttributeMapping()" instead.', __METHOD__); + + $this->enableAnnotationMapping = true; + + return $this->enableAttributeMapping(); + } + + /** + * Enables attribute based constraint mapping. + * + * @return $this + */ + public function enableAttributeMapping(): static { if (null !== $this->metadataFactory) { - throw new ValidatorException('You cannot enable annotation mapping after setting a custom metadata factory. Configure your metadata factory instead.'); + throw new ValidatorException('You cannot enable attribute mapping after setting a custom metadata factory. Configure your metadata factory instead.'); } - $this->enableAnnotationMapping = true; + $this->enableAttributeMapping = true; return $this; } /** - * Disables annotation and attribute based constraint mapping. + * @deprecated since Symfony 6.4, use "disableAttributeMapping()" instead * * @return $this */ public function disableAnnotationMapping(): static { - $this->enableAnnotationMapping = false; + trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated, use "disableAttributeMapping()" instead.', __METHOD__); + $this->annotationReader = null; + return $this->disableAttributeMapping(); + } + + /** + * Disables attribute based constraint mapping. + * + * @return $this + */ + public function disableAttributeMapping(): static + { + $this->enableAttributeMapping = false; + return $this; } @@ -250,7 +282,7 @@ public function addDefaultDoctrineAnnotationReader(): static */ public function setMetadataFactory(MetadataFactoryInterface $metadataFactory): static { - if (\count($this->xmlMappings) > 0 || \count($this->yamlMappings) > 0 || \count($this->methodMappings) > 0 || $this->enableAnnotationMapping) { + if (\count($this->xmlMappings) > 0 || \count($this->yamlMappings) > 0 || \count($this->methodMappings) > 0 || $this->enableAttributeMapping) { throw new ValidatorException('You cannot set a custom metadata factory after adding custom mappings. You should do either of both.'); } @@ -346,6 +378,8 @@ public function getLoaders(): array if ($this->enableAnnotationMapping) { $loaders[] = new AnnotationLoader($this->annotationReader); + } elseif ($this->enableAttributeMapping) { + $loaders[] = new AttributeLoader(); } return array_merge($loaders, $this->loaders);