2008-03-05 14:27:46 +03:00
|
|
|
<?php
|
|
|
|
require_once 'lib/DoctrineTestInit.php';
|
|
|
|
|
|
|
|
class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
|
|
|
|
{
|
|
|
|
private $_unitOfWork;
|
|
|
|
private $_user;
|
|
|
|
|
|
|
|
protected function setUp() {
|
2008-05-01 13:41:47 +04:00
|
|
|
parent::setUp();
|
2008-05-17 16:22:24 +04:00
|
|
|
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
|
2008-03-05 14:27:46 +03:00
|
|
|
$this->_user = new ForumUser();
|
2008-05-17 16:22:24 +04:00
|
|
|
$this->_unitOfWork = $em->getUnitOfWork();
|
2008-03-05 14:27:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown() {
|
|
|
|
$this->_user->free();
|
|
|
|
}
|
|
|
|
|
2008-05-01 13:41:47 +04:00
|
|
|
public function testRegisterNew()
|
2008-03-05 14:27:46 +03:00
|
|
|
{
|
2008-05-06 17:41:22 +04:00
|
|
|
$this->_user->username = 'romanb';
|
|
|
|
$this->_user->id = 1;
|
2008-05-01 13:41:47 +04:00
|
|
|
$this->_unitOfWork->registerNew($this->_user);
|
|
|
|
$this->assertFalse($this->_unitOfWork->contains($this->_user));
|
|
|
|
$this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user));
|
|
|
|
$this->assertFalse($this->_unitOfWork->isRegisteredDirty($this->_user));
|
|
|
|
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
2008-03-05 14:27:46 +03:00
|
|
|
}
|
|
|
|
|
2008-05-01 13:41:47 +04:00
|
|
|
public function testRegisterDirty()
|
2008-03-05 14:27:46 +03:00
|
|
|
{
|
2008-05-01 13:41:47 +04:00
|
|
|
$this->_user->username = 'romanb';
|
|
|
|
$this->_user->id = 1;
|
2008-05-14 01:20:34 +04:00
|
|
|
$this->assertEquals(Doctrine_Entity::STATE_TDIRTY, $this->_user->state());
|
2008-05-01 13:41:47 +04:00
|
|
|
$this->assertFalse($this->_unitOfWork->contains($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));
|
2008-05-06 17:41:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRegisterRemovedOnTransientEntityIsIgnored()
|
|
|
|
{
|
|
|
|
$this->_user->username = 'romanb';
|
|
|
|
$this->_user->id = 1;
|
|
|
|
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
|
|
|
$this->_unitOfWork->registerRemoved($this->_user);
|
|
|
|
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
2008-03-05 14:27:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*public function testSavedEntityHasIdentityAndIsManaged()
|
|
|
|
{
|
|
|
|
$this->_user->username = 'romanb';
|
|
|
|
$this->_user->save();
|
|
|
|
$this->assertTrue($this->_unitOfWork->hasIdentity($this->_user));
|
|
|
|
$this->assertTrue($this->_unitOfWork->isManaged($this->_user));
|
|
|
|
}*/
|
|
|
|
}
|