2009-11-06 13:28:37 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Id;
|
|
|
|
|
2010-03-31 01:14:17 +04:00
|
|
|
use Doctrine\ORM\Id\AssignedGenerator;
|
2009-11-06 13:28:37 +03:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
/**
|
2010-03-31 01:14:17 +04:00
|
|
|
* AssignedGeneratorTest
|
2009-11-06 13:28:37 +03:00
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
*/
|
2010-03-31 01:14:17 +04:00
|
|
|
class AssignedGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
2009-11-06 13:28:37 +03:00
|
|
|
{
|
|
|
|
private $_em;
|
|
|
|
private $_assignedGen;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->_em = $this->_getTestEntityManager();
|
2010-03-31 01:14:17 +04:00
|
|
|
$this->_assignedGen = new AssignedGenerator;
|
2009-11-06 13:28:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testThrowsExceptionIfIdNotAssigned()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$entity = new AssignedSingleIdEntity;
|
|
|
|
$this->_assignedGen->generate($this->_em, $entity);
|
|
|
|
$this->fail('Assigned generator did not throw exception even though ID was missing.');
|
|
|
|
} catch (\Doctrine\ORM\ORMException $expected) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$entity = new AssignedCompositeIdEntity;
|
|
|
|
$this->_assignedGen->generate($this->_em, $entity);
|
|
|
|
$this->fail('Assigned generator did not throw exception even though ID was missing.');
|
|
|
|
} catch (\Doctrine\ORM\ORMException $expected) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCorrectIdGeneration()
|
|
|
|
{
|
|
|
|
$entity = new AssignedSingleIdEntity;
|
|
|
|
$entity->myId = 1;
|
|
|
|
$id = $this->_assignedGen->generate($this->_em, $entity);
|
2009-11-26 00:48:04 +03:00
|
|
|
$this->assertEquals(array('myId' => 1), $id);
|
2009-11-06 13:28:37 +03:00
|
|
|
|
|
|
|
$entity = new AssignedCompositeIdEntity;
|
|
|
|
$entity->myId2 = 2;
|
|
|
|
$entity->myId1 = 4;
|
|
|
|
$id = $this->_assignedGen->generate($this->_em, $entity);
|
2009-11-26 00:48:04 +03:00
|
|
|
$this->assertEquals(array('myId1' => 4, 'myId2' => 2), $id);
|
2009-11-06 13:28:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class AssignedSingleIdEntity {
|
|
|
|
/** @Id @Column(type="integer") */
|
|
|
|
public $myId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class AssignedCompositeIdEntity {
|
|
|
|
/** @Id @Column(type="integer") */
|
|
|
|
public $myId1;
|
|
|
|
/** @Id @Column(type="integer") */
|
|
|
|
public $myId2;
|
|
|
|
}
|