Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1514Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\ORM\UnitOfWork;
7
8 require_once __DIR__ . '/../../../TestInit.php';
9
10 /**
11  * @group DDC-1514
12  */
13 class DDC1514Test extends \Doctrine\Tests\OrmFunctionalTestCase
14 {
15     protected function setUp()
16     {
17         parent::setUp();
18
19         try {
20             $this->_schemaTool->createSchema(array(
21                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'),
22                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'),
23                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'),
24             ));
25         } catch (\Exception $ignored) {
26         }
27     }
28
29     public function testIssue()
30     {
31         $a1 = new DDC1514EntityA();
32         $a1->title = "foo";
33
34         $a2 = new DDC1514EntityA();
35         $a2->title = "bar";
36
37         $b1 = new DDC1514EntityB();
38         $b1->entityAFrom = $a1;
39         $b1->entityATo = $a2;
40
41         $b2 = new DDC1514EntityB();
42         $b2->entityAFrom = $a2;
43         $b2->entityATo = $a1;
44
45         $c = new DDC1514EntityC();
46         $c->title = "baz";
47         $a2->entityC = $c;
48
49         $this->_em->persist($a1);
50         $this->_em->persist($a2);
51         $this->_em->persist($b1);
52         $this->_em->persist($b2);
53         $this->_em->persist($c);
54         $this->_em->flush();
55         $this->_em->clear();
56
57         $dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c";
58         $results = $this->_em->createQuery($dql)->getResult();
59
60         $this->assertEquals($c->title, $results[1]->entityC->title);
61     }
62 }
63
64 /**
65  * @Entity
66  */
67 class DDC1514EntityA
68 {
69     /** @Id @Column(type="integer") @GeneratedValue */
70     public $id;
71     /** @Column */
72     public $title;
73     /** @ManyToMany(targetEntity="DDC1514EntityB", mappedBy="entityAFrom") */
74     public $entitiesB;
75     /** @ManyToOne(targetEntity="DDC1514EntityC") */
76     public $entityC;
77
78     public function __construct()
79     {
80         $this->entitiesB = new ArrayCollection();
81     }
82 }
83
84 /**
85  * @Entity
86  */
87 class DDC1514EntityB
88 {
89     /** @Id @Column(type="integer") @GeneratedValue */
90     public $id;
91
92     /**
93      * @ManyToOne(targetEntity="DDC1514EntityA", inversedBy="entitiesB")
94      */
95     public $entityAFrom;
96     /**
97      * @ManyToOne(targetEntity="DDC1514EntityA")
98      */
99     public $entityATo;
100 }
101
102 /**
103  * @Entity
104  */
105 class DDC1514EntityC
106 {
107     /** @Id @Column(type="integer") @GeneratedValue */
108     public $id;
109     /** @Column */
110     public $title;
111 }