public function testTestCreateForCouldNotHydrateObjectWithProperty() { $object = new SimpleObject('dummy', new \stdClass()); $property = new Property('foo', 'bar'); $exception = HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property); $this->assertEquals('Could not hydrate the property "foo" of the object "dummy" (class: stdClass).', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNull($exception->getPrevious()); $code = 500; $previous = new \Error(); $exception = HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property, $code, $previous); $this->assertEquals('Could not hydrate the property "foo" of the object "dummy" (class: stdClass).', $exception->getMessage()); $this->assertEquals($code, $exception->getCode()); $this->assertSame($previous, $exception->getPrevious()); }
/** * {@inheritdoc} * * @throws NoSuchPropertyException * @throws InaccessiblePropertyException * @throws InvalidArgumentException When the typehint does not match for example * @throws HydrationException */ 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); }