1
0
mirror of synced 2025-01-19 06:51:40 +03:00
doctrine2/tests/Orm/Entity/AccessorTest.php
2008-07-11 10:48:04 +00:00

61 lines
1.6 KiB
PHP

<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_Entity_AccessorTest extends Doctrine_OrmTestCase
{
public function testGetterSetterOverride()
{
$entity1 = new CustomAccessorMutatorTestEntity();
$entity1->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username);
$entity2 = new MagicAccessorMutatorTestEntity();
$entity2->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username);
}
}
/* Local test classes */
class CustomAccessorMutatorTestEntity extends Doctrine_Entity
{
public static function initMetadata($class)
{
$class->mapColumn('id', 'integer', 4, array('primary'));
$class->mapColumn('username', 'string', 50, array(
'accessor' => 'getUsernameCustom',
'mutator' => 'setUsernameCustom'));
}
public function getUsernameCustom()
{
return $this->_rawGetField('username') . "!";
}
public function setUsernameCustom($username)
{
$this->_rawSetField('username', $username . "?");
}
}
class MagicAccessorMutatorTestEntity extends Doctrine_Entity
{
public static function initMetadata($class)
{
$class->mapColumn('id', 'integer', 4, array('primary'));
$class->mapColumn('username', 'string', 50, array());
}
public function getUsername()
{
return $this->_rawGetField('username') . "!";
}
public function setUsername($username)
{
$this->_rawSetField('username', $username . "?");
}
}