Skip to content

Commit 1bd42d0

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Fix tests that use deprecated callable syntax Make sure nested composite types do not crash ReflectionExtractor
2 parents 38b2770 + aabc22b commit 1bd42d0

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,25 @@ public function testDescribeCallable($callable, $expectedDescription)
206206
$this->assertDescription($expectedDescription, $callable);
207207
}
208208

209-
public function getDescribeCallableTestData()
209+
public function getDescribeCallableTestData(): array
210210
{
211211
return $this->getDescriptionTestData(ObjectsProvider::getCallables());
212212
}
213213

214+
/**
215+
* @group legacy
216+
* @dataProvider getDescribeDeprecatedCallableTestData
217+
*/
218+
public function testDescribeDeprecatedCallable($callable, $expectedDescription)
219+
{
220+
$this->assertDescription($expectedDescription, $callable);
221+
}
222+
223+
public function getDescribeDeprecatedCallableTestData(): array
224+
{
225+
return $this->getDescriptionTestData(ObjectsProvider::getDeprecatedCallables());
226+
}
227+
214228
/** @dataProvider getClassDescriptionTestData */
215229
public function testGetClassDescription($object, $expectedDescription)
216230
{

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,25 @@ public static function getEventDispatchers()
245245
return ['event_dispatcher_1' => $eventDispatcher];
246246
}
247247

248-
public static function getCallables()
248+
public static function getCallables(): array
249249
{
250250
return [
251251
'callable_1' => 'array_key_exists',
252252
'callable_2' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'],
253253
'callable_3' => [new CallableClass(), 'method'],
254254
'callable_4' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass::staticMethod',
255-
'callable_5' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'],
256255
'callable_6' => function () { return 'Closure'; },
257256
'callable_7' => new CallableClass(),
258257
'callable_from_callable' => (new CallableClass())(...),
259258
];
260259
}
260+
261+
public static function getDeprecatedCallables(): array
262+
{
263+
return [
264+
'callable_5' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'],
265+
];
266+
}
261267
}
262268

263269
class CallableClass

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ private function extractFromReflectionType(\ReflectionType $reflectionType, \Ref
537537
$nullable = $reflectionType->allowsNull();
538538

539539
foreach (($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) ? $reflectionType->getTypes() : [$reflectionType] as $type) {
540+
if (!$type instanceof \ReflectionNamedType) {
541+
// Nested composite types are not supported yet.
542+
return [];
543+
}
544+
540545
$phpTypeOrClass = $type->getName();
541546
if ('null' === $phpTypeOrClass || 'mixed' === $phpTypeOrClass || 'never' === $phpTypeOrClass) {
542547
continue;

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ public function testExtractPhp82Type($property, array $type = null)
309309
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, []));
310310
}
311311

312-
public function php82TypesProvider()
312+
public function php82TypesProvider(): iterable
313313
{
314314
yield ['nil', null];
315315
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
316316
yield ['true', [new Type(Type::BUILTIN_TYPE_TRUE)]];
317+
318+
// Nesting intersection and union types is not supported yet,
319+
// but we should make sure this kind of composite types does not crash the extractor.
320+
yield ['someCollection', null];
317321
}
318322

319323
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ class Php82Dummy
1818
public false $false = false;
1919

2020
public true $true = true;
21+
22+
public (\Traversable&\Countable)|null $someCollection = null;
2123
}

0 commit comments

Comments
 (0)