Skip to content

Commit 87ba5d8

Browse files
bug symfony#61607 [Config] Fix ReflectionClassResource hash validation (HypeMC)
This PR was merged into the 7.3 branch. Discussion ---------- [Config] Fix `ReflectionClassResource` hash validation | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT It looks like symfony#57948 broke hash validation. The problem is that `$excludedVendors` is now used to generate the hash but is not serialized. After unserialization, the property is empty, so the generated hash never matches the dumped one. Commits ------- cec2f00 [Config] Fix `ReflectionClassResource` hash validation
2 parents acb2027 + cec2f00 commit 87ba5d8

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __sleep(): array
6969
$this->loadFiles($this->classReflector);
7070
}
7171

72-
return ['files', 'className', 'hash'];
72+
return ['files', 'className', 'excludedVendors', 'hash'];
7373
}
7474

7575
private function loadFiles(\ReflectionClass $class): void
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Config\Tests\Fixtures\FakeVendor;
13+
14+
abstract class Base
15+
{
16+
public $baseFoo;
17+
18+
protected $baseBar;
19+
20+
public function baseBaz()
21+
{
22+
}
23+
24+
public function baseQux()
25+
{
26+
}
27+
}

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Resource\ReflectionClassResource;
16+
use Symfony\Component\Config\Tests\Fixtures\FakeVendor\Base;
1617
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1718
use Symfony\Contracts\Service\ServiceSubscriberInterface;
1819

@@ -71,7 +72,7 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
7172

7273
$code = <<<'EOPHP'
7374
/* 0*/
74-
/* 1*/ class %s extends ErrorException
75+
/* 1*/ class %s extends %s
7576
/* 2*/ {
7677
/* 3*/ const FOO = 123;
7778
/* 4*/
@@ -91,22 +92,27 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
9192
/*18*/ }
9293
EOPHP;
9394

94-
static $expectedSignature, $generateSignature;
95+
static $expectedSignature, $signatureGenerator;
9596

9697
if (null === $expectedSignature) {
97-
eval(\sprintf($code, $class = 'Foo'.(string) $resourceClassNameSuffix));
98+
eval(\sprintf($code, $class = 'Foo'.(string) $resourceClassNameSuffix, Base::class));
99+
98100
$r = new \ReflectionClass(ReflectionClassResource::class);
99101
$generateSignature = $r->getMethod('generateSignature');
100-
$generateSignature = $generateSignature->getClosure($r->newInstanceWithoutConstructor());
101-
$expectedSignature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
102+
103+
$res = new ReflectionClassResource(new \ReflectionClass($class), [\dirname(__DIR__).'/Fixtures/FakeVendor']);
104+
$signatureGenerator = $generateSignature->getClosure($res);
105+
$expectedSignature = implode("\n", iterator_to_array($signatureGenerator(new \ReflectionClass($class))));
106+
107+
$signatureGenerator = $generateSignature->getClosure(unserialize(serialize($res)));
102108
}
103109

104110
$code = explode("\n", $code);
105111
if (null !== $changedCode) {
106112
$code[$changedLine] = $changedCode;
107113
}
108-
eval(\sprintf(implode("\n", $code), $class = 'Bar'.(string) $resourceClassNameSuffix));
109-
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
114+
eval(\sprintf(implode("\n", $code), $class = 'Bar'.(string) $resourceClassNameSuffix, Base::class));
115+
$signature = implode("\n", iterator_to_array($signatureGenerator(new \ReflectionClass($class))));
110116

111117
if ($changeExpected) {
112118
$this->assertNotSame($expectedSignature, $signature);

0 commit comments

Comments
 (0)