Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\SpecificationBagDenormalizer\Value\UniqueValueDenormalizer::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)
    {
        $value = $this->denormalizer->denormalize($scope, $flags, $value);
        if (false === $this->requiresUnique($flags)) {
            return $value;
        }
        return $this->generateValue($scope, $flags, $value);
    }

Usage Example

 public function testIfParsedValueIsArrayValueThenUniqueFlagAppliesToItsElementInstead()
 {
     $fixture = new SimpleFixture('dummy_id', 'Dummy', SpecificationBagFactory::create());
     $value = 'string value';
     $denormalizedValue = new ArrayValue(['foo', 'bar']);
     $flags = (new FlagBag(''))->withFlag(new UniqueFlag());
     $decoratedDenormalizerProphecy = $this->prophesize(ValueDenormalizerInterface::class);
     $decoratedDenormalizerProphecy->denormalize($fixture, $flags, $value)->willReturn($denormalizedValue);
     /** @var ValueDenormalizerInterface $decoratedDenormalizer */
     $decoratedDenormalizer = $decoratedDenormalizerProphecy->reveal();
     $denormalizer = new UniqueValueDenormalizer($decoratedDenormalizer);
     $result = $denormalizer->denormalize($fixture, $flags, $value);
     $this->assertInstanceOf(ArrayValue::class, $result);
     /** @var ArrayValue $result */
     $this->assertInstanceOf(UniqueValue::class, $result->getValue()[0]);
     $this->stringContains('dummy_id', $result->getValue()[0]->getId());
     $this->assertEquals('foo', $result->getValue()[0]->getValue());
     $this->assertInstanceOf(UniqueValue::class, $result->getValue()[1]);
     $this->stringContains('dummy_id', $result->getValue()[1]->getId());
     $this->assertEquals('bar', $result->getValue()[1]->getValue());
 }