Chris@13: []]); Chris@0: return new Multiple([new Php7($lexer), new Php5($lexer)]); Chris@0: } Chris@0: Chris@0: private function getPrefer5() { Chris@0: $lexer = new Lexer(['usedAttributes' => []]); Chris@0: return new Multiple([new Php5($lexer), new Php7($lexer)]); Chris@0: } Chris@0: Chris@0: /** @dataProvider provideTestParse */ Chris@0: public function testParse($code, Multiple $parser, $expected) { Chris@0: $this->assertEquals($expected, $parser->parse($code)); Chris@0: } Chris@0: Chris@0: public function provideTestParse() { Chris@0: return [ Chris@0: [ Chris@0: // PHP 7 only code Chris@0: 'getPrefer5(), Chris@0: [ Chris@0: new Stmt\Class_('Test', ['stmts' => [ Chris@0: new Stmt\ClassMethod('function') Chris@0: ]]), Chris@0: ] Chris@0: ], Chris@0: [ Chris@0: // PHP 5 only code Chris@0: 'b;', Chris@0: $this->getPrefer7(), Chris@0: [ Chris@0: new Stmt\Global_([ Chris@0: new Expr\Variable(new Expr\PropertyFetch(new Expr\Variable('a'), 'b')) Chris@0: ]) Chris@0: ] Chris@0: ], Chris@0: [ Chris@0: // Different meaning (PHP 5) Chris@0: 'getPrefer5(), Chris@0: [ Chris@13: new Stmt\Expression(new Expr\Variable( Chris@0: new Expr\ArrayDimFetch(new Expr\Variable('a'), LNumber::fromString('0')) Chris@13: )) Chris@0: ] Chris@0: ], Chris@0: [ Chris@0: // Different meaning (PHP 7) Chris@0: 'getPrefer7(), Chris@0: [ Chris@13: new Stmt\Expression(new Expr\ArrayDimFetch( Chris@0: new Expr\Variable(new Expr\Variable('a')), LNumber::fromString('0') Chris@13: )) Chris@0: ] Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: public function testThrownError() { Chris@13: $this->expectException(Error::class); Chris@13: $this->expectExceptionMessage('FAIL A'); Chris@0: Chris@13: $parserA = $this->getMockBuilder(\PhpParser\Parser::class)->getMock(); Chris@0: $parserA->expects($this->at(0)) Chris@17: ->method('parse')->willThrowException(new Error('FAIL A')); Chris@0: Chris@13: $parserB = $this->getMockBuilder(\PhpParser\Parser::class)->getMock(); Chris@0: $parserB->expects($this->at(0)) Chris@17: ->method('parse')->willThrowException(new Error('FAIL B')); Chris@0: Chris@0: $parser = new Multiple([$parserA, $parserB]); Chris@0: $parser->parse('dummy'); Chris@0: } Chris@13: }