Skip to content

Commit

Permalink
[VarDumper] Fix tests for PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Jun 17, 2021
1 parent a4763e9 commit a586efd
Showing 1 changed file with 72 additions and 6 deletions.
78 changes: 72 additions & 6 deletions Tests/Caster/ReflectionCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,31 @@ public function testReflectionParameter()
{
$var = new \ReflectionParameter(reflectionParameterFixture::class, 0);

$this->assertDumpMatchesFormat(
<<<'EOTXT'
if (\PHP_VERSION_ID < 80100) {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
ReflectionParameter {
+name: "arg1"
position: 0
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
default: null
}
EOTXT
, $var
);
, $var
);
} else {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
ReflectionParameter {
+name: "arg1"
position: 0
allowsNull: true
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
}
EOTXT
, $var
);
}
}

public function testReflectionParameterScalar()
Expand Down Expand Up @@ -406,7 +420,8 @@ public function testGenerator()
$generator = new GeneratorDemo();
$generator = $generator->baz();

$expectedDump = <<<'EODUMP'
if (\PHP_VERSION_ID < 80100) {
$expectedDump = <<<'EODUMP'
Generator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
executing: {
Expand All @@ -420,14 +435,32 @@ public function testGenerator()
closed: false
}
EODUMP;
} else {
$expectedDump = <<<'EODUMP'
Generator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
trace: {
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:13 {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
› public function baz()
› {
› yield from bar();
}
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
}
closed: false
}
EODUMP;
}

$this->assertDumpMatchesFormat($expectedDump, $generator);

foreach ($generator as $v) {
break;
}

$expectedDump = <<<'EODUMP'
if (\PHP_VERSION_ID < 80100) {
$expectedDump = <<<'EODUMP'
array:2 [
0 => ReflectionGenerator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
Expand Down Expand Up @@ -456,6 +489,39 @@ public function testGenerator()
}
]
EODUMP;
} else {
$expectedDump = <<<'EODUMP'
array:2 [
0 => ReflectionGenerator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
trace: {
%s%eTests%eFixtures%eGeneratorDemo.php:9 {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
› {
› yield 1;
› }
}
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
}
closed: false
}
1 => Generator {
trace: {
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:9 {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
› {
› yield 1;
› }
}
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() {}
}
closed: false
}
]
EODUMP;
}

$r = new \ReflectionGenerator($generator);
$this->assertDumpMatchesFormat($expectedDump, [$r, $r->getExecutingGenerator()]);
Expand Down

0 comments on commit a586efd

Please sign in to comment.