Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1228Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\Tests\Models\CMS\CmsEmployee;
7
8 require_once __DIR__ . '/../../../TestInit.php';
9
10 /**
11  * @group DDC-1228
12  * @group DDC-1226
13  */
14 class DDC1228Test extends \Doctrine\Tests\OrmFunctionalTestCase
15 {
16     public function setUp()
17     {
18         parent::setUp();
19         try {
20             $this->_schemaTool->createSchema(array(
21                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'),
22                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'),
23             ));
24         } catch(\Exception $e) {
25
26         }
27     }
28
29     public function testOneToOnePersist()
30     {
31         $user = new DDC1228User;
32         $profile = new DDC1228Profile();
33         $profile->name = "Foo";
34         $user->profile = $profile;
35
36         $this->_em->persist($user);
37         $this->_em->persist($profile);
38         $this->_em->flush();
39         $this->_em->clear();
40
41         $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id);
42
43         $this->assertFalse($user->getProfile()->__isInitialized__, "Proxy is not initialized");
44         $user->getProfile()->setName("Bar");
45         $this->assertTrue($user->getProfile()->__isInitialized__, "Proxy is not initialized");
46
47         $this->assertEquals("Bar", $user->getProfile()->getName());
48         $this->assertEquals(array("id" => 1, "name" => "Foo"), $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile()));
49
50         $this->_em->flush();
51         $this->_em->clear();
52
53         $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id);
54         $this->assertEquals("Bar", $user->getProfile()->getName());
55     }
56
57     public function testRefresh()
58     {
59         $user = new DDC1228User;
60         $profile = new DDC1228Profile();
61         $profile->name = "Foo";
62         $user->profile = $profile;
63
64         $this->_em->persist($user);
65         $this->_em->persist($profile);
66         $this->_em->flush();
67         $this->_em->clear();
68
69         $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1228User', $user->id);
70
71         $this->_em->refresh($user);
72         $user->name = "Baz";
73         $this->_em->flush();
74         $this->_em->clear();
75
76         $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id);
77         $this->assertEquals("Baz", $user->name);
78     }
79 }
80
81 /**
82  * @Entity
83  */
84 class DDC1228User
85 {
86     /**
87      * @Id @Column(type="integer") @GeneratedValue
88      * @var int
89      */
90     public $id;
91
92     /**
93      * @Column(type="string")
94      * @var string
95      */
96     public $name = 'Bar';
97
98     /**
99      * @OneToOne(targetEntity="DDC1228Profile")
100      * @var Profile
101      */
102     public $profile;
103
104     public function getProfile()
105     {
106         return $this->profile;
107     }
108 }
109
110 /**
111  * @Entity
112  */
113 class DDC1228Profile
114 {
115     /**
116      * @Id @Column(type="integer") @GeneratedValue
117      * @var int
118      */
119     public $id;
120
121     /**
122      * @column(type="string")
123      * @var string
124      */
125     public $name;
126
127     public function getName()
128     {
129         return $this->name;
130     }
131
132     public function setName($name)
133     {
134         $this->name = $name;
135     }
136 }