diff --git a/src/ProxyManager/Factory/HydratorFactory.php b/src/ProxyManager/Factory/HydratorFactory.php index d87020523..e29684503 100644 --- a/src/ProxyManager/Factory/HydratorFactory.php +++ b/src/ProxyManager/Factory/HydratorFactory.php @@ -94,7 +94,14 @@ public function createProxy($className) $this->configuration->getProxyAutoloader()->__invoke($proxyClassName); } - $reflectionProperties = $reflection->getProperties(); + /* @var $properties \ReflectionProperty[] */ + $properties = $reflection->getProperties(); + $reflectionProperties = array(); + + foreach ($properties as $property) { + $reflectionProperties[$property->getName()] = $property; + } + $this->reflectionProperties[$className] = $reflectionProperties; return $this->hydrators[$className] = new $proxyClassName($reflectionProperties); diff --git a/tests/ProxyManagerTest/Factory/HydratorFactoryFunctionalTest.php b/tests/ProxyManagerTest/Factory/HydratorFactoryFunctionalTest.php new file mode 100644 index 000000000..5ca1bda6b --- /dev/null +++ b/tests/ProxyManagerTest/Factory/HydratorFactoryFunctionalTest.php @@ -0,0 +1,100 @@ + + * @license MIT + * + * @group Functional + */ +class HydratorFactoryFunctionalTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \ProxyManager\Factory\HydratorFactory + */ + protected $factory; + + /** + * @var \ProxyManager\Configuration + */ + protected $config; + + /** + * @var string + */ + protected $generatedClassName; + + /** + * {@inheritDoc} + */ + public function setUp() + { + $this->config = new Configuration(); + $this->factory = new HydratorFactory($this->config); + + $generator = new EvaluatingGeneratorStrategy(); + $this->generatedClassName = 'foo' . uniqid(); + $proxiedClass = ClassGenerator::fromReflection( + new ClassReflection('ProxyManagerTestAsset\\ClassWithMixedProperties') + ); + + $proxiedClass->setName($this->generatedClassName); + $proxiedClass->setNamespaceName(null); + $generator->generate($proxiedClass); // evaluating the generated class + + $this->config->setGeneratorStrategy($generator); + } + + /** + * @covers \ProxyManager\Factory\HydratorFactory::__construct + * @covers \ProxyManager\Factory\HydratorFactory::createProxy + */ + public function testWillGenerateValidProxy() + { + $this->assertInstanceOf( + 'Zend\\Stdlib\\Hydrator\\HydratorInterface', + $this->factory->createProxy($this->generatedClassName) + ); + } + + /** + * @covers \ProxyManager\Factory\HydratorFactory::__construct + * @covers \ProxyManager\Factory\HydratorFactory::createProxy + */ + public function testWillCacheProxyInstancesProxy() + { + $this->assertSame( + $this->factory->createProxy($this->generatedClassName), + $this->factory->createProxy($this->generatedClassName), + 'Hydrator instances are cached' + ); + } +}