Nelmio\Alice\FixtureBuilder\Denormalizer\FlagParser\ElementFlagParser::parse PHP Method

parse() public method

public parse ( string $element ) : FlagBag
$element string
return Nelmio\Alice\Definition\FlagBag
    public function parse(string $element) : FlagBag
    {
        if (1 !== preg_match(self::REGEX, $element, $matches)) {
            return new FlagBag($element);
        }
        $flags = new FlagBag($matches['reference']);
        $stringFlags = preg_split('/\\s*,\\s*/', $matches['stringFlags']);
        foreach ($stringFlags as $stringFlag) {
            $flags = $flags->mergeWith($this->parser->parse(trim($stringFlag)));
        }
        return $flags;
    }

Usage Example

Beispiel #1
0
 public function testIfAFlagIsFoundThenParsesItWithDecoratedParserBeforeReturningTheFlags()
 {
     $element = 'dummy ( flag1 , flag2 )';
     $decoratedParserProphecy = $this->prophesize(FlagParserInterface::class);
     $decoratedParserProphecy->parse('flag1')->willReturn((new FlagBag(''))->withFlag(new ElementFlag('flag1')));
     $decoratedParserProphecy->parse('flag2')->willReturn((new FlagBag(''))->withFlag(new ElementFlag('flag2'))->withFlag(new ElementFlag('additional flag')));
     /** @var FlagParserInterface $decoratedParser */
     $decoratedParser = $decoratedParserProphecy->reveal();
     $expected = (new FlagBag('dummy'))->withFlag(new ElementFlag('flag1'))->withFlag(new ElementFlag('flag2'))->withFlag(new ElementFlag('additional flag'));
     $parser = new ElementFlagParser($decoratedParser);
     $actual = $parser->parse($element);
     $this->assertEquals($expected, $actual);
 }
ElementFlagParser