Changeset 4699 for trunk/tests/Orm

Show
Ignore:
Timestamp:
07/20/08 21:13:24 (6 months ago)
Author:
romanb
Message:

Checkin of occasional work from the past weeks.

Location:
trunk/tests/Orm
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/Orm/Component/CollectionTest.php

    r4523 r4699  
    107107     * @test  
    108108     */ 
    109     public function shouldSetKeyColumnWhenAddingNewRowAsArray() 
     109    /*public function shouldSetKeyColumnWhenAddingNewRowAsArray() 
    110110    { 
    111111        $this->assertTrue(isset($this->cmsColl['test'])); 
    112112        $this->assertEquals($this->cmsUser,  $this->cmsColl['test']); 
    113     } 
     113    }*/ 
    114114 
    115115 
     
    117117     * @test 
    118118     */ 
    119     public function shouldSerializeAndUnserializeCollectionWithData() 
     119    /*public function shouldSerializeAndUnserializeCollectionWithData() 
    120120    { 
    121121        $serialized = serialize($this->cmsColl); 
     
    127127        $this->assertTrue($user instanceOf CmsUser); 
    128128        $this->assertEquals('test', $user['username']); 
    129     } 
     129    }*/ 
    130130 
    131131} 
  • trunk/tests/Orm/Entity/AccessorTest.php

    r4655 r4699  
    2323class CustomAccessorMutatorTestEntity extends Doctrine_Entity 
    2424{ 
    25     public static function initMetadata($class)  
     25    public static function initMetadata($mapping)  
    2626    { 
    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        )); 
    3140    } 
    3241     
     
    4453class MagicAccessorMutatorTestEntity extends Doctrine_Entity 
    4554{ 
    46     public static function initMetadata($class)  
     55    public static function initMetadata($mapping)  
    4756    { 
    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        )); 
    5068    } 
    5169     
  • trunk/tests/Orm/Entity/ConstructorTest.php

    r4653 r4699  
    2323     
    2424    /* The mapping definition */ 
    25     public static function initMetadata($class)  
     25    public static function initMetadata($mapping)  
    2626    { 
    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        )); 
    2938    } 
    3039} 
  • trunk/tests/Orm/UnitOfWorkTest.php

    r4628 r4699  
    11<?php 
    22require_once 'lib/DoctrineTestInit.php'; 
    3   
     3require_once 'lib/mocks/Doctrine_EntityManagerMock.php'; 
     4require_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 */ 
    411class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase 
    512{ 
     
    714    private $_user; 
    815     
     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     
    927    protected function setUp() { 
    1028        parent::setUp(); 
     29         
    1130        $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(); 
    1339    } 
    1440     
     
    1743    } 
    1844     
     45    /* Basic registration tests */ 
     46     
    1947    public function testRegisterNew() 
    2048    { 
    21         $this->_user->username = 'romanb'; 
    22         $this->_user->id = 1; 
    2349        // registerNew() is normally called in save()/persist() 
    2450        $this->_unitOfWork->registerNew($this->_user); 
    2551        $this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user)); 
    26         $this->assertTrue($this->_unitOfWork->contains($this->_user)); 
     52        $this->assertTrue($this->_unitOfWork->isInIdentityMap($this->_user)); 
    2753        $this->assertFalse($this->_unitOfWork->isRegisteredDirty($this->_user)); 
    2854        $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); 
    2955    } 
    3056     
     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     
    3170    public function testRegisterDirty() 
    3271    { 
    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)); 
    3774        $this->_unitOfWork->registerDirty($this->_user); 
    3875        $this->assertTrue($this->_unitOfWork->isRegisteredDirty($this->_user)); 
     
    4178    } 
    4279     
    43     public function testRegisterRemovedOnTransientEntityIsIgnored() 
     80    public function testRegisterRemovedOnNewEntityIsIgnored() 
    4481    { 
    45         $this->_user->username = 'romanb'; 
    46         $this->_user->id = 1; 
    4782        $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user)); 
    48         $this->_unitOfWork->registerRemoved($this->_user); 
     83        $this->_unitOfWork->registerDeleted($this->_user); 
    4984        $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));         
    5085    } 
    5186     
    52     /*public function testSavedEntityHasIdentityAndIsManaged() 
     87     
     88    /* Operational tests */ 
     89     
     90    public function testSavingSingleEntityWithIdentityColumnForcesInsert() 
    5391    { 
    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     
    59160}