public static createForInvalidProperty ( Nelmio\Alice\ObjectInterface $object, |
||
$object | Nelmio\Alice\ObjectInterface | |
$property | ||
$code | integer | |
$previous | Throwable | |
return | InvalidArgumentException |
public function testTestCreateForInvalidProperty() { $object = new SimpleObject('dummy', new \stdClass()); $property = new Property('foo', 'bar'); $exception = HydrationExceptionFactory::createForInvalidProperty($object, $property); $this->assertEquals('Invalid value given for 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::createForInvalidProperty($object, $property, $code, $previous); $this->assertEquals('Invalid value given for 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); }