/**
  * @test
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function getValueObjectUsageCountEmitsExpectedSql($subject = 'fakeHash')
 {
     $mockStatement = $this->getMock('PDOStatement');
     $mockStatement->expects($this->once())->method('execute')->with(array('fakeHash'));
     $mockPdo = $this->getMock('PdoInterface');
     $mockPdo->expects($this->once())->method('prepare')->with('SELECT COUNT(DISTINCT "parent") FROM "properties_data" WHERE "object"=?')->will($this->returnValue($mockStatement));
     $subject = new \stdClass();
     $persistenceSession = new \F3\FLOW3\Persistence\Session();
     $persistenceSession->registerObject($subject, 'fakeHash');
     $backend = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\Persistence\\Backend\\GenericPdo\\Backend'), array('dummy'));
     $backend->injectPersistenceSession($persistenceSession);
     $backend->_set('databaseHandle', $mockPdo);
     $backend->_call('getValueObjectUsageCount', $subject);
 }
 /**
  * @test
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function unregisterObjectRemovesRegisteredObject()
 {
     $object1 = new \stdClass();
     $object2 = new \stdClass();
     $session = new \F3\FLOW3\Persistence\Session();
     $session->registerObject($object1, 12345);
     $session->registerObject($object2, 67890);
     $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('12345'), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('67890'), 'Session claims it does not have registered object.');
     $session->unregisterObject($object1);
     $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
     $this->assertFalse($session->hasIdentifier('12345'), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
     $this->assertTrue($session->hasIdentifier('67890'), 'Session claims it does not have registered object.');
 }
 /**
  * @test
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function persistAllFetchesRemovedObjects()
 {
     $entity1 = new \F3\FLOW3\Tests\Persistence\Fixture\Model\CleanEntity();
     $entity3 = new \F3\FLOW3\Tests\Persistence\Fixture\Model\CleanEntity();
     $repository = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\Persistence\\Repository'), array('dummy'));
     $repository->_set('objectType', get_class($entity1));
     $repository->remove($entity1);
     $mockReflectionService = $this->getMock('F3\\FLOW3\\Reflection\\ReflectionService');
     $mockReflectionService->expects($this->once())->method('getAllImplementationClassNamesForInterface')->with('F3\\FLOW3\\Persistence\\RepositoryInterface')->will($this->returnValue(array('F3\\FLOW3\\Persistence\\Repository')));
     $mockObjectManager = $this->getMock('F3\\FLOW3\\Object\\ObjectManagerInterface');
     $mockObjectManager->expects($this->once())->method('getObject')->with('F3\\FLOW3\\Persistence\\Repository')->will($this->returnValue($repository));
     $session = new \F3\FLOW3\Persistence\Session();
     $session->registerReconstitutedObject($entity1);
     $session->registerReconstitutedObject($entity3);
     $mockBackend = $this->getMock('F3\\FLOW3\\Persistence\\BackendInterface');
     // this is the really important assertion!
     $deletedObjectStorage = new \SplObjectStorage();
     $deletedObjectStorage->attach($entity1);
     $mockBackend->expects($this->once())->method('setDeletedEntities')->with($deletedObjectStorage);
     $manager = new \F3\FLOW3\Persistence\PersistenceManager();
     $manager->injectBackend($mockBackend);
     $manager->injectReflectionService($mockReflectionService);
     $manager->injectPersistenceSession($session);
     $manager->injectObjectManager($mockObjectManager);
     $manager->persistAll();
     $this->assertTrue($session->getReconstitutedObjects()->contains($entity3));
 }