parent
aaad25a061
commit
f6ce69fe29
@ -2,109 +2,120 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\SchemaException;
|
||||||
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC6303
|
* @group #6303
|
||||||
*/
|
*/
|
||||||
class DDC6303Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
class DDC6303Test extends OrmFunctionalTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
try {
|
try {
|
||||||
$this->_schemaTool->createSchema(
|
$this->_schemaTool->createSchema([
|
||||||
[
|
|
||||||
$this->_em->getClassMetadata(DDC6303Contract::class),
|
$this->_em->getClassMetadata(DDC6303Contract::class),
|
||||||
$this->_em->getClassMetadata(DDC6303ContractA::class),
|
$this->_em->getClassMetadata(DDC6303ContractA::class),
|
||||||
$this->_em->getClassMetadata(DDC6303ContractB::class)
|
$this->_em->getClassMetadata(DDC6303ContractB::class),
|
||||||
]
|
]);
|
||||||
);
|
} catch (SchemaException $ignored) {
|
||||||
} catch (\Exception $ignored) {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMixedTypeHydratedCorrectlyInJoinedInheritance()
|
public function testMixedTypeHydratedCorrectlyInJoinedInheritance()
|
||||||
{
|
{
|
||||||
$contractA = new DDC6303ContractA();
|
$contractA = new DDC6303ContractA();
|
||||||
$contractAData = 'authorized';
|
$contractAData = 'authorized';
|
||||||
$contractA->originalData = $contractAData;
|
$contractA->originalData = $contractAData;
|
||||||
|
|
||||||
$contractB = new DDC6303ContractB();
|
$contractB = new DDC6303ContractB();
|
||||||
//contractA and contractB have an inheritance from Contract, but one has a string originalData and the second has an array
|
//contractA and contractB have an inheritance from Contract, but one has a string originalData and the second has an array
|
||||||
$contractBData = ['accepted', 'authorized'];
|
$contractBData = ['accepted', 'authorized'];
|
||||||
$contractB->originalData = $contractBData;
|
$contractB->originalData = $contractBData;
|
||||||
|
|
||||||
$this->_em->persist($contractA);
|
$this->_em->persist($contractA);
|
||||||
$this->_em->persist($contractB);
|
$this->_em->persist($contractB);
|
||||||
|
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
||||||
// instead of just returning the existing managed entities
|
// instead of just returning the existing managed entities
|
||||||
$this->_em->clear();
|
$this->_em->clear();
|
||||||
|
|
||||||
$repository = $this->_em->getRepository(DDC6303Contract::class);
|
$repository = $this->_em->getRepository(DDC6303Contract::class);
|
||||||
|
|
||||||
$dataMap = [
|
$dataMap = [
|
||||||
$contractA->id => $contractAData,
|
$contractA->id => $contractAData,
|
||||||
$contractB->id => $contractBData
|
$contractB->id => $contractBData,
|
||||||
];
|
];
|
||||||
|
|
||||||
$contracts = $repository->createQueryBuilder('p')
|
$contracts = $repository
|
||||||
|
->createQueryBuilder('p')
|
||||||
->where('p.id IN(:ids)')
|
->where('p.id IN(:ids)')
|
||||||
->setParameter('ids', array_keys($dataMap))
|
->setParameter('ids', array_keys($dataMap))
|
||||||
->getQuery()->getResult();
|
->getQuery()->getResult();
|
||||||
|
|
||||||
foreach( $contracts as $contract ){
|
foreach ($contracts as $contract) {
|
||||||
static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original');
|
static::assertEquals(
|
||||||
|
$contract->originalData,
|
||||||
|
$dataMap[$contract->id],
|
||||||
|
'contract ' . get_class($contract) . ' not equals to original'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyValuesInJoinedInheritance()
|
public function testEmptyValuesInJoinedInheritance()
|
||||||
{
|
{
|
||||||
$contractStringEmptyData = '';
|
$contractStringEmptyData = '';
|
||||||
$contractStringZeroData = 0;
|
$contractStringZeroData = 0;
|
||||||
$contractArrayEmptyData = [];
|
$contractArrayEmptyData = [];
|
||||||
|
|
||||||
$contractStringEmpty = new DDC6303ContractA();
|
$contractStringEmpty = new DDC6303ContractA();
|
||||||
|
$contractStringZero = new DDC6303ContractA();
|
||||||
|
$contractArrayEmpty = new DDC6303ContractB();
|
||||||
|
|
||||||
$contractStringEmpty->originalData = $contractStringEmptyData;
|
$contractStringEmpty->originalData = $contractStringEmptyData;
|
||||||
|
$contractStringZero->originalData = $contractStringZeroData;
|
||||||
$contractStringZero = new DDC6303ContractA();
|
$contractArrayEmpty->originalData = $contractArrayEmptyData;
|
||||||
$contractStringZero->originalData = $contractStringZeroData;
|
|
||||||
|
|
||||||
$contractArrayEmpty = new DDC6303ContractB();
|
|
||||||
$contractArrayEmpty->originalData = $contractArrayEmptyData;
|
|
||||||
|
|
||||||
$this->_em->persist($contractStringZero);
|
$this->_em->persist($contractStringZero);
|
||||||
$this->_em->persist($contractStringEmpty);
|
$this->_em->persist($contractStringEmpty);
|
||||||
$this->_em->persist($contractArrayEmpty);
|
$this->_em->persist($contractArrayEmpty);
|
||||||
|
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
||||||
// instead of just returning the existing managed entities
|
// instead of just returning the existing managed entities
|
||||||
$this->_em->clear();
|
$this->_em->clear();
|
||||||
|
|
||||||
$repository = $this->_em->getRepository(DDC6303Contract::class);
|
$repository = $this->_em->getRepository(DDC6303Contract::class);
|
||||||
$dataMap = [
|
$dataMap = [
|
||||||
$contractStringZero->id => $contractStringZeroData,
|
$contractStringZero->id => $contractStringZeroData,
|
||||||
$contractStringEmpty->id => $contractStringEmptyData,
|
$contractStringEmpty->id => $contractStringEmptyData,
|
||||||
$contractArrayEmpty->id => $contractArrayEmptyData,
|
$contractArrayEmpty->id => $contractArrayEmptyData,
|
||||||
];
|
];
|
||||||
|
|
||||||
$contracts = $repository->createQueryBuilder('p')
|
$contracts = $repository
|
||||||
|
->createQueryBuilder('p')
|
||||||
->where('p.id IN(:ids)')
|
->where('p.id IN(:ids)')
|
||||||
->setParameter('ids', array_keys($dataMap))
|
->setParameter('ids', array_keys($dataMap))
|
||||||
->getQuery()->getResult();
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
foreach( $contracts as $contract ){
|
foreach ($contracts as $contract) {
|
||||||
static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original');
|
static::assertEquals(
|
||||||
|
$contract->originalData,
|
||||||
|
$dataMap[$contract->id],
|
||||||
|
'contract ' . get_class($contract) . ' not equals to original'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
* @Table(name="ddc6303_contract")
|
* @Table
|
||||||
* @InheritanceType("JOINED")
|
* @InheritanceType("JOINED")
|
||||||
* @DiscriminatorColumn(name="discr", type="string")
|
* @DiscriminatorColumn(name="discr", type="string")
|
||||||
* @DiscriminatorMap({
|
* @DiscriminatorMap({
|
||||||
@ -115,40 +126,20 @@ class DDC6303Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
*/
|
*/
|
||||||
class DDC6303Contract
|
class DDC6303Contract
|
||||||
{
|
{
|
||||||
/**
|
/** @Id @Column(type="integer") @GeneratedValue */
|
||||||
* @Id
|
|
||||||
* @Column(type="integer")
|
|
||||||
* @GeneratedValue
|
|
||||||
*/
|
|
||||||
public $id;
|
public $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @Entity @Table */
|
||||||
/**
|
|
||||||
* @Entity
|
|
||||||
* @Table(name="ddc6303_contracts_a")
|
|
||||||
*/
|
|
||||||
class DDC6303ContractA extends DDC6303Contract
|
class DDC6303ContractA extends DDC6303Contract
|
||||||
{
|
{
|
||||||
/**
|
/** @Column(type="string", nullable=true) */
|
||||||
* @Column(type="string", nullable=true)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $originalData;
|
public $originalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @Entity @Table */
|
||||||
/**
|
|
||||||
* @Entity
|
|
||||||
* @Table(name="ddc6303_contracts_b")
|
|
||||||
*/
|
|
||||||
class DDC6303ContractB extends DDC6303Contract
|
class DDC6303ContractB extends DDC6303Contract
|
||||||
{
|
{
|
||||||
/**
|
/** @Column(type="simple_array", nullable=true) */
|
||||||
* @Column(type="simple_array", nullable=true)
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $originalData;
|
public $originalData;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user