1
0
Fork 0
mirror of synced 2025-04-01 20:36:14 +03:00

inheritance with composite keys

added tests for single table inheritance
This commit is contained in:
Thomas Rothe 2012-12-17 11:01:20 +01:00
parent fb055ca75d
commit 86c33d78d0
4 changed files with 113 additions and 0 deletions

View file

@ -0,0 +1,21 @@
<?php
namespace Doctrine\Tests\Models\CompositeKeyInheritance;
/**
* @Entity
*/
class SingleChildClass extends SingleRootClass
{
/**
* @var string
* @Column(type="string")
*/
public $extension = 'ext';
/**
* @var string
* @Column(type="string")
* @Id
*/
private $additionalId = 'additional';
}

View file

@ -0,0 +1,25 @@
<?php
namespace Doctrine\Tests\Models\CompositeKeyInheritance;
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"child" = "SingleChildClass",})
*/
class SingleRootClass
{
/**
* @var string
* @Column(type="string")
* @Id
*/
protected $keyPart1 = 'part-1';
/**
* @var string
* @Column(type="string")
* @Id
*/
protected $keyPart2 = 'part-2';
}

View file

@ -0,0 +1,64 @@
<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\Tests\Models\CompositeKeyInheritance\SingleChildClass;
class SingleTableCompositeKeyTest extends OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('compositekeyinheritance');
parent::setUp();
}
/**
*
*/
public function testInsertWithCompositeKey()
{
$childEntity = new SingleChildClass();
$this->_em->persist($childEntity);
$this->_em->flush();
$this->_em->clear();
$entity = $this->findEntity();
$this->assertEquals($childEntity, $entity);
}
/**
*
*/
public function testUpdateWithCompositeKey()
{
$childEntity = new SingleChildClass();
$this->_em->persist($childEntity);
$this->_em->flush();
$this->_em->clear();
$entity = $this->findEntity();
$entity->extension = 'ext-new';
$this->_em->persist($entity);
$this->_em->flush();
$this->_em->clear();
$persistedEntity = $this->findEntity();
$this->assertEquals($entity, $persistedEntity);
}
/**
* @return \Doctrine\Tests\Models\CompositeKeyInheritance\JoinedChildClass
*/
private function findEntity()
{
return $this->_em->find(
'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass',
array('keyPart1' => 'part-1', 'keyPart2' => 'part-2')
);
}
}

View file

@ -127,6 +127,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
'compositekeyinheritance' => array(
'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedRootClass',
'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedChildClass',
'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass',
'Doctrine\Tests\Models\CompositeKeyInheritance\SingleChildClass',
)
);
@ -246,6 +248,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
if (isset($this->_usedModelSets['compositekeyinheritance'])) {
$conn->executeUpdate('DELETE FROM JoinedChildClass');
$conn->executeUpdate('DELETE FROM JoinedRootClass');
$conn->executeUpdate('DELETE FROM SingleRootClass');
}