1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/tests/Orm/Entity/AccessorTestCase.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2008-05-26 00:57:32 +04:00
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase
{
public function testGetterSetterOverride()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$entity1 = new CustomAccessorMutatorTestEntity();
$entity1->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username);
$entity2 = new MagicAccessorMutatorTestEntity();
$entity2->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username);
}
}
class CustomAccessorMutatorTestEntity extends Doctrine_Entity
{
public static function initMetadata($class)
{
$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('username', 'string', 50, array());
}
public function getUsername()
{
return $this->rawGetField('username') . "!";
}
public function setUsername($username)
{
$this->rawSetField('username', $username . "?");
}
}