Skip to content

Commit 9d98722

Browse files
Merge branch '7.4' into 8.0
* 7.4: [DependencyInjection] Fix lazy proxy type resolution for decorated services [HttpClient] Fix dealing with truncated streams after headers arrived with CurlHttpClient [PropertyInfo] Fix DocBlock resolution for inherited promoted properties [HttpFoundation] Fix PdoSessionHandler charset-collation mismatch with the Doctrine DBAL on MySQL [HttpClient] Fix dealing with multiple levels of AsyncResponse decoration [Messenger] Only send UNLISTEN query if we are actively listening [RateLimiter] Persist state when consuming negative tokens
2 parents 9f5cf0b + 1c9d326 commit 9d98722

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

Extractor/PhpDocExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ private function findDocBlock(string $class, string $property): array
249249
$ucFirstProperty = ucfirst($property);
250250

251251
switch (true) {
252-
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($class, $property):
253-
$data = [$docBlock, self::MUTATOR, null, $reflectionProperty->getDeclaringClass()->getName()];
252+
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($reflectionProperty->class, $property):
253+
$data = [$docBlock, self::MUTATOR, null, $reflectionProperty->class];
254254
break;
255255

256256
case [$docBlock, $declaringClass] = $this->getDocBlockFromProperty($class, $property):

Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
2424
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildOfParentUsingTrait;
2525
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;
2628
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithSelfDocBlock;
2729
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingNestedTrait;
2830
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingTraitWithSelfDocBlock;
2931
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentUsingTraitWithSelfDocBlock;
32+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedPropertyDocBlock;
3033
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedSelfDocBlock;
3134
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithSelfDocBlock;
3235
use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy;
@@ -327,6 +330,16 @@ public function testPropertiesParentType(string $class, string $property, ?Type
327330
$this->assertEquals($type, $this->extractor->getType($class, $property));
328331
}
329332

333+
/**
334+
* @return iterable<array{0: class-string, 1: string, 2: ?Type}>
335+
*/
336+
public static function propertiesParentTypeProvider(): iterable
337+
{
338+
yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')];
339+
yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)];
340+
}
341+
342+
330343
/**
331344
* @param class-string $class
332345
* @param class-string $expectedResolvedClass
@@ -359,13 +372,22 @@ public static function selfDocBlockResolutionProvider(): iterable
359372
yield 'promoted property from child' => [ChildOfParentWithPromotedSelfDocBlock::class, 'promotedSelfProp', ParentWithPromotedSelfDocBlock::class];
360373
}
361374

375+
#[DataProvider('inheritedPromotedPropertyWithConstructorOverrideProvider')]
376+
public function testInheritedPromotedPropertyWithConstructorOverride(string $class, string $property, ?Type $expectedType)
377+
{
378+
$this->assertEquals($expectedType, $this->extractor->getType($class, $property));
379+
}
380+
362381
/**
363-
* @return iterable<array{0: class-string, 1: string, 2: ?Type}>
382+
* @return iterable<string, array{0: class-string, 1: string, 2: ?Type}>
364383
*/
365-
public static function propertiesParentTypeProvider(): iterable
384+
public static function inheritedPromotedPropertyWithConstructorOverrideProvider(): iterable
366385
{
367-
yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')];
368-
yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)];
386+
$expectedItemsType = Type::dict(Type::int(), Type::string());
387+
388+
yield 'parent promoted property' => [ParentWithPromotedPropertyDocBlock::class, 'items', $expectedItemsType];
389+
yield 'child without constructor override' => [ChildWithoutConstructorOverride::class, 'items', $expectedItemsType];
390+
yield 'child with constructor override' => [ChildWithConstructorOverride::class, 'items', $expectedItemsType];
369391
}
370392

371393
public function testUnknownPseudoType()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor;
13+
14+
class ParentWithPromotedPropertyDocBlock
15+
{
16+
/**
17+
* @param array<string, int> $items
18+
*/
19+
public function __construct(
20+
public $items = [],
21+
) {
22+
}
23+
}
24+
25+
class ChildWithoutConstructorOverride extends ParentWithPromotedPropertyDocBlock
26+
{
27+
}
28+
29+
class ChildWithConstructorOverride extends ParentWithPromotedPropertyDocBlock
30+
{
31+
public function __construct(
32+
public $extraProp = null,
33+
) {
34+
parent::__construct();
35+
}
36+
}

0 commit comments

Comments
 (0)