Changeset 4699 for trunk/tests/Orm
- Timestamp:
- 07/20/08 21:13:24 (6 months ago)
- Location:
- trunk/tests/Orm
- Files:
-
- 3 added
- 4 modified
-
Associations (added)
-
Associations/CascadeTest.php (added)
-
Associations/OneToOneMappingTest.php (added)
-
Component/CollectionTest.php (modified) (3 diffs)
-
Entity/AccessorTest.php (modified) (2 diffs)
-
Entity/ConstructorTest.php (modified) (1 diff)
-
UnitOfWorkTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/Orm/Component/CollectionTest.php
r4523 r4699 107 107 * @test 108 108 */ 109 public function shouldSetKeyColumnWhenAddingNewRowAsArray()109 /*public function shouldSetKeyColumnWhenAddingNewRowAsArray() 110 110 { 111 111 $this->assertTrue(isset($this->cmsColl['test'])); 112 112 $this->assertEquals($this->cmsUser, $this->cmsColl['test']); 113 } 113 }*/ 114 114 115 115 … … 117 117 * @test 118 118 */ 119 public function shouldSerializeAndUnserializeCollectionWithData()119 /*public function shouldSerializeAndUnserializeCollectionWithData() 120 120 { 121 121 $serialized = serialize($this->cmsColl); … … 127 127 $this->assertTrue($user instanceOf CmsUser); 128 128 $this->assertEquals('test', $user['username']); 129 } 129 }*/ 130 130 131 131 } -
trunk/tests/Orm/Entity/AccessorTest.php
r4655 r4699 23 23 class CustomAccessorMutatorTestEntity extends Doctrine_Entity 24 24 { 25 public static function initMetadata($ class)25 public static function initMetadata($mapping) 26 26 { 27 $class->mapColumn('id', 'integer', 4, array('primary')); 28 $class->mapColumn('username', 'string', 50, array( 29 'accessor' => 'getUsernameCustom', 30 'mutator' => 'setUsernameCustom')); 27 $mapping->mapField(array( 28 'fieldName' => 'id', 29 'type' => 'integer', 30 'length' => 4, 31 'id' => true 32 )); 33 $mapping->mapField(array( 34 'fieldName' => 'username', 35 'type' => 'string', 36 'length' => 50, 37 'accessor' => 'getUsernameCustom', 38 'mutator' => 'setUsernameCustom' 39 )); 31 40 } 32 41 … … 44 53 class MagicAccessorMutatorTestEntity extends Doctrine_Entity 45 54 { 46 public static function initMetadata($ class)55 public static function initMetadata($mapping) 47 56 { 48 $class->mapColumn('id', 'integer', 4, array('primary')); 49 $class->mapColumn('username', 'string', 50, array()); 57 $mapping->mapField(array( 58 'fieldName' => 'id', 59 'type' => 'integer', 60 'length' => 4, 61 'id' => true 62 )); 63 $mapping->mapField(array( 64 'fieldName' => 'username', 65 'type' => 'string', 66 'length' => 50 67 )); 50 68 } 51 69 -
trunk/tests/Orm/Entity/ConstructorTest.php
r4653 r4699 23 23 24 24 /* The mapping definition */ 25 public static function initMetadata($ class)25 public static function initMetadata($mapping) 26 26 { 27 $class->mapColumn('id', 'integer', 4, array('primary')); 28 $class->mapColumn('username', 'string', 50, array()); 27 $mapping->mapField(array( 28 'fieldName' => 'id', 29 'type' => 'integer', 30 'length' => 4, 31 'id' => true 32 )); 33 $mapping->mapField(array( 34 'fieldName' => 'username', 35 'type' => 'string', 36 'length' => 50 37 )); 29 38 } 30 39 } -
trunk/tests/Orm/UnitOfWorkTest.php
r4628 r4699 1 1 <?php 2 2 require_once 'lib/DoctrineTestInit.php'; 3 3 require_once 'lib/mocks/Doctrine_EntityManagerMock.php'; 4 require_once 'lib/mocks/Doctrine_ConnectionMock.php'; 5 6 /** 7 * UnitOfWork tests. 8 * These tests run without a database through mocking the 9 * persister/connection/sequence used by the UnitOfWork. 10 */ 4 11 class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase 5 12 { … … 7 14 private $_user; 8 15 16 // Mocks 17 18 // Provides a sequence mock to the UnitOfWork 19 private $_connectionMock; 20 // The sequence mock 21 private $_sequenceMock; 22 // The persister mock used by the UnitOfWork 23 private $_persisterMock; 24 // The EntityManager mock that provides the mock persister 25 private $_emMock; 26 9 27 protected function setUp() { 10 28 parent::setUp(); 29 11 30 $this->_user = new ForumUser(); 12 $this->_unitOfWork = new Doctrine_Connection_UnitOfWork($this->_em); 31 $this->_user->id = 1; 32 $this->_user->username = 'romanb'; 33 34 $this->_connectionMock = new Doctrine_ConnectionMock(array()); 35 $this->_sequenceMock = $this->_connectionMock->getSequenceModule(); 36 $this->_emMock = new Doctrine_EntityManagerMock($this->_connectionMock); 37 $this->_persisterMock = $this->_emMock->getEntityPersister("ForumUser"); 38 $this->_unitOfWork = $this->_emMock->getUnitOfWork(); 13 39 } 14 40 … … 17 43 } 18 44 45 /* Basic registration tests */ 46 19 47 public function testRegisterNew() 20 48 { 21 $this->_user->username = 'romanb';22 $this->_user->id = 1;23 49 // registerNew() is normally called in save()/persist() 24 50 $this->_unitOfWork->registerNew($this->_user); 25 51 $this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user)); 26 $this->assertTrue($this->_unitOfWork-> contains($this->_user));52 $this->assertTrue($this->_unitOfWork->isInIdentityMap($this->_user)); 27 53 $this->assertFalse($this->_unitOfWork->isRegisteredDirty($this->_user)); 28 54 $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); 29 55 } 30 56 57 /*public function testRegisterNewPerf() { 58 $s = microtime(true); 59 60 for ($i=1; $i<40000; $i++) { 61 $user = new ForumUser(); 62 $user->id = $i; 63 $this->_unitOfWork->registerNew($user); 64 } 65 $e = microtime(true); 66 67 echo $e - $s . " seconds" . PHP_EOL; 68 }*/ 69 31 70 public function testRegisterDirty() 32 71 { 33 $this->_user->username = 'romanb'; 34 $this->_user->id = 1; 35 $this->assertEquals(Doctrine_Entity::STATE_TDIRTY, $this->_user->_state()); 36 $this->assertFalse($this->_unitOfWork->contains($this->_user)); 72 $this->assertEquals(Doctrine_Entity::STATE_NEW, $this->_user->_state()); 73 $this->assertFalse($this->_unitOfWork->isInIdentityMap($this->_user)); 37 74 $this->_unitOfWork->registerDirty($this->_user); 38 75 $this->assertTrue($this->_unitOfWork->isRegisteredDirty($this->_user)); … … 41 78 } 42 79 43 public function testRegisterRemovedOn TransientEntityIsIgnored()80 public function testRegisterRemovedOnNewEntityIsIgnored() 44 81 { 45 $this->_user->username = 'romanb';46 $this->_user->id = 1;47 82 $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); 48 $this->_unitOfWork->register Removed($this->_user);83 $this->_unitOfWork->registerDeleted($this->_user); 49 84 $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); 50 85 } 51 86 52 /*public function testSavedEntityHasIdentityAndIsManaged() 87 88 /* Operational tests */ 89 90 public function testSavingSingleEntityWithIdentityColumnForcesInsert() 53 91 { 54 $this->_user->username = 'romanb'; 55 $this->_user->save(); 56 $this->assertTrue($this->_unitOfWork->hasIdentity($this->_user)); 57 $this->assertTrue($this->_unitOfWork->isManaged($this->_user)); 58 }*/ 92 $this->assertEquals(Doctrine_Entity::STATE_NEW, $this->_user->_state()); 93 94 $this->_unitOfWork->save($this->_user); 95 96 $this->assertEquals(1, count($this->_persisterMock->getInserts())); // insert forced 97 $this->assertEquals(0, count($this->_persisterMock->getUpdates())); 98 $this->assertEquals(0, count($this->_persisterMock->getDeletes())); 99 100 $this->assertTrue($this->_unitOfWork->isInIdentityMap($this->_user)); 101 $this->assertEquals(Doctrine_Entity::STATE_MANAGED, $this->_user->_state()); 102 103 // should no longer be scheduled for insert 104 $this->assertFalse($this->_unitOfWork->isRegisteredNew($this->_user)); 105 // should have an id 106 $this->assertTrue(is_numeric($this->_user->id)); 107 108 // Now lets check whether a subsequence commit() does anything 109 110 $this->_persisterMock->reset(); 111 112 $this->_unitOfWork->commit(); // shouldnt do anything 113 114 // verify that nothing happened 115 $this->assertEquals(0, count($this->_persisterMock->getInserts())); 116 $this->assertEquals(0, count($this->_persisterMock->getUpdates())); 117 $this->assertEquals(0, count($this->_persisterMock->getDeletes())); 118 } 119 120 public function testSavingSingleEntityWithSequenceIdGeneratorSchedulesInsert() 121 { 122 //... 123 } 124 125 public function testSavingSingleEntityWithTableIdGeneratorSchedulesInsert() 126 { 127 //... 128 } 129 130 public function testSavingSingleEntityWithSingleNaturalIdForcesInsert() 131 { 132 //... 133 } 134 135 public function testSavingSingleEntityWithCompositeIdForcesInsert() 136 { 137 //... 138 } 139 140 public function testSavingEntityGraphWithIdentityColumnsForcesInserts() 141 { 142 //... 143 } 144 145 public function testSavingEntityGraphWithSequencesDelaysInserts() 146 { 147 //... 148 } 149 150 public function testSavingEntityGraphWithNaturalIdsForcesInserts() 151 { 152 //... 153 } 154 155 public function testSavingEntityGraphWithMixedIdGenerationStrategies() 156 { 157 //... 158 } 159 59 160 }