|
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\Clazz; |
17 | 18 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Cons
8000
tructorDummyWithoutDocBlock;
|
18 | 19 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
|
19 | 20 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
|
20 | 21 | use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
|
| 22 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric; |
| 23 | +use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace; |
21 | 24 | use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
|
22 | 25 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
|
23 | 26 | use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy;
|
@@ -482,7 +485,88 @@ public static function php80TypesProvider()
|
482 | 485 |
|
483 | 486 | public function testGenericInterface()
|
484 | 487 | {
|
485 |
| - $this->assertNull($this->extractor->getTypes(Dummy::class, 'genericInterface')); |
| 488 | + $this->assertEquals( |
| 489 | + [ |
| 490 | + new Type( |
| 491 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 492 | + class: \BackedEnum::class, |
| 493 | + collectionValueType: new Type( |
| 494 | + builtinType: Type::BUILTIN_TYPE_STRING, |
| 495 | + ) |
| 496 | + ), |
| 497 | + ], |
| 498 | + $this->extractor->getTypes(Dummy::class, 'genericInterface') |
| 499 | + ); |
| 500 | + } |
| 501 | + |
| 502 | + /** |
| 503 | + * @param list<Type> $expectedTypes |
| 504 | + * @dataProvider genericsProvider |
| 505 | + */ |
| 506 | + public function testGenericsLegacy(string $property, array $expectedTypes) |
| 507 | + { |
| 508 | + $this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property)); |
| 509 | + } |
| 510 | + |
| 511 | + /** |
| 512 | + * @return iterable<array{0: string, 1: list<Type>}> |
| 513 | + */ |
| 514 | + public static function genericsProvider(): iterable |
| 515 | + { |
| 516 | + yield [ |
| 517 | + 'basicClass', |
| 518 | + [ |
| 519 | + new Type( |
| 520 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 521 | + class: Clazz::class, |
| 522 | + collectionValueType: new Type( |
| 523 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 524 | + class: Dummy::class, |
| 525 | + ) |
| 526 | + ), |
| 527 | + ], |
| 528 | + ]; |
| 529 | + yield [ |
| 530 | + 'nullableClass', |
| 531 | + [ |
| 532 | + new Type( |
| 533 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 534 | + class: Clazz::class, |
| 535 | + nullable: true, |
| 536 | + collectionValueType: new Type( |
| 537 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 538 | + class: Dummy::class, |
| 539 | + ) |
| 540 | + ), |
| 541 | + ], |
| 542 | + ]; |
| 543 | + yield [ |
| 544 | + 'basicInterface', |
| 545 | + [ |
| 546 | + new Type( |
| 547 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 548 | + class: IFace::class, |
| 549 | + collectionValueType: new Type( |
| 550 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 551 | + class: Dummy::class, |
| 552 | + ) |
| 553 | + ), |
| 554 | + ], |
| 555 | + ]; |
| 556 | + yield [ |
| 557 | + 'nullableInterface', |
| 558 | + [ |
| 559 | + new Type( |
| 560 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 561 | + class: IFace::class, |
| 562 | + nullable: true, |
| 563 | + collectionValueType: new Type( |
| 564 | + builtinType: Type::BUILTIN_TYPE_OBJECT, |
| 565 | + class: Dummy::class, |
| 566 | + ) |
| 567 | + ), |
| 568 | + ], |
| 569 | + ]; |
486 | 570 | }
|
487 | 571 | }
|
488 | 572 |
|
|
0 commit comments