Skip to content

Commit

Permalink
Use current php version parser (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinfi authored Feb 20, 2025
1 parent 430e561 commit 7591071
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Internal/ObjectExporter/ClosureExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function export(object $object, \ReflectionObject $reflectionObject, arra
private function getParser()
{
if ($this->parser === null) {
$this->parser = (new ParserFactory)->createForVersion(PhpVersion::fromComponents(7, 4));
$this->parser = (new ParserFactory)->createForHostVersion();
}

return $this->parser;
Expand Down
26 changes: 26 additions & 0 deletions tests/ExportClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Brick\VarExporter\Tests;

use Brick\VarExporter\Tests\Classes\Enum;
use Brick\VarExporter\Tests\Classes\NoProperties;
use Brick\VarExporter\Tests\Classes\PublicPropertiesOnly;
use Brick\VarExporter\Tests\Classes\SetState;
Expand Down Expand Up @@ -252,6 +253,31 @@ function ($planet) {
$this->assertExportEquals($expected, $var, VarExporter::ADD_RETURN | VarExporter::CLOSURE_SNAPSHOT_USES);
}

public function testExportEnumMatchFunction(): void
{
$var = [
(object) [
'callback' => static fn (Enum $enum): string => match ($enum) {
Enum::TEST => 'foo',
}
]
];

$expected = <<<'PHP'
[
(object) [
'callback' => function (\Brick\VarExporter\Tests\Classes\Enum $enum): string {
return match ($enum) {
\Brick\VarExporter\Tests\Classes\Enum::TEST => 'foo',
};
}
]
]
PHP;

$this->assertExportEquals($expected, $var);
}

public function testExportClosureDefinedInEval(): void
{
$var = eval(<<<PHP
Expand Down

0 comments on commit 7591071

Please sign in to comment.