Chris@0: array( Chris@0: 'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments' Chris@0: ))); Chris@0: $parser5 = new Parser\Php5($lexer); Chris@0: $parser7 = new Parser\Php7($lexer); Chris@0: Chris@0: $dumpPositions = isset($modes['positions']); Chris@0: $output5 = $this->getParseOutput($parser5, $code, $dumpPositions); Chris@0: $output7 = $this->getParseOutput($parser7, $code, $dumpPositions); Chris@0: Chris@0: if (isset($modes['php5'])) { Chris@0: $this->assertSame($expected, $output5, $name); Chris@0: $this->assertNotSame($expected, $output7, $name); Chris@0: } else if (isset($modes['php7'])) { Chris@0: $this->assertNotSame($expected, $output5, $name); Chris@0: $this->assertSame($expected, $output7, $name); Chris@0: } else { Chris@0: $this->assertSame($expected, $output5, $name); Chris@0: $this->assertSame($expected, $output7, $name); Chris@0: } Chris@0: } Chris@0: Chris@0: private function getParseOutput(Parser $parser, $code, $dumpPositions) { Chris@0: $errors = new ErrorHandler\Collecting; Chris@0: $stmts = $parser->parse($code, $errors); Chris@0: Chris@0: $output = ''; Chris@0: foreach ($errors->getErrors() as $error) { Chris@0: $output .= $this->formatErrorMessage($error, $code) . "\n"; Chris@0: } Chris@0: Chris@0: if (null !== $stmts) { Chris@0: $dumper = new NodeDumper(['dumpComments' => true, 'dumpPositions' => $dumpPositions]); Chris@0: $output .= $dumper->dump($stmts, $code); Chris@0: } Chris@0: Chris@0: return canonicalize($output); Chris@0: } Chris@0: Chris@0: public function provideTestParse() { Chris@0: return $this->getTests(__DIR__ . '/../code/parser', 'test'); Chris@0: } Chris@0: Chris@0: private function formatErrorMessage(Error $e, $code) { Chris@0: if ($e->hasColumnInfo()) { Chris@0: return $e->getMessageWithColumnInfo($code); Chris@0: } else { Chris@0: return $e->getMessage(); Chris@0: } Chris@0: } Chris@0: }