Skip to content

Commit b5277c1

Browse files
author
Patrik Foldes
committed
fix
1 parent 43dc6ca commit b5277c1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/generation/GeneratedClassAsserter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
use PhpParser\Node\Stmt\UseUse;
2323
use PhpParser\NodeFinder;
2424
use PhpParser\ParserFactory;
25-
use PhpParser\PhpVersion;
2625
use PHPUnit\Framework\Assert;
26+
use ReflectionClass;
2727

2828
use function array_pop;
2929
use function explode;
@@ -40,9 +40,14 @@ final class GeneratedClassAsserter
4040
public function __construct(InMemoryFileWriter $fileWriter, string $path)
4141
{
4242
$this->nodeFinder = new NodeFinder();
43-
$phpParser = (new ParserFactory())->createForVersion(PhpVersion::fromString('7.0'));
44-
$phpCode = $fileWriter->getContentsByFullPath($path);
45-
$statements = $phpParser->parse($phpCode);
43+
if ((new ReflectionClass(ParserFactory::class))->hasMethod('create')) {
44+
$phpParser = (new ParserFactory())->create(1);
45+
} else {
46+
$phpParser = (new ParserFactory())->createForHostVersion();
47+
}
48+
49+
$phpCode = $fileWriter->getContentsByFullPath($path);
50+
$statements = $phpParser->parse($phpCode);
4651
if ($statements === null) {
4752
throw new InvalidArgumentException('No statements found in provided PHP code');
4853
}

0 commit comments

Comments
 (0)