From 65b370e63ea15607c495a538ebc266df7fd59adf Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 10 Dec 2024 12:14:43 +0100 Subject: [PATCH] [PropertyInfo] Upmerge #59012 --- .../Tests/Extractor/PhpStanExtractorTest.php | 142 ++++++++++-------- 1 file changed, 83 insertions(+), 59 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 6543a0b5a2963..ba378812e3677 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -14,20 +14,20 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor; -use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Clazz; +use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithoutDocBlock; use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue; use Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback; use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection; +use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyPropertyAndGetterWithDifferentTypes; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyUnionType; +use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace; use Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy; -use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric; -use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace; use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy; @@ -555,6 +555,77 @@ public static function allowPrivateAccessLegacyProvider(): array ]; } + /** + * @param list $expectedTypes + * + * @dataProvider legacyGenericsProvider + */ + public function testGenericsLegacy(string $property, array $expectedTypes) + { + $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); + } + + /** + * @return iterable}> + */ + public static function legacyGenericsProvider(): iterable + { + yield [ + 'basicClass', + [ + new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Clazz::class, + collectionValueType: new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Dummy::class, + ) + ), + ], + ]; + yield [ + 'nullableClass', + [ + new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Clazz::class, + nullable: true, + collectionValueType: new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Dummy::class, + ) + ), + ], + ]; + yield [ + 'basicInterface', + [ + new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: IFace::class, + collectionValueType: new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Dummy::class, + ) + ), + ], + ]; + yield [ + 'nullableInterface', + [ + new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: IFace::class, + nullable: true, + collectionValueType: new LegacyType( + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, + class: Dummy::class, + ) + ), + ], + ]; + } + /** * @dataProvider typesProvider */ @@ -972,86 +1043,39 @@ public static function allowPrivateAccessProvider(): array public function testGenericInterface() { $this->assertEquals( - [ - new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: \BackedEnum::class, - collectionValueType: new Type( - builtinType: Type::BUILTIN_TYPE_STRING, - ) - ), - ], - $this->extractor->getTypes(Dummy::class, 'genericInterface') + Type::generic(Type::object(\BackedEnum::class), Type::string()), + $this->extractor->getType(Dummy::class, 'genericInterface'), ); } /** - * @param list $expectedTypes * @dataProvider genericsProvider */ - public function testGenericsLegacy(string $property, array $expectedTypes) + public function testGenerics(string $property, Type $expectedType) { - $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); + $this->assertEquals($expectedType, $this->extractor->getType(DummyGeneric::class, $property)); } /** - * @return iterable}> + * @return iterable */ public static function genericsProvider(): iterable { yield [ 'basicClass', - [ - new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Clazz::class, - collectionValueType: new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Dummy::class, - ) - ), - ], + Type::generic(Type::object(Clazz::class), Type::object(Dummy::class)), ]; yield [ 'nullableClass', - [ - new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Clazz::class, - nullable: true, - collectionValueType: new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Dummy::class, - ) - ), - ], + Type::nullable(Type::generic(Type::object(Clazz::class), Type::object(Dummy::class))), ]; yield [ 'basicInterface', - [ - new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: IFace::class, - collectionValueType: new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Dummy::class, - ) - ), - ], + Type::generic(Type::object(IFace::class), Type::object(Dummy::class)), ]; yield [ 'nullableInterface', - [ - new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: IFace::class, - nullable: true, - collectionValueType: new Type( - builtinType: Type::BUILTIN_TYPE_OBJECT, - class: Dummy::class, - ) - ), - ], + Type::nullable(Type::generic(Type::object(IFace::class), Type::object(Dummy::class))), ]; } }