withParser() public method

public withParser ( Nelmio\Alice\FixtureBuilder\ExpressionLanguage\ParserInterface $parser ) : self
$parser Nelmio\Alice\FixtureBuilder\ExpressionLanguage\ParserInterface
return self
Example #1
0
 public function testWithersReturnNewModifiedInstance()
 {
     $parser = new FakeParser();
     $parserAwareProphecy = $this->prophesize(ParserAwareInterface::class);
     $parserAwareProphecy->withParser($parser)->willReturn($returnedParser = new FakeChainableTokenParser());
     /** @var ParserAwareInterface $parserAware */
     $parserAware = $parserAwareProphecy->reveal();
     $tokenParser = new TokenParserRegistry([$parser1 = new FakeChainableTokenParser(), $parser2 = new ProphecyChainableTokenParserAware(new FakeChainableTokenParser(), $parserAware)]);
     $newTokenParser = $tokenParser->withParser($parser);
     $this->assertInstanceOf(TokenParserRegistry::class, $newTokenParser);
     $this->assertSame([$parser1, $parser2], $this->parsersRefl->getValue($tokenParser));
     $newTokenParserParsers = $this->parsersRefl->getValue($newTokenParser);
     $this->assertCount(2, $newTokenParserParsers);
     $this->assertEquals([$parser1, $returnedParser], $newTokenParserParsers);
 }