Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1238Test.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-1238
12  */
13 class DDC1238Test extends \Doctrine\Tests\OrmFunctionalTestCase
14 {
15     public function setUp()
16     {
17         parent::setUp();
18         try {
19             $this->_schemaTool->createSchema(array(
20                 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'),
21             ));
22         } catch(\Exception $e) {
23
24         }
25     }
26
27     public function testIssue()
28     {
29         $user = new DDC1238User;
30         $user->setName("test");
31
32         $this->_em->persist($user);
33         $this->_em->flush();
34         $this->_em->clear();
35
36         $userId = $user->getId();
37         $this->_em->clear();
38
39         $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
40         $this->_em->clear();
41
42         $userId2 = $user->getId();
43         $this->assertEquals($userId, $userId2, "This proxy can still be initialized.");
44     }
45
46     public function testIssueProxyClear()
47     {
48         $user = new DDC1238User;
49         $user->setName("test");
50
51         $this->_em->persist($user);
52         $this->_em->flush();
53         $this->_em->clear();
54
55         // force proxy load, getId() doesn't work anymore
56         $user->getName();
57         $userId = $user->getId();
58         $this->_em->clear();
59
60         $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
61         $this->_em->clear();
62
63         $user2 = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
64
65         // force proxy load, getId() doesn't work anymore
66         $user->getName();
67         $this->assertNull($user->getId(), "Now this is null, we already have a user instance of that type");
68     }
69 }
70
71 /**
72  * @Entity
73  */
74 class DDC1238User
75 {
76     /** @Id @GeneratedValue @Column(type="integer") */
77     private $id;
78
79     /**
80      * @Column
81      * @var string
82      */
83     private $name;
84
85     public function getId()
86     {
87         return $this->id;
88     }
89
90     public function getName()
91     {
92         return $this->name;
93     }
94
95     public function setName($name)
96     {
97         $this->name = $name;
98     }
99 }
100