Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\SpecificationBagDenormalizer\Calls\OptionalCallsDenormalizer::denormalize PHP Method

denormalize() public method

public denormalize ( Nelmio\Alice\FixtureInterface $scope, Nelmio\Alice\FixtureBuilder\Denormalizer\FlagParserInterface $parser, string $unparsedMethod, array $unparsedArguments ) : Nelmio\Alice\Definition\MethodCallInterface
$scope Nelmio\Alice\FixtureInterface
$parser Nelmio\Alice\FixtureBuilder\Denormalizer\FlagParserInterface
$unparsedMethod string
$unparsedArguments array
return Nelmio\Alice\Definition\MethodCallInterface
    public function denormalize(FixtureInterface $scope, FlagParserInterface $parser, string $unparsedMethod, array $unparsedArguments) : MethodCallInterface
    {
        $methodFlags = $parser->parse($unparsedMethod);
        $method = $methodFlags->getKey();
        $arguments = $this->argumentDenormalizer->denormalize($scope, $parser, $unparsedArguments);
        $methodCall = new SimpleMethodCall($method, $arguments);
        return $this->handleMethodFlags($methodCall, $methodFlags);
    }

Usage Example

 /**
  * @dataProvider provideMethods
  */
 public function testDenormalizesMethodWithOptionalCallFlagToReturnAOptionalMethodCall(FlagParserInterface $flagParser, bool $optional)
 {
     $fixture = new FakeFixture();
     $unparsedArguments = ['<latitude()>', '<longitude()>'];
     $argumentsDenormalizerProphecy = $this->prophesize(ArgumentsDenormalizerInterface::class);
     $argumentsDenormalizerProphecy->denormalize($fixture, $flagParser, $unparsedArguments)->willReturn($parsedArguments = [new \stdClass()]);
     /** @var ArgumentsDenormalizerInterface $argumentsDenormalizer */
     $argumentsDenormalizer = $argumentsDenormalizerProphecy->reveal();
     $expected = new SimpleMethodCall('parsed_method', $parsedArguments);
     $denormalizer = new OptionalCallsDenormalizer($argumentsDenormalizer);
     $actual = $denormalizer->denormalize($fixture, $flagParser, 'something', $unparsedArguments);
     if ($optional) {
         $this->assertEquals(new OptionalMethodCall($expected, new OptionalFlag(80)), $actual);
     } else {
         $this->assertEquals($expected, $actual);
     }
 }