Author: Roman Borschel (roman@code-factory.org)
Author: Giorgio Sironi (piccoloprincipeazzurro@gmail.com)
Ejemplo n.º 1
0
 public function testReferenceProxyDelegatesLoadingToThePersister()
 {
     $proxyClass = 'Proxies\\__CG__\\Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature';
     $modelClass = 'Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature';
     $query = array('documentName' => '\\' . $modelClass, 'id' => 'SomeUUID');
     $uowMock = $this->getMock('Doctrine\\ODM\\CouchDB\\UnitOfWork', array('refresh'), array(), '', false);
     $uowMock->expects($this->atLeastOnce())->method('refresh')->with($this->isInstanceOf($proxyClass));
     $dmMock = new DocumentManagerMock();
     $dmMock->setUnitOfWorkMock($uowMock);
     $this->proxyFactory = new ProxyFactory($dmMock, __DIR__ . '/generated', 'Proxies', true);
     $proxy = $this->proxyFactory->getProxy($modelClass, $query['id'], $query['documentName']);
     $this->assertInstanceOf('Doctrine\\ODM\\CouchDB\\Proxy\\Proxy', $proxy);
     $proxy->getDescription();
 }
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 $documentName The name of the entity type.
  * @param mixed $identifier The entity identifier.
  * @return object The entity reference.
  */
 public function getReference($documentName, $identifier)
 {
     $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
     // Check identity map first, if its already in there just return it.
     if ($document = $this->unitOfWork->tryGetById($identifier)) {
         return $document;
     }
     $document = $this->proxyFactory->getProxy($class->name, $identifier);
     $this->unitOfWork->registerManaged($document, $identifier, null);
     return $document;
 }