Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\SpecificationBagDenormalizer\Value\SimpleValueDenormalizer::denormalize PHP Method

denormalize() public method

public denormalize ( Nelmio\Alice\FixtureInterface $scope, FlagBag $flags = null, $value )
$scope Nelmio\Alice\FixtureInterface
$flags Nelmio\Alice\Definition\FlagBag
    public function denormalize(FixtureInterface $scope, FlagBag $flags = null, $value)
    {
        if (is_string($value)) {
            return $this->parseValue($this->parser, $value);
        }
        if (is_array($value)) {
            $array = [];
            foreach ($value as $key => $item) {
                $array[$key] = $this->denormalize($scope, $flags, $item);
            }
            return new ArrayValue($array);
        }
        return $value;
    }

Usage Example

 public function testWhenParserThrowsExceptionDenormalizerAExceptionIsThrown()
 {
     $parserProphecy = $this->prophesize(ParserInterface::class);
     $parserProphecy->parse(Argument::any())->willThrow($thrownException = new RootParseException('hello world', 10));
     /** @var ParserInterface $parser */
     $parser = $parserProphecy->reveal();
     $denormalizer = new SimpleValueDenormalizer($parser);
     try {
         $denormalizer->denormalize(new FakeFixture(), null, 'foo');
         $this->fail('Expected throwable to be thrown.');
     } catch (DenormalizationThrowable $throwable) {
         $this->assertEquals('Could not parse value "foo".', $throwable->getMessage());
         $this->assertEquals(0, $throwable->getCode());
         $this->assertEquals($thrownException, $throwable->getPrevious());
     }
 }