_user = new ForumUser(); $this->_user->id = 1; $this->_user->username = 'romanb'; $this->_connectionMock = new Doctrine_ConnectionMock(array()); $this->_platformMock = new Doctrine_DatabasePlatformMock(); $this->_emMock = new Doctrine_EntityManagerMock($this->_connectionMock); $this->_sequenceMock = new Doctrine_SequenceMock($this->_connectionMock); $this->_connectionMock->setSequenceManager($this->_sequenceMock); $this->_connectionMock->setDatabasePlatform($this->_platformMock); $this->_persisterMock = new Doctrine_EntityPersisterMock( $this->_emMock, $this->_emMock->getClassMetadata("ForumUser")); $this->_emMock->setEntityPersister($this->_persisterMock); $this->_unitOfWork = $this->_emMock->getUnitOfWork(); } protected function tearDown() { $this->_user->free(); } /* Basic registration tests */ public function testRegisterNew() { // registerNew() is normally called in save()/persist() $this->_unitOfWork->registerNew($this->_user); $this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user)); $this->assertTrue($this->_unitOfWork->isInIdentityMap($this->_user)); $this->assertFalse($this->_unitOfWork->isRegisteredDirty($this->_user)); $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); } /*public function testRegisterNewPerf() { $s = microtime(true); for ($i=1; $i<40000; $i++) { $user = new ForumUser(); $user->id = $i; $this->_unitOfWork->registerNew($user); } $e = microtime(true); echo $e - $s . " seconds" . PHP_EOL; }*/ public function testRegisterDirty() { $this->assertEquals(Doctrine_Entity::STATE_NEW, $this->_user->_state()); $this->assertFalse($this->_unitOfWork->isInIdentityMap($this->_user)); $this->_unitOfWork->registerDirty($this->_user); $this->assertTrue($this->_unitOfWork->isRegisteredDirty($this->_user)); $this->assertFalse($this->_unitOfWork->isRegisteredNew($this->_user)); $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); } public function testRegisterRemovedOnNewEntityIsIgnored() { $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); $this->_unitOfWork->registerDeleted($this->_user); $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); } /* Operational tests */ public function testSavingSingleEntityWithIdentityColumnForcesInsert() { $this->assertEquals(Doctrine_Entity::STATE_NEW, $this->_user->_state()); $this->_unitOfWork->save($this->_user); $this->assertEquals(1, count($this->_persisterMock->getInserts())); // insert forced $this->assertEquals(0, count($this->_persisterMock->getUpdates())); $this->assertEquals(0, count($this->_persisterMock->getDeletes())); $this->assertTrue($this->_unitOfWork->isInIdentityMap($this->_user)); $this->assertEquals(Doctrine_Entity::STATE_MANAGED, $this->_user->_state()); // should no longer be scheduled for insert $this->assertFalse($this->_unitOfWork->isRegisteredNew($this->_user)); // should have an id $this->assertTrue(is_numeric($this->_user->id)); // Now lets check whether a subsequent commit() does anything $this->_persisterMock->reset(); $this->_unitOfWork->commit(); // shouldnt do anything // verify that nothing happened $this->assertEquals(0, count($this->_persisterMock->getInserts())); $this->assertEquals(0, count($this->_persisterMock->getUpdates())); $this->assertEquals(0, count($this->_persisterMock->getDeletes())); } public function testSavingSingleEntityWithSequenceIdGeneratorSchedulesInsert() { //... } public function testSavingSingleEntityWithTableIdGeneratorSchedulesInsert() { //... } public function testSavingSingleEntityWithSingleNaturalIdForcesInsert() { //... } public function testSavingSingleEntityWithCompositeIdForcesInsert() { //... } public function testSavingEntityGraphWithIdentityColumnsForcesInserts() { //... } public function testSavingEntityGraphWithSequencesDelaysInserts() { //... } public function testSavingEntityGraphWithNaturalIdsForcesInserts() { //... } public function testSavingEntityGraphWithMixedIdGenerationStrategies() { //... } }