public parse ( |
||
$token | ||
return |
public function parse(Token $token) : DynamicArrayValue
{
parent::parse($token);
if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) {
throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
}
return new DynamicArrayValue((int) $this->parser->parse($matches['quantifier']), $this->parser->parse($matches['elements']));
}
public function testReturnsADynamicArrayIfCanParseToken() { $token = new Token('10x @user', new TokenType(TokenType::DYNAMIC_ARRAY_TYPE)); $decoratedParserProphecy = $this->prophesize(ParserInterface::class); $decoratedParserProphecy->parse('10')->willReturn('0'); $decoratedParserProphecy->parse('@user')->willReturn('parsed_element'); /** @var ParserInterface $decoratedParser */ $decoratedParser = $decoratedParserProphecy->reveal(); $expected = new DynamicArrayValue(0, 'parsed_element'); $parser = new DynamicArrayTokenParser($decoratedParser); $actual = $parser->parse($token); $this->assertEquals($expected, $actual); $decoratedParserProphecy->parse(Argument::any())->shouldHaveBeenCalledTimes(2); }