Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC237Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase
8 {
9     protected function setUp()
10     {
11         parent::setUp();
12         $this->_schemaTool->createSchema(array(
13             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityX'),
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityY'),
15             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityZ')
16         ));
17     }
18
19     public function testUninitializedProxyIsInitializedOnFetchJoin()
20     {
21         $x = new DDC237EntityX;
22         $y = new DDC237EntityY;
23         $z = new DDC237EntityZ;
24
25         $x->data = 'X';
26         $y->data = 'Y';
27         $z->data = 'Z';
28
29         $x->y = $y;
30         $z->y = $y;
31
32         $this->_em->persist($x);
33         $this->_em->persist($y);
34         $this->_em->persist($z);
35
36         $this->_em->flush();
37         $this->_em->clear();
38
39         $x2 = $this->_em->find(get_class($x), $x->id); // proxy injected for Y
40         $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $x2->y);
41         $this->assertFalse($x2->y->__isInitialized__);
42
43         // proxy for Y is in identity map
44
45         $z2 = $this->_em->createQuery('select z,y from ' . get_class($z) . ' z join z.y y where z.id = ?1')
46                 ->setParameter(1, $z->id)
47                 ->getSingleResult();
48         $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y);
49         $this->assertTrue($z2->y->__isInitialized__);
50         $this->assertEquals('Y', $z2->y->data);
51         $this->assertEquals($y->id, $z2->y->id);
52
53         // since the Y is the same, the instance from the identity map is
54         // used, even if it is a proxy.
55
56         $this->assertNotSame($x, $x2);
57         $this->assertNotSame($z, $z2);
58         $this->assertSame($z2->y, $x2->y);
59         $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y);
60
61     }
62 }
63
64
65 /**
66  * @Entity @Table(name="ddc237_x")
67  */
68 class DDC237EntityX
69 {
70     /**
71      * @Id @Column(type="integer") @GeneratedValue
72      */
73     public $id;
74     /**
75      * @Column(type="string")
76      */
77     public $data;
78     /**
79      * @OneToOne(targetEntity="DDC237EntityY")
80      * @JoinColumn(name="y_id", referencedColumnName="id")
81      */
82     public $y;
83 }
84
85
86 /** @Entity @Table(name="ddc237_y") */
87 class DDC237EntityY
88 {
89     /**
90      * @Id @Column(type="integer") @GeneratedValue
91      */
92     public $id;
93     /**
94      * @Column(type="string")
95      */
96     public $data;
97 }
98
99 /** @Entity @Table(name="ddc237_z") */
100 class DDC237EntityZ
101 {
102     /** @Id @Column(type="integer") @GeneratedValue */
103     public $id;
104     /** @Column(type="string") */
105     public $data;
106
107     /**
108      * @OneToOne(targetEntity="DDC237EntityY")
109      * @JoinColumn(name="y_id", referencedColumnName="id")
110      */
111     public $y;
112 }