Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable\PropertyReferenceTokenParser::parse PHP Метод

parse() публичный Метод

public parse ( Token $token ) : FixturePropertyValue
$token Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Token
Результат Nelmio\Alice\Definition\Value\FixturePropertyValue
    public function parse(Token $token) : FixturePropertyValue
    {
        parent::parse($token);
        $explodedValue = explode('->', $token->getValue());
        if (count($explodedValue) !== 2) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }
        $reference = $this->parser->parse($explodedValue[0]);
        if (false === $reference instanceof ValueInterface) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }
        return new FixturePropertyValue($reference, $explodedValue[1]);
    }

Usage Example

 public function testReturnsAPropertyReferenceIfCanParseToken()
 {
     $token = new Token('@user->username', new TokenType(TokenType::PROPERTY_REFERENCE_TYPE));
     $decoratedParserProphecy = $this->prophesize(ParserInterface::class);
     $decoratedParserProphecy->parse('@user')->willReturn($reference = new FixtureReferenceValue('user'));
     /** @var ParserInterface $decoratedParser */
     $decoratedParser = $decoratedParserProphecy->reveal();
     $expected = new FixturePropertyValue($reference, 'username');
     $parser = new PropertyReferenceTokenParser($decoratedParser);
     $actual = $parser->parse($token);
     $this->assertEquals($expected, $actual);
     $decoratedParserProphecy->parse(Argument::any())->shouldHaveBeenCalledTimes(1);
 }
PropertyReferenceTokenParser