From f819aed8d1319c77528dc6fbe92eea5837af4a26 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Wed, 26 Feb 2025 15:48:05 +0100 Subject: [PATCH 1/2] [PropertyInfo] Deprecate Type --- UPGRADE-7.3.md | 12 ++++++ src/Symfony/Bridge/Doctrine/CHANGELOG.md | 1 + .../PropertyInfo/DoctrineExtractor.php | 5 +++ .../PropertyInfo/DoctrineExtractorTest.php | 25 +++++++++++ .../Component/PropertyInfo/CHANGELOG.md | 3 ++ ...structorArgumentTypeExtractorInterface.php | 2 + .../Extractor/ConstructorExtractor.php | 5 +++ .../Extractor/PhpDocExtractor.php | 10 +++++ .../Extractor/PhpStanExtractor.php | 9 ++++ .../Extractor/ReflectionExtractor.php | 9 ++++ .../PropertyInfoCacheExtractor.php | 5 +++ .../PropertyInfo/PropertyInfoExtractor.php | 5 +++ .../PropertyTypeExtractorInterface.php | 2 + .../Extractor/ConstructorExtractorTest.php | 7 +++ .../Tests/Extractor/PhpDocExtractorTest.php | 38 ++++++++++++++++ .../Tests/Extractor/PhpStanExtractorTest.php | 43 +++++++++++++++++++ .../Extractor/ReflectionExtractorTest.php | 23 ++++++++++ .../Tests/PropertyInfoCacheExtractorTest.php | 5 +++ src/Symfony/Component/PropertyInfo/Type.php | 4 ++ .../PropertyInfo/Util/PhpDocTypeHelper.php | 4 ++ .../Component/PropertyInfo/composer.json | 1 + 21 files changed, 218 insertions(+) diff --git a/UPGRADE-7.3.md b/UPGRADE-7.3.md index 98d490584646f..89882edbc5b58 100644 --- a/UPGRADE-7.3.md +++ b/UPGRADE-7.3.md @@ -44,6 +44,11 @@ DependencyInjection * Deprecate `ContainerBuilder::getAutoconfiguredAttributes()` in favor of the `getAttributeAutoconfigurators()` method. +DoctrineBridge +-------------- + + * Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead + FrameworkBundle --------------- @@ -76,6 +81,13 @@ OptionsResolver }); ``` +PropertyInfo +------- + + * Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class from `symfony/type-info` instead + * Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead + * Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead + Security -------- diff --git a/src/Symfony/Bridge/Doctrine/CHANGELOG.md b/src/Symfony/Bridge/Doctrine/CHANGELOG.md index 01851164e6b3a..65c0daf6c9ee9 100644 --- a/src/Symfony/Bridge/Doctrine/CHANGELOG.md +++ b/src/Symfony/Bridge/Doctrine/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Reset the manager registry using native lazy objects when applicable + * Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead 7.2 --- diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 478fbfbe8e251..050b84acece96 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -161,8 +161,13 @@ public function getType(string $class, string $property, array $context = []): ? }; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + if (null === $metadata = $this->getMetadata($class)) { return null; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 7903da227e912..ad3d603adbfaf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -30,6 +30,7 @@ use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded; use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt; use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumString; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\PropertyInfo\Type as LegacyType; use Symfony\Component\TypeInfo\Type; @@ -38,6 +39,8 @@ */ class DoctrineExtractorTest extends TestCase { + use ExpectDeprecationTrait; + private function createExtractor(): DoctrineExtractor { $config = ORMSetup::createConfiguration(true); @@ -108,15 +111,24 @@ public function testTestGetPropertiesWithEmbedded() } /** + * @group legacy + * * @dataProvider legacyTypesProvider */ public function testExtractLegacy(string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.'); + $this->assertEquals($type, $this->createExtractor()->getTypes(DoctrineDummy::class, $property, [])); } + /** + * @group legacy + */ public function testExtractWithEmbeddedLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.'); + $expectedTypes = [new LegacyType( LegacyType::BUILTIN_TYPE_OBJECT, false, @@ -132,8 +144,13 @@ public function testExtractWithEmbeddedLegacy() $this->assertEquals($expectedTypes, $actualTypes); } + /** + * @group legacy + */ public function testExtractEnumLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.'); + $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', [])); $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', [])); $this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', [])); @@ -141,6 +158,9 @@ public function testExtractEnumLegacy() $this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', [])); } + /** + * @group legacy + */ public static function legacyTypesProvider(): array { // DBAL 4 has a special fallback strategy for BINGINT (int -> string) @@ -240,8 +260,13 @@ public function testGetPropertiesCatchException() $this->assertNull($this->createExtractor()->getProperties('Not\Exist')); } + /** + * @group legacy + */ public function testGetTypesCatchExceptionLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.'); + $this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz')); } diff --git a/src/Symfony/Component/PropertyInfo/CHANGELOG.md b/src/Symfony/Component/PropertyInfo/CHANGELOG.md index 78803e270751f..9f3cf35706b90 100644 --- a/src/Symfony/Component/PropertyInfo/CHANGELOG.md +++ b/src/Symfony/Component/PropertyInfo/CHANGELOG.md @@ -6,6 +6,9 @@ CHANGELOG * Add support for `non-positive-int`, `non-negative-int` and `non-zero-int` PHPStan types to `PhpStanExtractor` * Add `PropertyDescriptionExtractorInterface` to `PhpStanExtractor` + * Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class from `symfony/type-info` instead + * Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead + * Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead 7.1 --- diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php b/src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php index ea9e87b871f56..57695d8312114 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php @@ -24,6 +24,8 @@ interface ConstructorArgumentTypeExtractorInterface /** * Gets types of an argument from constructor. * + * @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead + * * @return LegacyType[]|null */ public function getTypesFromConstructor(string $class, string $property): ?array; diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ConstructorExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ConstructorExtractor.php index 26caa68735835..106158beeaa1e 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ConstructorExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ConstructorExtractor.php @@ -40,8 +40,13 @@ public function getType(string $class, string $property, array $context = []): ? return null; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + foreach ($this->extractors as $extractor) { $value = $extractor->getTypesFromConstructor($class, $property); if (null !== $value) { diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index ec44fcadd83c3..5ee3097851d19 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -118,8 +118,13 @@ public function getLongDescription(string $class, string $property, array $conte return '' === $contents ? null : $contents; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + /** @var DocBlock $docBlock */ [$docBlock, $source, $prefix] = $this->findDocBlock($class, $property); if (!$docBlock) { @@ -171,8 +176,13 @@ public function getTypes(string $class, string $property, array $context = []): return [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $types[0])]; } + /** + * @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead + */ public function getTypesFromConstructor(string $class, string $property): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class); + $docBlock = $this->getDocBlockFromConstructor($class, $property); if (!$docBlock) { diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index 32105e8a8a669..afe29bec26117 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -95,8 +95,13 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref $this->typeContextFactory = new TypeContextFactory($this->stringTypeResolver); } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + /** @var PhpDocNode|null $docNode */ [$docNode, $source, $prefix, $declaringClass] = $this->getDocBlock($class, $property); if (null === $docNode) { @@ -168,10 +173,14 @@ public function getTypes(string $class, string $property, array $context = []): } /** + * @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead + * * @return LegacyType[]|null */ public function getTypesFromConstructor(string $class, string $property): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class); + if (null === $tagDocNode = $this->getDocBlockFromConstructor($class, $property)) { return null; } diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 506a5fa24e02e..39b16caeb86e3 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -155,8 +155,13 @@ public function getProperties(string $class, array $context = []): ?array return $properties ? array_values($properties) : null; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + if ($fromMutator = $this->extractFromMutator($class, $property)) { return $fromMutator; } @@ -180,10 +185,14 @@ public function getTypes(string $class, string $property, array $context = []): } /** + * @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead + * * @return LegacyType[]|null */ public function getTypesFromConstructor(string $class, string $property): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class); + try { $reflection = new \ReflectionClass($class); } catch (\ReflectionException) { diff --git a/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php b/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php index 911e9f6350af3..866c38e99eb40 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php +++ b/src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php @@ -95,8 +95,13 @@ public function getType(string $class, string $property, array $context = []): ? return $this->arrayCache[$key] = $value; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + return $this->extract('getTypes', [$class, $property, $context]); } diff --git a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php index edbc6ef6140b8..5a54854bfbba4 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php +++ b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php @@ -75,8 +75,13 @@ public function getType(string $class, string $property, array $context = []): ? return null; } + /** + * @deprecated since Symfony 7.3, use "getType" instead + */ public function getTypes(string $class, string $property, array $context = []): ?array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + return $this->extract($this->typeExtractors, 'getTypes', [$class, $property, $context]); } diff --git a/src/Symfony/Component/PropertyInfo/PropertyTypeExtractorInterface.php b/src/Symfony/Component/PropertyInfo/PropertyTypeExtractorInterface.php index c986aaf586e22..358c08dd61c52 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyTypeExtractorInterface.php +++ b/src/Symfony/Component/PropertyInfo/PropertyTypeExtractorInterface.php @@ -26,6 +26,8 @@ interface PropertyTypeExtractorInterface /** * Gets types of a property. * + * @deprecated since Symfony 7.3, use "getType" instead + * * @return LegacyType[]|null */ public function getTypes(string $class, string $property, array $context = []): ?array; diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ConstructorExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ConstructorExtractorTest.php index fcfa7bb86a078..3ff7757a2f21a 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ConstructorExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ConstructorExtractorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\PropertyInfo\Tests\Extractor; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyExtractor; use Symfony\Component\PropertyInfo\Type as LegacyType; @@ -22,6 +23,8 @@ */ class ConstructorExtractorTest extends TestCase { + use ExpectDeprecationTrait; + private ConstructorExtractor $extractor; protected function setUp(): void @@ -50,6 +53,8 @@ public function testGetTypeIfNoExtractors() */ public function testGetTypes() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getType()" instead.'); + $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)], $this->extractor->getTypes('Foo', 'bar', [])); } @@ -58,6 +63,8 @@ public function testGetTypes() */ public function testGetTypesIfNoExtractors() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getType()" instead.'); + $extractor = new ConstructorExtractor([]); $this->assertNull($extractor->getTypes('Foo', 'bar', [])); } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php index 003011f87bf13..e956ec0f27f75 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\PropertyInfo\Tests\Extractor; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use phpDocumentor\Reflection\DocBlock; use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; @@ -34,6 +35,8 @@ */ class PhpDocExtractorTest extends TestCase { + use ExpectDeprecationTrait; + private PhpDocExtractor $extractor; protected function setUp(): void @@ -48,6 +51,8 @@ protected function setUp(): void */ public function testExtractLegacy($property, ?array $type, $shortDescription, $longDescription) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes(Dummy::class, $property)); $this->assertSame($shortDescription, $this->extractor->getShortDescription(Dummy::class, $property)); $this->assertSame($longDescription, $this->extractor->getLongDescription(Dummy::class, $property)); @@ -71,6 +76,8 @@ public function testGetDocBlock() */ public function testParamTagTypeIsOmittedLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType')); } @@ -90,6 +97,8 @@ public static function provideLegacyInvalidTypes() */ public function testInvalidLegacy($property, $shortDescription, $longDescription) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', $property)); $this->assertSame($shortDescription, $this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', $property)); $this->assertSame($longDescription, $this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', $property)); @@ -100,6 +109,8 @@ public function testInvalidLegacy($property, $shortDescription, $longDescription */ public function testEmptyParamAnnotationLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', 'foo')); $this->assertSame('Foo.', $this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', 'foo')); $this->assertNull($this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', 'foo')); @@ -112,6 +123,8 @@ public function testEmptyParamAnnotationLegacy() */ public function testExtractTypesWithNoPrefixesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $noPrefixExtractor = new PhpDocExtractor(null, [], [], []); $this->assertEquals($type, $noPrefixExtractor->getTypes(Dummy::class, $property)); @@ -240,6 +253,8 @@ public static function provideLegacyCollectionTypes() */ public function testExtractTypesWithCustomPrefixesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $customExtractor = new PhpDocExtractor(null, ['add', 'remove'], ['is', 'can']); $this->assertEquals($type, $customExtractor->getTypes(Dummy::class, $property)); @@ -356,6 +371,8 @@ public static function provideLegacyDockBlockFallbackTypes() */ public function testDocBlockFallbackLegacy($property, $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback', $property)); } @@ -366,6 +383,8 @@ public function testDocBlockFallbackLegacy($property, $types) */ public function testPropertiesDefinedByTraitsLegacy(string $property, LegacyType $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property)); } @@ -388,6 +407,8 @@ public static function provideLegacyPropertiesDefinedByTraits(): array */ public function testMethodsDefinedByTraitsLegacy(string $property, LegacyType $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property)); } @@ -410,6 +431,8 @@ public static function provideLegacyMethodsDefinedByTraits(): array */ public function testPropertiesStaticTypeLegacy(string $class, string $property, LegacyType $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals([$type], $this->extractor->getTypes($class, $property)); } @@ -428,6 +451,8 @@ public static function provideLegacyPropertiesStaticType(): array */ public function testPropertiesParentTypeLegacy(string $class, string $property, ?array $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes($class, $property)); } @@ -444,11 +469,18 @@ public static function provideLegacyPropertiesParentType(): array */ public function testUnknownPseudoTypeLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'scalar')], $this->extractor->getTypes(PseudoTypeDummy::class, 'unknownPseudoType')); } + /** + * @group legacy + */ public function testGenericInterface() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes(Dummy::class, 'genericInterface')); } @@ -459,6 +491,8 @@ public function testGenericInterface() */ public function testExtractConstructorTypesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypesFromConstructor()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypeFromConstructor()" instead.'); + $this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy', $property)); } @@ -481,6 +515,8 @@ public static function provideLegacyConstructorTypes() */ public function testPseudoTypesLegacy($property, array $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\PseudoTypesDummy', $property)); } @@ -506,6 +542,8 @@ public static function provideLegacyPseudoTypes(): array */ public function testExtractPromotedPropertyLegacy(string $property, ?array $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes(Php80Dummy::class, $property)); } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 092ecd9df1b83..10e9c9674e0b2 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\PropertyInfo\Tests\Extractor; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor; use Symfony\Component\PropertyInfo\Tests\Fixtures\Clazz; @@ -48,6 +49,8 @@ */ class PhpStanExtractorTest extends TestCase { + use ExpectDeprecationTrait; + private PhpStanExtractor $extractor; private PhpDocExtractor $phpDocExtractor; @@ -64,6 +67,8 @@ protected function setUp(): void */ public function testExtractLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); } @@ -72,6 +77,8 @@ public function testExtractLegacy($property, ?array $type = null) */ public function testParamTagTypeIsOmittedLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes(PhpStanOmittedParamTagTypeDocBlock::class, 'omittedType')); } @@ -92,6 +99,8 @@ public static function provideLegacyInvalidTypes() */ public function testInvalidLegacy($property) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertNull($this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy', $property)); } @@ -102,6 +111,8 @@ public function testInvalidLegacy($property) */ public function testExtractTypesWithNoPrefixesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $noPrefixExtractor = new PhpStanExtractor([], [], []); $this->assertEquals($type, $noPrefixExtractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); @@ -218,6 +229,8 @@ public static function provideLegacyCollectionTypes() */ public function testExtractTypesWithCustomPrefixesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $customExtractor = new PhpStanExtractor(['add', 'remove'], ['is', 'can']); $this->assertEquals($type, $customExtractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); @@ -321,6 +334,8 @@ public static function provideLegacyDockBlockFallbackTypes() */ public function testDocBlockFallbackLegacy($property, $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback', $property)); } @@ -331,6 +346,8 @@ public function testDocBlockFallbackLegacy($property, $types) */ public function testPropertiesDefinedByTraitsLegacy(string $property, LegacyType $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property)); } @@ -351,6 +368,8 @@ public static function provideLegacyPropertiesDefinedByTraits(): array */ public function testPropertiesStaticTypeLegacy(string $class, string $property, LegacyType $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals([$type], $this->extractor->getTypes($class, $property)); } @@ -369,6 +388,8 @@ public static function provideLegacyPropertiesStaticType(): array */ public function testPropertiesParentTypeLegacy(string $class, string $property, ?array $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes($class, $property)); } @@ -387,6 +408,8 @@ public static function provideLegacyPropertiesParentType(): array */ public function testExtractConstructorTypesLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypesFromConstructor()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypeFromConstructor()" instead.'); + $this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy', $property)); } @@ -397,6 +420,8 @@ public function testExtractConstructorTypesLegacy($property, ?array $type = null */ public function testExtractConstructorTypesReturnNullOnEmptyDocBlockLegacy($property) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypesFromConstructor()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypeFromConstructor()" instead.'); + $this->assertNull($this->extractor->getTypesFromConstructor(ConstructorDummyWithoutDocBlock::class, $property)); } @@ -418,6 +443,8 @@ public static function provideLegacyConstructorTypes() */ public function testExtractorUnionTypesLegacy(string $property, ?array $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DummyUnionType', $property)); } @@ -441,6 +468,8 @@ public static function provideLegacyUnionTypes(): array */ public function testPseudoTypesLegacy($property, array $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\PhpStanPseudoTypesDummy', $property)); } @@ -477,6 +506,8 @@ public static function provideLegacyPseudoTypes(): array */ public function testDummyNamespaceLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals( [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')], $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace', 'dummy') @@ -488,6 +519,8 @@ public function testDummyNamespaceLegacy() */ public function testDummyNamespaceWithPropertyLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $phpStanTypes = $this->extractor->getTypes(\B\Dummy::class, 'property'); $phpDocTypes = $this->phpDocExtractor->getTypes(\B\Dummy::class, 'property'); @@ -502,6 +535,8 @@ public function testDummyNamespaceWithPropertyLegacy() */ public function testExtractorIntRangeTypeLegacy(string $property, ?array $types) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy', $property)); } @@ -521,6 +556,8 @@ public static function provideLegacyIntRangeType(): array */ public function testExtractPhp80TypeLegacy(string $class, $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); } @@ -543,6 +580,8 @@ public static function provideLegacyPhp80Types() */ public function testAllowPrivateAccessLegacy(bool $allowPrivateAccess, array $expectedTypes) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $extractor = new PhpStanExtractor(allowPrivateAccess: $allowPrivateAccess); $this->assertEquals( $expectedTypes, @@ -559,12 +598,16 @@ public static function allowPrivateAccessLegacyProvider(): array } /** + * @group legacy + * * @param list $expectedTypes * * @dataProvider legacyGenericsProvider */ public function testGenericsLegacy(string $property, array $expectedTypes) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor::getType()" instead.'); + $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index 1372d25c785ef..0c501c6956926 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\PropertyInfo\Tests\Extractor; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\PropertyInfo\PropertyReadInfo; use Symfony\Component\PropertyInfo\PropertyWriteInfo; @@ -42,6 +43,8 @@ */ class ReflectionExtractorTest extends TestCase { + use ExpectDeprecationTrait; + private ReflectionExtractor $extractor; protected function setUp(): void @@ -227,6 +230,8 @@ public function testGetPropertiesWithNoPrefixes() */ public function testExtractorsLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property, [])); } @@ -256,6 +261,8 @@ public static function provideLegacyTypes() */ public function testExtractPhp7TypeLegacy(string $class, string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); } @@ -279,6 +286,8 @@ public static function provideLegacyPhp7Types() */ public function testExtractPhp71TypeLegacy($property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php71Dummy', $property, [])); } @@ -300,6 +309,8 @@ public static function provideLegacyPhp71Types() */ public function testExtractPhp80TypeLegacy(string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy', $property, [])); } @@ -324,6 +335,8 @@ public static function provideLegacyPhp80Types() */ public function testExtractPhp81TypeLegacy(string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy', $property, [])); } @@ -347,6 +360,8 @@ public function testReadonlyPropertiesAreNotWriteable() */ public function testExtractPhp82TypeLegacy(string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, [])); } @@ -368,6 +383,8 @@ public static function provideLegacyPhp82Types(): iterable */ public function testExtractWithDefaultValueLegacy($property, $type) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals($type, $this->extractor->getTypes(DefaultValue::class, $property, [])); } @@ -511,6 +528,8 @@ public static function getInitializableProperties(): array */ public function testExtractTypeConstructorLegacy(string $class, string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + /* Check that constructor extractions works by default, and if passed in via context. Check that null is returned if constructor extraction is disabled */ $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); @@ -549,6 +568,8 @@ public function testNullOnPrivateProtectedAccessor() */ public function testTypedPropertiesLegacy() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getType()" instead.'); + $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, Dummy::class)], $this->extractor->getTypes(Php74Dummy::class, 'dummy')); $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_BOOL, true)], $this->extractor->getTypes(Php74Dummy::class, 'nullableBoolProp')); $this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING))], $this->extractor->getTypes(Php74Dummy::class, 'stringCollection')); @@ -687,6 +708,8 @@ public function testGetWriteInfoReadonlyProperties() */ public function testExtractConstructorTypesLegacy(string $property, ?array $type = null) { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypesFromConstructor()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor::getTypeFromConstructor()" instead.'); + $this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy', $property)); } diff --git a/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php index f557f89eae3a1..ad6398ceca82f 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\PropertyInfo\Tests; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor; @@ -25,6 +26,8 @@ */ class PropertyInfoCacheExtractorTest extends AbstractPropertyInfoExtractorTest { + use ExpectDeprecationTrait; + protected function setUp(): void { parent::setUp(); @@ -55,6 +58,8 @@ public function testGetType() */ public function testGetTypes() { + $this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor::getType()" instead.'); + parent::testGetTypes(); parent::testGetTypes(); } diff --git a/src/Symfony/Component/PropertyInfo/Type.php b/src/Symfony/Component/PropertyInfo/Type.php index 98894e1d96c0c..2bed492346370 100644 --- a/src/Symfony/Component/PropertyInfo/Type.php +++ b/src/Symfony/Component/PropertyInfo/Type.php @@ -11,11 +11,15 @@ namespace Symfony\Component\PropertyInfo; +trigger_deprecation('symfony/property-info', '7.3', 'The "%s" class is deprecated. Use "%s" class from "symfony/type-info" instead.', Type::class, \Symfony\Component\TypeInfo\Type::class); + /** * Type value object (immutable). * * @author Kévin Dunglas * + * @deprecated since Symfony 7.3, use "Symfony\Component\TypeInfo\Type" class from "symfony/type-info" instead + * * @final */ class Type diff --git a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php index 6c83da2a92938..4537ab6799574 100644 --- a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php +++ b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php @@ -41,10 +41,14 @@ final class PhpDocTypeHelper /** * Creates a {@see LegacyType} from a PHPDoc type. * + * @deprecated since Symfony 7.3, use "getType" instead + * * @return LegacyType[] */ public function getTypes(DocType $varType): array { + trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); + if ($varType instanceof ConstExpression) { // It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment return []; diff --git a/src/Symfony/Component/PropertyInfo/composer.json b/src/Symfony/Component/PropertyInfo/composer.json index 65f2782ed909c..f8ae018a40b7f 100644 --- a/src/Symfony/Component/PropertyInfo/composer.json +++ b/src/Symfony/Component/PropertyInfo/composer.json @@ -24,6 +24,7 @@ ], "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/string": "^6.4|^7.0", "symfony/type-info": "~7.1.9|^7.2.2" }, From 4d2ccf4ac94c6591835985e27db9a7f7cfa2a8fd Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 22 Mar 2025 18:18:22 +0100 Subject: [PATCH 2/2] Fix md formatting --- UPGRADE-7.3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE-7.3.md b/UPGRADE-7.3.md index 89882edbc5b58..921ce52a4112d 100644 --- a/UPGRADE-7.3.md +++ b/UPGRADE-7.3.md @@ -82,7 +82,7 @@ OptionsResolver ``` PropertyInfo -------- +------------ * Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class from `symfony/type-info` instead * Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead