Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC279Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 class DDC279Test extends \Doctrine\Tests\OrmFunctionalTestCase
8 {
9     protected function setUp()
10     {
11         parent::setUp();
12         $this->_schemaTool->createSchema(array(
13             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityXAbstract'),
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityX'),
15             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityY'),
16             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityZ'),
17         ));
18     }
19
20     /**
21      * @group DDC-279
22      */
23     public function testDDC279()
24     {
25         $x = new DDC279EntityX();
26         $y = new DDC279EntityY();
27         $z = new DDC279EntityZ();
28
29         $x->data = 'X';
30         $y->data = 'Y';
31         $z->data = 'Z';
32
33         $x->y = $y;
34         $y->z = $z;
35
36         $this->_em->persist($x);
37         $this->_em->persist($y);
38         $this->_em->persist($z);
39
40         $this->_em->flush();
41         $this->_em->clear();
42
43         $query = $this->_em->createQuery(
44             'SELECT x, y, z FROM Doctrine\Tests\ORM\Functional\Ticket\DDC279EntityX x '.
45             'INNER JOIN x.y y INNER JOIN y.z z WHERE x.id = ?1'
46         )->setParameter(1, $x->id);
47
48         $result = $query->getResult();
49
50         $expected1 = 'Y';
51         $expected2 = 'Z';
52
53         $this->assertEquals(1, count($result));
54
55         $this->assertEquals($expected1, $result[0]->y->data);
56         $this->assertEquals($expected2, $result[0]->y->z->data);
57     }
58 }
59
60
61 /**
62  * @Entity
63  * @InheritanceType("JOINED")
64  * @DiscriminatorColumn(name="discr", type="string")
65  * @DiscriminatorMap({"DDC279EntityX" = "DDC279EntityX"})
66  */
67 abstract class DDC279EntityXAbstract
68 {
69     /**
70      * @Id
71      * @GeneratedValue
72      * @Column(name="id", type="integer")
73      */
74     public $id;
75
76     /**
77      * @column(type="string")
78      */
79     public $data;
80
81 }
82
83 /**
84  * @Entity
85  */
86 class DDC279EntityX extends DDC279EntityXAbstract
87 {
88     /**
89      * @OneToOne(targetEntity="DDC279EntityY")
90      * @JoinColumn(name="y_id", referencedColumnName="id")
91      */
92     public $y;
93 }
94
95 /**
96  * @Entity
97  */
98 class DDC279EntityY
99 {
100     /**
101      * @Id @GeneratedValue
102      * @Column(name="id", type="integer")
103      */
104     public $id;
105
106     /**
107      * @column(type="string")
108      */
109     public $data;
110
111     /**
112      * @OneToOne(targetEntity="DDC279EntityZ")
113      * @JoinColumn(name="z_id", referencedColumnName="id")
114      */
115     public $z;
116 }
117
118 /**
119  * @Entity
120  */
121 class DDC279EntityZ
122 {
123     /**
124      * @Id @GeneratedValue
125      * @Column(name="id", type="integer")
126      */
127     public $id;
128
129     /**
130      * @column(type="string")
131      */
132     public $data;
133 }