Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable\StringArrayTokenParser::parse PHP Method

parse() public method

public parse ( Token $token ) : array
$token Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Token
return array
    public function parse(Token $token) : array
    {
        parent::parse($token);
        $value = $token->getValue();
        try {
            $elements = substr($value, 1, strlen($value) - 2);
            return $this->parseElements($this->parser, $elements);
        } catch (\TypeError $error) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $error);
        }
    }

Usage Example

 public function testTrimsEachArgumentValueBeforePassingThemToTheDecoratedParser()
 {
     $token = new Token('[ val1 , val2 ]', new TokenType(TokenType::STRING_ARRAY_TYPE));
     $decoratedParserProphecy = $this->prophesize(ParserInterface::class);
     $decoratedParserProphecy->parse('val1')->willReturn('parsed_val1');
     $decoratedParserProphecy->parse('val2')->willReturn('parsed_val2');
     /** @var ParserInterface $decoratedParser */
     $decoratedParser = $decoratedParserProphecy->reveal();
     $expected = ['parsed_val1', 'parsed_val2'];
     $parser = new StringArrayTokenParser($decoratedParser);
     $actual = $parser->parse($token);
     $this->assertEquals($expected, $actual);
 }