1
0
mirror of synced 2024-12-15 23:56:02 +03:00
doctrine2/tests/Orm/Entity/AccessorTest.php

61 lines
1.6 KiB
PHP
Raw Normal View History

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