3 namespace PhpParser\Parser;
7 use PhpParser\Node\Expr;
8 use PhpParser\Node\Scalar\LNumber;
9 use PhpParser\Node\Stmt;
10 use PhpParser\ParserTest;
12 require_once __DIR__ . '/../ParserTest.php';
14 class MultipleTest extends ParserTest {
15 // This provider is for the generic parser tests, just pick an arbitrary order here
16 protected function getParser(Lexer $lexer) {
17 return new Multiple([new Php5($lexer), new Php7($lexer)]);
20 private function getPrefer7() {
21 $lexer = new Lexer(['usedAttributes' => []]);
22 return new Multiple([new Php7($lexer), new Php5($lexer)]);
25 private function getPrefer5() {
26 $lexer = new Lexer(['usedAttributes' => []]);
27 return new Multiple([new Php5($lexer), new Php7($lexer)]);
30 /** @dataProvider provideTestParse */
31 public function testParse($code, Multiple $parser, $expected) {
32 $this->assertEquals($expected, $parser->parse($code));
35 public function provideTestParse() {
39 '<?php class Test { function function() {} }',
42 new Stmt\Class_('Test', ['stmts' => [
43 new Stmt\ClassMethod('function')
49 '<?php global $$a->b;',
53 new Expr\Variable(new Expr\PropertyFetch(new Expr\Variable('a'), 'b'))
58 // Different meaning (PHP 5)
63 new Expr\ArrayDimFetch(new Expr\Variable('a'), LNumber::fromString('0'))
68 // Different meaning (PHP 7)
72 new Expr\ArrayDimFetch(
73 new Expr\Variable(new Expr\Variable('a')), LNumber::fromString('0')
80 public function testThrownError() {
81 $this->setExpectedException('PhpParser\Error', 'FAIL A');
83 $parserA = $this->getMockBuilder('PhpParser\Parser')->getMock();
84 $parserA->expects($this->at(0))
85 ->method('parse')->will($this->throwException(new Error('FAIL A')));
87 $parserB = $this->getMockBuilder('PhpParser\Parser')->getMock();
88 $parserB->expects($this->at(0))
89 ->method('parse')->will($this->throwException(new Error('FAIL B')));
91 $parser = new Multiple([$parserA, $parserB]);
92 $parser->parse('dummy');