/**
  * Sets up this test case
  * @return void
  */
 public function setUp()
 {
     $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
     $this->query = new Tx_Extbase_Persistence_Query('someType');
     $this->query->injectObjectManager($this->objectManager);
     $this->querySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
     $this->query->setQuerySettings($this->querySettings);
     $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
     $this->backend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
     $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
     $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->query->injectPersistenceManager($this->persistenceManager);
     $this->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');
     $this->query->injectDataMapper($this->dataMapper);
 }
Exemple #2
0
 /**
  * Commits new objects and changes to objects in the current persistence
  * session into the backend
  *
  * @return void
  * @api
  */
 public function persistAll()
 {
     $aggregateRootObjects = new Tx_Extbase_Persistence_ObjectStorage();
     $removedObjects = new Tx_Extbase_Persistence_ObjectStorage();
     // fetch and inspect objects from all known repositories
     foreach ($this->repositoryClassNames as $repositoryClassName) {
         $repository = $this->objectManager->get($repositoryClassName);
         $aggregateRootObjects->addAll($repository->getAddedObjects());
         $removedObjects->addAll($repository->getRemovedObjects());
     }
     foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) {
         if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) {
             $aggregateRootObjects->attach($reconstitutedObject);
         }
     }
     // hand in only aggregate roots, leaving handling of subobjects to
     // the underlying storage layer
     $this->backend->setAggregateRootObjects($aggregateRootObjects);
     $this->backend->setDeletedObjects($removedObjects);
     $this->backend->commit();
     // this needs to unregister more than just those, as at least some of
     // the subobjects are supposed to go away as well...
     // OTOH those do no harm, changes to the unused ones should not happen,
     // so all they do is eat some memory.
     foreach ($removedObjects as $removedObject) {
         $this->session->unregisterReconstitutedObject($removedObject);
     }
 }