Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03c53f3

Browse filesBrowse files
committed
bug #59156 [PropertyInfo] [7.1] Fix interface handling in PhpStanTypeHelper (mtarld)
This PR was merged into the 7.1 branch. Discussion ---------- [PropertyInfo] [7.1] Fix interface handling in PhpStanTypeHelper | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Upmerge #59012 up to 7.1 Commits ------- 65b370e [PropertyInfo] Upmerge #59012
2 parents b210a7d + 65b370e commit 03c53f3
Copy full SHA for 03c53f3

File tree

1 file changed

+83
-59
lines changed
Filter options

1 file changed

+83
-59
lines changed

‎src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php
+83-59Lines changed: 83 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1616
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
17-
use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy;
1817
use Symfony\Component\PropertyInfo\Tests\Fixtures\Clazz;
18+
use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy;
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithoutDocBlock;
2020
use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
2121
use Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback;
2222
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
2323
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
24+
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric;
2425
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyNamespace;
2526
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyPropertyAndGetterWithDifferentTypes;
2627
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyUnionType;
28+
use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace;
2729
use Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy;
2830
use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy;
29-
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyGeneric;
30-
use Symfony\Component\PropertyInfo\Tests\Fixtures\IFace;
3131
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
3232
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
3333
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy;
@@ -555,6 +555,77 @@ public static function allowPrivateAccessLegacyProvider(): array
555555
];
556556
}
557557

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+
558629
/**
559630
* @dataProvider typesProvider
560631
*/
@@ -972,86 +1043,39 @@ public static function allowPrivateAccessProvider(): array
9721043
public function testGenericInterface()
9731044
{
9741045
$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'),
9851048
);
9861049
}
9871050

9881051
/**
989-
* @param list<Type> $expectedTypes
9901052
* @dataProvider genericsProvider
9911053
*/
992-
public function testGenericsLegacy(string $property, array $expectedTypes)
1054+
public function testGenerics(string $property, Type $expectedType)
9931055
{
994-
$this->assertEquals($expectedTypes, $this->extractor->getTypes(DummyGeneric::class, $property));
1056+
$this->assertEquals($expectedType, $this->extractor->getType(DummyGeneric::class, $property));
9951057
}
9961058

9971059
/**
998-
* @return iterable<array{0: string, 1: list<Type>}>
1060+
* @return iterable<array{0: string, 1: Type}>
9991061
*/
10001062
public static function genericsProvider(): iterable
10011063
{
10021064
yield [
10031065
'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)),
10141067
];
10151068
yield [
10161069
'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))),
10281071
];
10291072
yield [
10301073
'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)),
10411075
];
10421076
yield [
10431077
'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))),
10551079
];
10561080
}
10571081
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.