Nelmio\Alice\Generator\Hydrator\Property\SymfonyPropertyAccessorHydratorTest::testThrowsAnHydrationExceptionIfAnAccessExceptionIsThrown PHP Method

testThrowsAnHydrationExceptionIfAnAccessExceptionIsThrown() public method

    public function testThrowsAnHydrationExceptionIfAnAccessExceptionIsThrown()
    {
        try {
            $property = new Property('username', 'bob');
            $instance = new Dummy();
            $object = new SimpleObject('dummy', $instance);
            $accessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
            $accessorProphecy->setValue(Argument::cetera())->willThrow(AccessException::class);
            /** @var PropertyAccessorInterface $accessor */
            $accessor = $accessorProphecy->reveal();
            $hydrator = new SymfonyPropertyAccessorHydrator($accessor);
            $hydrator->hydrate($object, $property, new GenerationContext());
            $this->fail('Expected exception to be thrown.');
        } catch (InaccessiblePropertyException $exception) {
            $this->assertEquals('Could not access to the property "username" of the object "dummy" (class: Nelmio\\Alice\\Entity\\Hydrator\\Dummy).', $exception->getMessage());
            $this->assertEquals(0, $exception->getCode());
            $this->assertNotNull($exception->getPrevious());
        }
    }