inheritance with composite keys
added tests for single table inheritance
This commit is contained in:
parent
fb055ca75d
commit
86c33d78d0
4 changed files with 113 additions and 0 deletions
|
@ -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';
|
||||
}
|
|
@ -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';
|
||||
}
|
|
@ -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')
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue