Skip to content

Commit

Permalink
[VarDumper] Fix test suite with PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Mar 12, 2024
1 parent 2e9c2b1 commit a078ef2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
10 changes: 8 additions & 2 deletions Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $

public static function castAttribute(\ReflectionAttribute $c, array $a, Stub $stub, bool $isNested)
{
self::addMap($a, $c, [
$map = [
'name' => 'getName',
'arguments' => 'getArguments',
]);
];

if (\PHP_VERSION_ID >= 80400) {
unset($map['name']);
}

self::addMap($a, $c, $map);

return $a;
}
Expand Down
27 changes: 16 additions & 11 deletions Tests/Caster/ReflectionCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,14 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
public function testReflectionClassWithAttribute()
{
$var = new \ReflectionClass(LotsOfAttributes::class);
$dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name';

$this->assertDumpMatchesFormat(<<< 'EOTXT'
$this->assertDumpMatchesFormat(<<<EOTXT
ReflectionClass {
+name: "Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes"
%A attributes: array:1 [
0 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
arguments: []
}
]
Expand All @@ -621,14 +622,15 @@ public function testReflectionClassWithAttribute()
public function testReflectionMethodWithAttribute()
{
$var = new \ReflectionMethod(LotsOfAttributes::class, 'someMethod');
$dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name';

$this->assertDumpMatchesFormat(<<< 'EOTXT'
$this->assertDumpMatchesFormat(<<<EOTXT
ReflectionMethod {
+name: "someMethod"
+class: "Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes"
%A attributes: array:1 [
0 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
arguments: array:1 [
0 => "two"
]
Expand All @@ -646,14 +648,15 @@ public function testReflectionMethodWithAttribute()
public function testReflectionPropertyWithAttribute()
{
$var = new \ReflectionProperty(LotsOfAttributes::class, 'someProperty');
$dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name';

$this->assertDumpMatchesFormat(<<< 'EOTXT'
$this->assertDumpMatchesFormat(<<<EOTXT
ReflectionProperty {
+name: "someProperty"
+class: "Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes"
%A attributes: array:1 [
0 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
arguments: array:2 [
0 => "one"
"extra" => "hello"
Expand All @@ -671,22 +674,23 @@ public function testReflectionPropertyWithAttribute()
public function testReflectionClassConstantWithAttribute()
{
$var = new \ReflectionClassConstant(LotsOfAttributes::class, 'SOME_CONSTANT');
$dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name';

$this->assertDumpMatchesFormat(<<< 'EOTXT'
$this->assertDumpMatchesFormat(<<<EOTXT
ReflectionClassConstant {
+name: "SOME_CONSTANT"
+class: "Symfony\Component\VarDumper\Tests\Fixtures\LotsOfAttributes"
modifiers: "public"
value: "some value"
attributes: array:2 [
0 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute"
arguments: array:1 [
0 => "one"
]
}
1 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute"
arguments: array:1 [
0 => "two"
]
Expand All @@ -703,14 +707,15 @@ public function testReflectionClassConstantWithAttribute()
public function testReflectionParameterWithAttribute()
{
$var = new \ReflectionParameter([LotsOfAttributes::class, 'someMethod'], 'someParameter');
$dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name';

$this->assertDumpMatchesFormat(<<< 'EOTXT'
$this->assertDumpMatchesFormat(<<<EOTXT
ReflectionParameter {
+name: "someParameter"
position: 0
attributes: array:1 [
0 => ReflectionAttribute {
name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
$dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute"
arguments: array:1 [
0 => "three"
]
Expand Down

0 comments on commit a078ef2

Please sign in to comment.