Inheritance: extends AbstractChainableParserAwareParser
Example #1
0
 public function testReturnsAnOptionalValueIfCanParseToken()
 {
     $token = new Token('60%? foo: bar', new TokenType(TokenType::OPTIONAL_TYPE));
     $anotherToken = new Token('80%? baz', new TokenType(TokenType::OPTIONAL_TYPE));
     $decoratedParserProphecy = $this->prophesize(ParserInterface::class);
     $decoratedParserProphecy->parse('60')->willReturn('parsed_quantifier');
     $decoratedParserProphecy->parse('foo')->willReturn('parsed_first_member');
     $decoratedParserProphecy->parse('bar')->willReturn('parsed_second_member');
     $decoratedParserProphecy->parse('80')->willReturn('parsed_80');
     $decoratedParserProphecy->parse('baz')->willReturn('parsed_baz');
     /** @var ParserInterface $decoratedParser */
     $decoratedParser = $decoratedParserProphecy->reveal();
     $expected0 = new OptionalValue('parsed_quantifier', 'parsed_first_member', 'parsed_second_member');
     $expected1 = new OptionalValue('parsed_80', 'parsed_baz');
     $parser = new OptionalTokenParser($decoratedParser);
     $actual0 = $parser->parse($token);
     $actual1 = $parser->parse($anotherToken);
     $this->assertEquals($expected0, $actual0);
     $this->assertEquals($expected1, $actual1);
     $decoratedParserProphecy->parse(Argument::any())->shouldHaveBeenCalledTimes(5);
 }