Nelmio\Alice\Generator\Hydrator\Property\SymfonyPropertyAccessorHydrator::hydrate PHP Method

hydrate() public method

public hydrate ( Nelmio\Alice\ObjectInterface $object, Property $property, GenerationContext $context ) : Nelmio\Alice\ObjectInterface
$object Nelmio\Alice\ObjectInterface
$property Nelmio\Alice\Definition\Property
$context Nelmio\Alice\Generator\GenerationContext
return Nelmio\Alice\ObjectInterface
    public function hydrate(ObjectInterface $object, Property $property, GenerationContext $context) : ObjectInterface
    {
        $instance = $object->getInstance();
        try {
            $this->propertyAccessor->setValue($instance, $property->getName(), $property->getValue());
        } catch (SymfonyNoSuchPropertyException $exception) {
            throw HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property, 0, $exception);
        } catch (SymfonyAccessException $exception) {
            throw HydrationExceptionFactory::createForInaccessibleProperty($object, $property, 0, $exception);
        } catch (SymfonyInvalidArgumentException $exception) {
            throw HydrationExceptionFactory::createForInvalidProperty($object, $property, 0, $exception);
        } catch (SymfonyPropertyAccessException $exception) {
            throw HydrationExceptionFactory::create($object, $property, 0, $exception);
        }
        return new SimpleObject($object->getId(), $instance);
    }

Usage Example

 /**
  * @dataProvider provideProperties
  */
 public function testTestObjectHydrationAgainstMutlipleValues(Property $property)
 {
     $instance = new Dummy();
     $object = new SimpleObject('dummy', $instance);
     $hydratedObject = $this->hydrator->hydrate($object, $property, new GenerationContext());
     $expected = $property->getValue();
     $actual = $this->propertyAccessor->getValue($hydratedObject->getInstance(), $property->getName());
     $this->assertSame($expected, $actual);
 }
SymfonyPropertyAccessorHydrator