function it_uses_parser_options(ParserFactory $parserFactory, TraverserFactory $traverserFactory, Parser $parser, NodeTraverserInterface $traverser) { $file = new SplFileInfo('php://memory'); $this->setParserOptions($options = ['kind' => 'php7']); $parserFactory->createFromOptions($options)->shouldBeCalled()->willReturn($parser); $traverserFactory->createForTaskContext($options, Argument::that(function (ParserContext $context) use($file) { return $context->getFile() === $file && $context->getErrors() instanceof ParseErrorsCollection; }))->shouldBeCalled()->willReturn($traverser); $this->parse($file); }
/** * @param SplFileInfo $file * * @return ParseErrorsCollection */ public function parse(SplFileInfo $file) { $errors = new ParseErrorsCollection(); $context = new ParserContext($file, $errors); $parser = $this->parserFactory->createFromOptions($this->parserOptions); $traverser = $this->traverserFactory->createForTaskContext($this->parserOptions, $context); try { $code = $this->filesystem->readFromFileInfo($file); $stmts = $parser->parse($code); $traverser->traverse($stmts); } catch (Error $e) { $errors->add(PhpParserError::fromParseException($e, $file->getRealPath())); } return $errors; }