tests with custom inheritance tree
This commit is contained in:
parent
671fd50725
commit
aac523d155
24
tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php
Normal file
24
tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC6303;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc6303_contract")
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({
|
||||
* "contract" = "DDC6303Contract",
|
||||
* "contract_b" = "DDC6303ContractB",
|
||||
* "contract_a" = "DDC6303ContractA"
|
||||
* })
|
||||
*/
|
||||
class DDC6303Contract
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
}
|
17
tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractA.php
Normal file
17
tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractA.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC6303;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc6303_contracts_a")
|
||||
*/
|
||||
class DDC6303ContractA extends DDC6303Contract
|
||||
{
|
||||
/**
|
||||
* @Column(type="string", nullable=true)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $originalData;
|
||||
}
|
17
tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractB.php
Normal file
17
tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractB.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC6303;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc6303_contracts_b")
|
||||
*/
|
||||
class DDC6303ContractB extends DDC6303Contract
|
||||
{
|
||||
/**
|
||||
* @Column(type="simple_array", nullable=true)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $originalData;
|
||||
}
|
56
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php
Normal file
56
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\Models\DDC6303\DDC6303ContractA;
|
||||
use Doctrine\Tests\Models\DDC6303\DDC6303ContractB;
|
||||
use Doctrine\Tests\Models\DDC6303\DDC6303Contract;
|
||||
|
||||
/**
|
||||
* @group DDC6303
|
||||
*/
|
||||
class DDC6303Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('ddc6303');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testMixedTypeHydratedCorrectlyInJoinedInheritance()
|
||||
{
|
||||
$contractA = new DDC6303ContractA();
|
||||
$contractAData = 'authorized';
|
||||
$contractA->originalData = $contractAData;
|
||||
|
||||
$contractB = new DDC6303ContractB();
|
||||
$contractBData = ['accepted', 'authorized'];
|
||||
$contractB->originalData = $contractBData;
|
||||
|
||||
$this->_em->persist($contractA);
|
||||
$this->_em->persist($contractB);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
||||
// instead of just returning the existing managed entities
|
||||
$this->_em->clear();
|
||||
|
||||
$repository = $this->_em->getRepository(DDC6303Contract::class);
|
||||
|
||||
$contracts = $repository->createQueryBuilder('p')
|
||||
->getQuery()->getResult();
|
||||
|
||||
foreach( $contracts as $contract ){
|
||||
switch( $contract->id ){
|
||||
case $contractA->id:
|
||||
static::assertEquals($contract->originalData, $contractAData);
|
||||
break;
|
||||
|
||||
case $contractB->id:
|
||||
static::assertEquals($contract->originalData, $contractBData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -312,6 +312,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
Models\Issue5989\Issue5989Employee::class,
|
||||
Models\Issue5989\Issue5989Manager::class,
|
||||
],
|
||||
'ddc6303' => [
|
||||
Models\DDC6303\DDC6303Contract::class,
|
||||
Models\DDC6303\DDC6303ContractA::class,
|
||||
Models\DDC6303\DDC6303ContractB::class,
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user