Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  fix tests
  fix merge
  [VarDumper] Fix generator dump on PHP 8.4
  keep boolean options when their value is false
  gracefully handle cases when no resolver is set
  • Loading branch information
xabbuh committed May 28, 2024
2 parents d4dea60 + 4da159e commit 595e4a4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $
// Cannot create ReflectionGenerator based on a terminated Generator
try {
$reflectionGenerator = new \ReflectionGenerator($c);

return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
} catch (\Exception) {
$a[Caster::PREFIX_VIRTUAL.'closed'] = true;

return $a;
}

return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
}

public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $isNested): array
Expand Down
82 changes: 82 additions & 0 deletions Tests/Caster/ReflectionCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,84 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
);
}

/**
* @requires PHP < 8.4
*/
public function testGeneratorPriorTo84()
{
if (\extension_loaded('xdebug')) {
$this->markTestSkipped('xdebug is active');
}

$generator = new GeneratorDemo();
$generator = $generator->baz();

$expectedDump = <<<'EODUMP'
Generator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
%s: {
%sGeneratorDemo.php:14 {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
› {
› yield from bar();
› }
}
%A}
closed: false
}
EODUMP;

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

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

$expectedDump = <<<'EODUMP'
array:2 [
0 => ReflectionGenerator {
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
%s: {
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
%A › yield 1;
%A }
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
%A }
closed: false
}
1 => Generator {
%s: {
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
› yield 1;
› }
}
%A }
closed: false
}
]
EODUMP;

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

foreach ($generator as $v) {
}

$expectedDump = <<<'EODUMP'
Generator {
closed: true
}
EODUMP;
$this->assertDumpMatchesFormat($expectedDump, $generator);
}

/**
* @requires PHP 8.4
*/
public function testGenerator()
{
if (\extension_loaded('xdebug')) {
Expand All @@ -471,6 +549,7 @@ public function testGenerator()

$expectedDump = <<<'EODUMP'
Generator {
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
%s: {
%sGeneratorDemo.php:14 {
Expand All @@ -479,6 +558,7 @@ public function testGenerator()
› yield from bar();
› }
}
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
%A}
closed: false
}
Expand All @@ -505,6 +585,7 @@ public function testGenerator()
closed: false
}
1 => Generator {
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo"
%s: {
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
Expand All @@ -526,6 +607,7 @@ public function testGenerator()

$expectedDump = <<<'EODUMP'
Generator {
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
closed: true
}
EODUMP;
Expand Down

0 comments on commit 595e4a4

Please sign in to comment.