Skip to content

Commit 1c9d326

Browse files
Merge branch '7.3' into 7.4
* 7.3: [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 cc4f0a0 + dbb6fdc commit 1c9d326

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed

Extractor/PhpDocExtractor.php

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

341341
switch (true) {
342-
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($class, $property):
343-
$data = [$docBlock, self::MUTATOR, null, $reflectionProperty->getDeclaringClass()->getName()];
342+
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($reflectionProperty->class, $property):
343+
$data = [$docBlock, self::MUTATOR, null, $reflectionProperty->class];
344344
break;
345345

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

Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyCollection;
2626
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildOfParentUsingTrait;
2727
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildOfParentWithPromotedSelfDocBlock;
28+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithConstructorOverride;
29+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithoutConstructorOverride;
2830
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ChildWithSelfDocBlock;
2931
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingNestedTrait;
3032
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ClassUsingTraitWithSelfDocBlock;
3133
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentUsingTraitWithSelfDocBlock;
34+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedPropertyDocBlock;
3235
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithPromotedSelfDocBlock;
3336
use Symfony\Component\PropertyInfo\Tests\Fixtures\Extractor\ParentWithSelfDocBlock;
3437
use Symfony\Component\PropertyInfo\Tests\Fixtures\InvalidDummy;
@@ -827,6 +830,16 @@ public function testPropertiesParentType(string $class, string $property, ?Type
827830
$this->assertEquals($type, $this->extractor->getType($class, $property));
828831
}
829832

833+
/**
834+
* @return iterable<array{0: class-string, 1: string, 2: ?Type}>
835+
*/
836+
public static function propertiesParentTypeProvider(): iterable
837+
{
838+
yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')];
839+
yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)];
840+
}
841+
842+
830843
/**
831844
* @param class-string $class
832845
* @param class-string $expectedResolvedClass
@@ -859,13 +872,49 @@ public static function selfDocBlockResolutionProvider(): iterable
859872
yield 'promoted property from child' => [ChildOfParentWithPromotedSelfDocBlock::class, 'promotedSelfProp', ParentWithPromotedSelfDocBlock::class];
860873
}
861874

875+
#[IgnoreDeprecations]
876+
#[Group('legacy')]
877+
#[DataProvider('inheritedPromotedPropertyWithConstructorOverrideProviderLegacy')]
878+
public function testInheritedPromotedPropertyWithConstructorOverrideLegacy(string $class, string $property, ?array $expectedTypes)
879+
{
880+
$this->assertEquals($expectedTypes, $this->extractor->getTypes($class, $property));
881+
}
882+
862883
/**
863-
* @return iterable<array{0: class-string, 1: string, 2: ?Type}>
884+
* @return iterable<string, array{0: class-string, 1: string, 2: ?array}>
864885
*/
865-
public static function propertiesParentTypeProvider(): iterable
886+
public static function inheritedPromotedPropertyWithConstructorOverrideProviderLegacy(): iterable
866887
{
867-
yield [ParentDummy::class, 'parentAnnotationNoParent', Type::object('parent')];
868-
yield [Dummy::class, 'parentAnnotation', Type::object(ParentDummy::class)];
888+
$expectedItemsType = [new LegacyType(
889+
LegacyType::BUILTIN_TYPE_ARRAY,
890+
false,
891+
null,
892+
true,
893+
new LegacyType(LegacyType::BUILTIN_TYPE_STRING),
894+
new LegacyType(LegacyType::BUILTIN_TYPE_INT)
895+
)];
896+
897+
yield 'parent promoted property' => [ParentWithPromotedPropertyDocBlock::class, 'items', $expectedItemsType,];
898+
yield 'child without constructor override' => [ChildWithoutConstructorOverride::class, 'items', $expectedItemsType];
899+
yield 'child with constructor override' => [ChildWithConstructorOverride::class, 'items', $expectedItemsType];
900+
}
901+
902+
#[DataProvider('inheritedPromotedPropertyWithConstructorOverrideProvider')]
903+
public function testInheritedPromotedPropertyWithConstructorOverride(string $class, string $property, ?Type $expectedType)
904+
{
905+
$this->assertEquals($expectedType, $this->extractor->getType($class, $property));
906+
}
907+
908+
/**
909+
* @return iterable<string, array{0: class-string, 1: string, 2: ?Type}>
910+
*/
911+
public static function inheritedPromotedPropertyWithConstructorOverrideProvider(): iterable
912+
{
913+
$expectedItemsType = Type::dict(Type::int(), Type::string());
914+
915+
yield 'parent promoted property' => [ParentWithPromotedPropertyDocBlock::class, 'items', $expectedItemsType];
916+
yield 'child without constructor override' => [ChildWithoutConstructorOverride::class, 'items', $expectedItemsType];
917+
yield 'child with constructor override' => [ChildWithConstructorOverride::class, 'items', $expectedItemsType];
869918
}
870919

871920
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)