Skip to content

Commit

Permalink
Explicit test new ParserFactory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 17, 2023
1 parent 21fa9c9 commit 8b9488e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/PhpParser/Node/Scalar/DNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DNumberTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo 1_234.56;');

$echo = $nodes[0];
Expand Down
2 changes: 1 addition & 1 deletion test/PhpParser/Node/Scalar/NumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class NumberTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo 1_234;');

$echo = $nodes[0];
Expand Down
2 changes: 1 addition & 1 deletion test/PhpParser/Node/Scalar/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class StringTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo "sequence \x41";');

$echo = $nodes[0];
Expand Down
2 changes: 1 addition & 1 deletion test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class NodeConnectingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testConnectsNodeToItsParentNodeAndItsSiblingNodes() {
$ast = (new ParserFactory())->create(ParserFactory::PREFER_PHP7)->parse(
$ast = (new ParserFactory())->createForNewestSupportedVersion()->parse(
'<?php if (true) {} else {}'
);

Expand Down
2 changes: 1 addition & 1 deletion test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class ParentConnectingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testConnectsChildNodeToParentNode() {
$ast = (new ParserFactory())->create(ParserFactory::PREFER_PHP7)->parse(
$ast = (new ParserFactory())->createForNewestSupportedVersion()->parse(
'<?php class C { public function m() {} }'
);

Expand Down
27 changes: 12 additions & 15 deletions test/PhpParser/ParserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
/* This test is very weak, because PHPUnit's assertEquals assertion is way too slow dealing with the
* large objects involved here. So we just do some basic instanceof tests instead. */

use PhpParser\Parser\Php7;
use PhpParser\Parser\Php8;

class ParserFactoryTest extends \PHPUnit\Framework\TestCase {
/** @dataProvider provideTestCreate */
public function testCreate($kind, $lexer, $expected) {
$this->assertInstanceOf($expected, (new ParserFactory())->create($kind, $lexer));
}
public function testCreate() {
$factory = new ParserFactory();

public function provideTestCreate() {
$lexer = new Lexer();
return [
[
ParserFactory::PREFER_PHP7, $lexer,
Parser\Php7::class
],
[
ParserFactory::ONLY_PHP7, null,
Parser\Php7::class
],
];
$this->assertInstanceOf(Php7::class, $factory->create(ParserFactory::PREFER_PHP7, $lexer));
$this->assertInstanceOf(Php7::class, $factory->create(ParserFactory::ONLY_PHP7, $lexer));
$this->assertInstanceOf(Php7::class, $factory->create(ParserFactory::PREFER_PHP7));
$this->assertInstanceOf(Php7::class, $factory->create(ParserFactory::ONLY_PHP7));

$this->assertInstanceOf(Php8::class, $factory->createForNewestSupportedVersion());
$this->assertInstanceOf(Parser::class, $factory->createForHostVersion());
}
}

0 comments on commit 8b9488e

Please sign in to comment.