Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\TokenParserRegistryTest::testPicksTheFirstSuitableParserToParseTheToken PHP Method

testPicksTheFirstSuitableParserToParseTheToken() public method

    public function testPicksTheFirstSuitableParserToParseTheToken()
    {
        $token = new Token('foo', new TokenType(TokenType::STRING_TYPE));
        $expected = 'foo';
        $parser1Prophecy = $this->prophesize(ChainableTokenParserInterface::class);
        $parser1Prophecy->canParse($token)->willReturn(false);
        /* @var ChainableTokenParserInterface $parser1 */
        $parser1 = $parser1Prophecy->reveal();
        $parser2Prophecy = $this->prophesize(ChainableTokenParserInterface::class);
        $parser2Prophecy->canParse($token)->willReturn(true);
        $parser2Prophecy->parse($token)->willReturn($expected);
        /* @var ChainableTokenParserInterface $parser2 */
        $parser2 = $parser2Prophecy->reveal();
        $parser3Prophecy = $this->prophesize(ChainableTokenParserInterface::class);
        $parser3Prophecy->canParse(Argument::any())->shouldNotBeCalled();
        /* @var ChainableTokenParserInterface $parser3 */
        $parser3 = $parser3Prophecy->reveal();
        $registry = new TokenParserRegistry([$parser1, $parser2, $parser3]);
        $actual = $registry->parse($token);
        $this->assertSame($expected, $actual);
        $parser1Prophecy->canParse(Argument::any())->shouldHaveBeenCalledTimes(1);
        $parser2Prophecy->canParse(Argument::any())->shouldHaveBeenCalledTimes(1);
        $parser2Prophecy->parse(Argument::any())->shouldHaveBeenCalledTimes(1);
    }