1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php

100 lines
2.9 KiB
PHP
Raw Normal View History

2009-12-07 23:35:44 +03:00
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
require_once __DIR__ . '/../../../TestInit.php';
class DDC199Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ParentClass'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ChildClass'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199RelatedClass')
));
}
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
public function testPolymorphicLoading()
{
$child = new DDC199ChildClass;
$child->parentData = 'parentData';
$child->childData = 'childData';
$this->_em->persist($child);
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
$related1 = new DDC199RelatedClass;
$related1->relatedData = 'related1';
$related1->parent = $child;
$this->_em->persist($related1);
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
$related2 = new DDC199RelatedClass;
$related2->relatedData = 'related2';
$related2->parent = $child;
$this->_em->persist($related2);
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
$this->_em->flush();
$this->_em->clear();
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
$query = $this->_em->createQuery('select e,r from Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass e join e.relatedEntities r');
$result = $query->getResult();
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
$this->assertEquals(1, count($result));
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass', $result[0]);
2009-12-07 23:35:44 +03:00
$this->assertTrue($result[0]->relatedEntities->isInitialized());
$this->assertEquals(2, $result[0]->relatedEntities->count());
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[0]);
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[1]);
2009-12-07 23:35:44 +03:00
}
}
/**
* @Entity @Table(name="ddc199_entities")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"parent" = "DDC199ParentClass", "child" = "DDC199ChildClass"})
*/
class DDC199ParentClass
2011-12-20 01:56:19 +04:00
{
2009-12-07 23:35:44 +03:00
/**
2011-12-20 01:56:19 +04:00
* @Id @Column(type="integer")
2009-12-07 23:35:44 +03:00
* @GeneratedValue(strategy="AUTO")
*/
public $id;
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
/**
* @Column(type="string")
*/
public $parentData;
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
/**
* @OneToMany(targetEntity="DDC199RelatedClass", mappedBy="parent")
*/
public $relatedEntities;
}
/** @Entity */
class DDC199ChildClass extends DDC199ParentClass
{
/**
2010-04-10 02:00:36 +04:00
* @Column
2009-12-07 23:35:44 +03:00
*/
public $childData;
}
/** @Entity @Table(name="ddc199_relatedclass") */
2009-12-07 23:35:44 +03:00
class DDC199RelatedClass
{
2010-04-10 02:00:36 +04:00
/** @Id @Column(type="integer") @GeneratedValue */
2009-12-07 23:35:44 +03:00
public $id;
2010-04-10 02:00:36 +04:00
/** @Column */
2009-12-07 23:35:44 +03:00
public $relatedData;
2011-12-20 01:56:19 +04:00
2009-12-07 23:35:44 +03:00
/**
2010-04-10 02:00:36 +04:00
* @ManyToOne(targetEntity="DDC199ParentClass", inversedBy="relatedEntities")
2009-12-07 23:35:44 +03:00
* @JoinColumn(name="parent_id", referencedColumnName="id")
*/
public $parent;
}