Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC531Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase
8 {
9     protected function setUp()
10     {
11         parent::setUp();
12         $this->_schemaTool->createSchema(array(
13             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531Item'),
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531SubItem'),
15         ));
16     }
17
18     public function testIssue()
19     {
20         $item1 = new DDC531Item;
21         $item2 = new DDC531Item;
22         $item2->parent = $item1;
23         $item1->getChildren()->add($item2);
24         $this->_em->persist($item1);
25         $this->_em->persist($item2);
26         $this->_em->flush();
27         $this->_em->clear();
28
29         $item3 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item2->id); // Load child item first (id 2)
30         // parent will already be loaded, cannot be lazy because it has mapped subclasses and we would not
31         // know which proxy type to put in.
32         $this->assertInstanceOf(__NAMESPACE__ . '\DDC531Item', $item3->parent);
33         $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $item3->parent);
34         $item4 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item1->id); // Load parent item (id 1)
35         $this->assertNull($item4->parent);
36         $this->assertNotNull($item4->getChildren());
37         $this->assertTrue($item4->getChildren()->contains($item3)); // lazy-loads children
38     }
39 }
40
41 /**
42  * @Entity
43  * @InheritanceType("SINGLE_TABLE")
44  * @DiscriminatorColumn(name="type", type="integer")
45  * @DiscriminatorMap({"0" = "DDC531Item", "1" = "DDC531SubItem"})
46  */
47 class DDC531Item
48 {
49     /**
50      * @Id
51      * @Column(type="integer")
52      * @GeneratedValue(strategy="AUTO")
53      */
54     public $id;
55
56     /**
57      * @OneToMany(targetEntity="DDC531Item", mappedBy="parent")
58      */
59     protected $children;
60
61     /**
62      * @ManyToOne(targetEntity="DDC531Item", inversedBy="children")
63      * @JoinColumn(name="parentId", referencedColumnName="id")
64      */
65     public $parent;
66
67     public function __construct()
68     {
69         $this->children = new \Doctrine\Common\Collections\ArrayCollection;
70     }
71
72     public function getParent()
73     {
74         return $this->parent;
75     }
76
77     public function getChildren()
78     {
79         return $this->children;
80     }
81 }
82
83 /**
84  * @Entity
85  */
86 class DDC531SubItem extends DDC531Item
87 {
88 }