|
23 | 23 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection; |
24 | 24 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildOfParentUsingTrait; |
25 | 25 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildOfParentWithPromotedSelfDocBlock; |
| 26 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithConstructorOverride; |
| 27 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithoutConstructorOverride; |
26 | 28 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithSelfDocBlock; |
27 | 29 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingNestedTrait; |
28 | 30 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingTraitWithSelfDocBlock; |
29 | 31 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentUsingTraitWithSelfDocBlock; |
| 32 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedPropertyDocBlock; |
30 | 33 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedSelfDocBlock; |
31 | 34 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithSelfDocBlock; |
32 | 35 | use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy; |
@@ -880,6 +883,16 @@ public function testPropertiesParentType(string $class, string $property, ?Type |
880 | 883 | $this->assertEquals($type, $this->extractor->getType($class, $property)); |
881 | 884 | } |
882 | 885 |
|
| 886 | + /** |
| 887 | + * @return iterable<array{0: class-string, 1: string, 2: ?Type}> |
| 888 | + */ |
| 889 | + public static function propertiesParentTypeProvider(): iterable |
| 890 | + { |
| 891 | + yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')]; |
| 892 | + yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)]; |
| 893 | + } |
| 894 | + |
| 895 | + |
883 | 896 | /** |
884 | 897 | * @param class-string $class |
885 | 898 | * @param class-string $expectedResolvedClass |
@@ -914,12 +927,52 @@ public static function selfDocBlockResolutionProvider(): iterable |
914 | 927 | } |
915 | 928 |
|
916 | 929 | /** |
917 | | - * @return iterable<array{0: class-string, 1: string, 2: ?Type}> |
| 930 | + * @dataProvider inheritedPromotedPropertyWithConstructorOverrideProviderLegacy |
| 931 | + * |
| 932 | + * @group legacy |
918 | 933 | */ |
919 | | - public static function propertiesParentTypeProvider(): iterable |
| 934 | + public function testInheritedPromotedPropertyWithConstructorOverrideLegacy(string $class, string $property, ?array $expectedTypes) |
920 | 935 | { |
921 | | - yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')]; |
922 | | - yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)]; |
| 936 | + $this->assertEquals($expectedTypes, $this->extractor->getTypes($class, $property)); |
| 937 | + } |
| 938 | + |
| 939 | + /** |
| 940 | + * @return iterable<string, array{0: class-string, 1: string, 2: ?array}> |
| 941 | + */ |
| 942 | + public static function inheritedPromotedPropertyWithConstructorOverrideProviderLegacy(): iterable |
| 943 | + { |
| 944 | + $expectedItemsType = [new LegacyType( |
| 945 | + LegacyType::BUILTIN_TYPE_ARRAY, |
| 946 | + false, |
| 947 | + null, |
| 948 | + true, |
| 949 | + new LegacyType(LegacyType::BUILTIN_TYPE_STRING), |
| 950 | + new LegacyType(LegacyType::BUILTIN_TYPE_INT) |
| 951 | + )]; |
| 952 | + |
| 953 | + yield 'parent promoted property' => [ParentWithPromotedPropertyDocBlock::class, 'items', $expectedItemsType,]; |
| 954 | + yield 'child without constructor override' => [ChildWithoutConstructorOverride::class, 'items', $expectedItemsType]; |
| 955 | + yield 'child with constructor override' => [ChildWithConstructorOverride::class, 'items', $expectedItemsType]; |
| 956 | + } |
| 957 | + |
| 958 | + /** |
| 959 | + * @dataProvider inheritedPromotedPropertyWithConstructorOverrideProvider |
| 960 | + */ |
| 961 | + public function testInheritedPromotedPropertyWithConstructorOverride(string $class, string $property, ?Type $expectedType) |
| 962 | + { |
| 963 | + $this->assertEquals($expectedType, $this->extractor->getType($class, $property)); |
| 964 | + } |
| 965 | + |
| 966 | + /** |
| 967 | + * @return iterable<string, array{0: class-string, 1: string, 2: ?Type}> |
| 968 | + */ |
| 969 | + public static function inheritedPromotedPropertyWithConstructorOverrideProvider(): iterable |
| 970 | + { |
| 971 | + $expectedItemsType = Type::dict(Type::int(), Type::string()); |
| 972 | + |
| 973 | + yield 'parent promoted property' => [ParentWithPromotedPropertyDocBlock::class, 'items', $expectedItemsType]; |
| 974 | + yield 'child without constructor override' => [ChildWithoutConstructorOverride::class, 'items', $expectedItemsType]; |
| 975 | + yield 'child with constructor override' => [ChildWithConstructorOverride::class, 'items', $expectedItemsType]; |
923 | 976 | } |
924 | 977 |
|
925 | 978 | public function testUnknownPseudoType() |
|
0 commit comments