Ejemplo n.º 1
0
 public function testReferenceProxyRespectsMethodsParametersTypeHinting()
 {
     $proxyClass = 'Proxies\\DoctrineTestsModelsECommerceECommerceFeatureProxy';
     $persister = $this->_getMockPersister();
     $this->_uowMock->setEntityPersister('Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature', $persister);
     $proxy = $this->_proxyFactory->getProxy('Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature', null);
     $method = new \ReflectionMethod(get_class($proxy), 'setProduct');
     $params = $method->getParameters();
     $this->assertEquals(1, count($params));
     $this->assertEquals('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct', $params[0]->getClass()->getName());
 }
Ejemplo n.º 2
0
 /**
  * Gets a reference to the entity identified by the given type and identifier
  * without actually loading it, if the entity is not yet loaded.
  *
  * @param string $entityName The name of the entity type.
  * @param mixed $id The entity identifier.
  * @return object The entity reference.
  */
 public function getReference($entityName, $id)
 {
     $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
     if (!is_array($id)) {
         $id = array($class->identifier[0] => $id);
     }
     $sortedId = array();
     foreach ($class->identifier as $identifier) {
         if (!isset($id[$identifier])) {
             throw ORMException::missingIdentifierField($class->name, $identifier);
         }
         $sortedId[$identifier] = $id[$identifier];
     }
     // Check identity map first, if its already in there just return it.
     if ($entity = $this->unitOfWork->tryGetById($sortedId, $class->rootEntityName)) {
         return $entity instanceof $class->name ? $entity : null;
     }
     if ($class->subClasses) {
         return $this->find($entityName, $sortedId);
     }
     if (!is_array($sortedId)) {
         $sortedId = array($class->identifier[0] => $sortedId);
     }
     $entity = $this->proxyFactory->getProxy($class->name, $sortedId);
     $this->unitOfWork->registerManaged($entity, $sortedId, array());
     return $entity;
 }
Ejemplo n.º 3
0
 /**
  * Gets a reference to the entity identified by the given type and identifier
  * without actually loading it.
  *
  * If partial objects are allowed, this method will return a partial object that only
  * has its identifier populated. Otherwise a proxy is returned that automatically
  * loads itself on first access.
  *
  * @return object The entity reference.
  */
 public function getReference($entityName, $identifier)
 {
     $class = $this->_metadataFactory->getMetadataFor($entityName);
     // Check identity map first, if its already in there just return it.
     if ($entity = $this->_unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
         return $entity;
     }
     if (!is_array($identifier)) {
         $identifier = array($class->identifier[0] => $identifier);
     }
     $entity = $this->_proxyFactory->getProxy($class->name, $identifier);
     $this->_unitOfWork->registerManaged($entity, $identifier, array());
     return $entity;
 }
Ejemplo n.º 4
0
 /**
  * @group DDC-2432
  */
 public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized()
 {
     $persister = $this->getMock('Doctrine\\ORM\\Persisters\\BasicEntityPersister', array('load'), array(), '', false);
     $this->uowMock->setEntityPersister('Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature', $persister);
     /* @var $proxy \Doctrine\Common\Proxy\Proxy */
     $proxy = $this->proxyFactory->getProxy('Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature', array('id' => 42));
     $persister->expects($this->atLeastOnce())->method('load')->will($this->returnValue(null));
     try {
         $cloned = clone $proxy;
         $this->fail('An exception was expected to be raised');
     } catch (EntityNotFoundException $exception) {
     }
     $this->assertFalse($proxy->__isInitialized());
     $this->assertInstanceOf('Closure', $proxy->__getInitializer(), 'The initializer wasn\'t removed');
     $this->assertInstanceOf('Closure', $proxy->__getCloner(), 'The cloner wasn\'t removed');
 }
Ejemplo n.º 5
0
 /**
  * Gets a reference to the entity identified by the given type and identifier
  * without actually loading it, if the entity is not yet loaded.
  *
  * @param string $entityName The name of the entity type.
  * @param mixed $identifier The entity identifier.
  * @return object The entity reference.
  */
 public function getReference($entityName, $identifier)
 {
     $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
     // Check identity map first, if its already in there just return it.
     if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
         return $entity instanceof $class->name ? $entity : null;
     }
     if ($class->subClasses) {
         $entity = $this->find($entityName, $identifier);
     } else {
         if (!is_array($identifier)) {
             $identifier = array($class->identifier[0] => $identifier);
         }
         $entity = $this->proxyFactory->getProxy($class->name, $identifier);
         $this->unitOfWork->registerManaged($entity, $identifier, array());
     }
     return $entity;
 }
 /**
  * Test that the proxy behaves in regard to methods like &foo() correctly
  */
 public function testProxyRespectsMethodsWhichReturnValuesByReference()
 {
     $proxy = $this->_proxyFactory->getProxy('Doctrine\\Tests\\Models\\Forum\\ForumEntry', null);
     $method = new \ReflectionMethod(get_class($proxy), 'getTopicByReference');
     $this->assertTrue($method->returnsReference());
 }