Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1400Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4 use Doctrine\ORM\UnitOfWork;
5
6 require_once __DIR__ . '/../../../TestInit.php';
7
8 /**
9  * @group DDC-1400
10  */
11 class DDC1400Test extends \Doctrine\Tests\OrmFunctionalTestCase
12 {
13     protected function setUp()
14     {
15         parent::setUp();
16
17         try {
18             $this->_schemaTool->createSchema(array(
19                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400Article'),
20                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400User'),
21                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400UserState'),
22             ));
23         } catch (\Exception $ignored) {
24         }
25     }
26
27     public function testFailingCase()
28     {
29         $article = new DDC1400Article;
30         $user1 = new DDC1400User;
31         $user2 = new DDC1400User;
32
33         $this->_em->persist($article);
34         $this->_em->persist($user1);
35         $this->_em->persist($user2);
36         $this->_em->flush();
37
38         $userState1 = new DDC1400UserState;
39         $userState1->article = $article;
40         $userState1->articleId = $article->id;
41         $userState1->user = $user1;
42         $userState1->userId = $user1->id;
43
44         $userState2 = new DDC1400UserState;
45         $userState2->article = $article;
46         $userState2->articleId = $article->id;
47         $userState2->user = $user2;
48         $userState2->userId = $user2->id;
49
50         $this->_em->persist($userState1);
51         $this->_em->persist($userState2);
52
53         $this->_em->flush();
54         $this->_em->clear();
55
56         $user1 = $this->_em->getReference(__NAMESPACE__.'\DDC1400User', $user1->id);
57
58         $q = $this->_em->createQuery("SELECT a, s FROM ".__NAMESPACE__."\DDC1400Article a JOIN a.userStates s WITH s.user = :activeUser");
59         $q->setParameter('activeUser', $user1);
60         $articles = $q->getResult();
61
62         $this->_em->flush();
63     }
64 }
65
66 /**
67  * @Entity
68  */
69 class DDC1400Article
70 {
71     /**
72      * @Id
73      * @Column(type="integer")
74      * @GeneratedValue
75      */
76     public $id;
77
78     /**
79      * @OneToMany(targetEntity="DDC1400UserState", mappedBy="article", indexBy="userId", fetch="EXTRA_LAZY")
80      */
81     public $userStates;
82 }
83
84 /**
85  * @Entity
86  */
87 class DDC1400User
88 {
89
90     /**
91      * @Id
92      * @Column(type="integer")
93      * @GeneratedValue
94      */
95     public $id;
96
97     /**
98      * @OneToMany(targetEntity="DDC1400UserState", mappedBy="user", indexBy="articleId", fetch="EXTRA_LAZY")
99      */
100     public $userStates;
101 }
102
103 /**
104  * @Entity
105  */
106 class DDC1400UserState
107 {
108
109     /**
110       * @Id
111      *  @ManyToOne(targetEntity="DDC1400Article", inversedBy="userStates")
112      */
113     public $article;
114
115     /**
116       * @Id
117      *  @ManyToOne(targetEntity="DDC1400User", inversedBy="userStates")
118      */
119     public $user;
120
121     /**
122      * @Column(name="user_id", type="integer")
123      */
124     public $userId;
125
126     /**
127      * @Column(name="article_id", type="integer")
128      */
129     public $articleId;
130
131 }