|
14 | 14 | use PHPUnit\Framework\TestCase; |
15 | 15 | use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; |
16 | 16 | use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor; |
17 | | -use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy; |
18 | 17 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Clazz; |
| 18 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy; |
19 | 19 | use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithoutDocBlock; |
20 | 20 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue; |
21 | 21 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback; |
22 | 22 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; |
23 | 23 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection; |
| 24 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric; |
24 | 25 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace; |
25 | 26 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyPropertyAndGetterWithDifferentTypes; |
26 | 27 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyUnionType; |
| 28 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace; |
27 | 29 | use Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy; |
28 | 30 | use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy; |
29 | | -use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric; |
30 | | -use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace; |
31 | 31 | use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy; |
32 | 32 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy; |
33 | 33 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy; |
@@ -555,6 +555,77 @@ public static function allowPrivateAccessLegacyProvider(): array |
555 | 555 | ]; |
556 | 556 | } |
557 | 557 |
|
| 558 | + /** |
| 559 | + * @param list<LegacyType> $expectedTypes |
| 560 | + * |
| 561 | + * @dataProvider legacyGenericsProvider |
| 562 | + */ |
| 563 | + public function testGenericsLegacy(string $property, array $expectedTypes) |
| 564 | + { |
| 565 | + $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); |
| 566 | + } |
| 567 | + |
| 568 | + /** |
| 569 | + * @return iterable<array{0: string, 1: list<LegacyType>}> |
| 570 | + */ |
| 571 | + public static function legacyGenericsProvider(): iterable |
| 572 | + { |
| 573 | + yield [ |
| 574 | + 'basicClass', |
| 575 | + [ |
| 576 | + new LegacyType( |
| 577 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 578 | + class: Clazz::class, |
| 579 | + collectionValueType: new LegacyType( |
| 580 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 581 | + class: Dummy::class, |
| 582 | + ) |
| 583 | + ), |
| 584 | + ], |
| 585 | + ]; |
| 586 | + yield [ |
| 587 | + 'nullableClass', |
| 588 | + [ |
| 589 | + new LegacyType( |
| 590 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 591 | + class: Clazz::class, |
| 592 | + nullable: true, |
| 593 | + collectionValueType: new LegacyType( |
| 594 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 595 | + class: Dummy::class, |
| 596 | + ) |
| 597 | + ), |
| 598 | + ], |
| 599 | + ]; |
| 600 | + yield [ |
| 601 | + 'basicInterface', |
| 602 | + [ |
| 603 | + new LegacyType( |
| 604 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 605 | + class: IFace::class, |
| 606 | + collectionValueType: new LegacyType( |
| 607 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 608 | + class: Dummy::class, |
| 609 | + ) |
| 610 | + ), |
| 611 | + ], |
| 612 | + ]; |
| 613 | + yield [ |
| 614 | + 'nullableInterface', |
| 615 | + [ |
| 616 | + new LegacyType( |
| 617 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 618 | + class: IFace::class, |
| 619 | + nullable: true, |
| 620 | + collectionValueType: new LegacyType( |
| 621 | + builtinType: LegacyType::BUILTIN_TYPE_OBJECT, |
| 622 | + class: Dummy::class, |
| 623 | + ) |
| 624 | + ), |
| 625 | + ], |
| 626 | + ]; |
| 627 | + } |
| 628 | + |
558 | 629 | /** |
559 | 630 | * @dataProvider typesProvider |
560 | 631 | */ |
@@ -972,86 +1043,39 @@ public static function allowPrivateAccessProvider(): array |
972 | 1043 | public function testGenericInterface() |
973 | 1044 | { |
974 | 1045 | $this->assertEquals( |
975 | | - [ |
976 | | - new Type( |
977 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
978 | | - class: \BackedEnum::class, |
979 | | - collectionValueType: new Type( |
980 | | - builtinType: Type::BUILTIN_TYPE_STRING, |
981 | | - ) |
982 | | - ), |
983 | | - ], |
984 | | - $this->extractor->getTypes(Dummy::class, 'genericInterface') |
| 1046 | + Type::generic(Type::object(\BackedEnum::class), Type::string()), |
| 1047 | + $this->extractor->getType(Dummy::class, 'genericInterface'), |
985 | 1048 | ); |
986 | 1049 | } |
987 | 1050 |
|
988 | 1051 | /** |
989 | | - * @param list<Type> $expectedTypes |
990 | 1052 | * @dataProvider genericsProvider |
991 | 1053 | */ |
992 | | - public function testGenericsLegacy(string $property, array $expectedTypes) |
| 1054 | + public function testGenerics(string $property, Type $expectedType) |
993 | 1055 | { |
994 | | - $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); |
| 1056 | + $this->assertEquals($expectedType, $this->extractor->getType(DummyGeneric::class, $property)); |
995 | 1057 | } |
996 | 1058 |
|
997 | 1059 | /** |
998 | | - * @return iterable<array{0: string, 1: list<Type>}> |
| 1060 | + * @return iterable<array{0: string, 1: Type}> |
999 | 1061 | */ |
1000 | 1062 | public static function genericsProvider(): iterable |
1001 | 1063 | { |
1002 | 1064 | yield [ |
1003 | 1065 | 'basicClass', |
1004 | | - [ |
1005 | | - new Type( |
1006 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1007 | | - class: Clazz::class, |
1008 | | - collectionValueType: new Type( |
1009 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1010 | | - class: Dummy::class, |
1011 | | - ) |
1012 | | - ), |
1013 | | - ], |
| 1066 | + Type::generic(Type::object(Clazz::class), Type::object(Dummy::class)), |
1014 | 1067 | ]; |
1015 | 1068 | yield [ |
1016 | 1069 | 'nullableClass', |
1017 | | - [ |
1018 | | - new Type( |
1019 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1020 | | - class: Clazz::class, |
1021 | | - nullable: true, |
1022 | | - collectionValueType: new Type( |
1023 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1024 | | - class: Dummy::class, |
1025 | | - ) |
1026 | | - ), |
1027 | | - ], |
| 1070 | + Type::nullable(Type::generic(Type::object(Clazz::class), Type::object(Dummy::class))), |
1028 | 1071 | ]; |
1029 | 1072 | yield [ |
1030 | 1073 | 'basicInterface', |
1031 | | - [ |
1032 | | - new Type( |
1033 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1034 | | - class: IFace::class, |
1035 | | - collectionValueType: new Type( |
1036 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1037 | | - class: Dummy::class, |
1038 | | - ) |
1039 | | - ), |
1040 | | - ], |
| 1074 | + Type::generic(Type::object(IFace::class), Type::object(Dummy::class)), |
1041 | 1075 | ]; |
1042 | 1076 | yield [ |
1043 | 1077 | 'nullableInterface', |
1044 | | - [ |
1045 | | - new Type( |
1046 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1047 | | - class: IFace::class, |
1048 | | - nullable: true, |
1049 | | - collectionValueType: new Type( |
1050 | | - builtinType: Type::BUILTIN_TYPE_OBJECT, |
1051 | | - class: Dummy::class, |
1052 | | - ) |
1053 | | - ), |
1054 | | - ], |
| 1078 | + Type::nullable(Type::generic(Type::object(IFace::class), Type::object(Dummy::class))), |
1055 | 1079 | ]; |
1056 | 1080 | } |
1057 | 1081 | } |
|
0 commit comments