public function testInitializationRestoresDefaultPublicLazyLoadedFieldValues()
 {
     // setting noop persister
     $this->proxyLoader->expects($this->once())->method('load')->will($this->returnValue($this->lazyObject));
     $this->lazyObject->__setInitializer($this->getSuggestedInitializerImplementation());
     $this->assertSame('publicPersistentFieldValue', $this->lazyObject->publicPersistentField, 'Persistent field is restored to default value');
     $this->assertSame('publicAssociationValue', $this->lazyObject->publicAssociation, 'Association is restored to default value');
 }
Example #2
0
 /**
  * Sets a value in the current proxy object without triggering lazy loading through `__set`
  *
  * @link https://bugs.php.net/bug.php?id=63463
  *
  * @param string $property
  * @param mixed $value
  */
 public function setProxyValue($property, $value)
 {
     $reflectionProperty = new \ReflectionProperty($this->lazyObject, $property);
     $initializer = $this->lazyObject->__getInitializer();
     // disabling initializer since setting `publicPersistentField` triggers `__set`/`__get`
     $this->lazyObject->__setInitializer(null);
     $reflectionProperty->setValue($this->lazyObject, $value);
     $this->lazyObject->__setInitializer($initializer);
 }
 /**
  * Reset initialization/cloning logic for an un-initialized proxy
  *
  * @param \Doctrine\Common\Proxy\Proxy $proxy
  *
  * @return \Doctrine\Common\Proxy\Proxy
  *
  * @throws \Doctrine\Common\Proxy\Exception\InvalidArgumentException
  */
 public function resetUninitializedProxy(Proxy $proxy)
 {
     if ($proxy->__isInitialized()) {
         throw InvalidArgumentException::unitializedProxyExpected($proxy);
     }
     $className = ClassUtils::getClass($proxy);
     $definition = isset($this->definitions[$className]) ? $this->definitions[$className] : $this->getProxyDefinition($className);
     $proxy->__setInitializer($definition->initializer);
     $proxy->__setCloner($definition->cloner);
     return $proxy;
 }