Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC353Test.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 class DDC353Test extends \Doctrine\Tests\OrmFunctionalTestCase
9 {
10     protected function setUp()
11     {
12         parent::setUp();
13         try {
14             $this->_schemaTool->createSchema(array(
15                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353File'),
16                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353Picture'),
17             ));
18         } catch(\Exception $ignored) {}
19     }
20
21     public function testWorkingCase()
22     {
23         $file = new DDC353File;
24
25         $picture = new DDC353Picture;
26         $picture->setFile($file);
27
28         $em = $this->_em;
29         $em->persist($picture);
30         $em->flush();
31         $em->clear();
32
33         $fileId = $file->getFileId();
34         $this->assertTrue($fileId > 0);
35
36         $file = $em->getReference('Doctrine\Tests\ORM\Functional\Ticket\DDC353File', $fileId);
37         $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($file), "Reference Proxy should be marked MANAGED.");
38
39         $picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $picture->getPictureId());
40         $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
41
42         $em->remove($picture);
43         $em->flush();
44     }
45
46     public function testFailingCase()
47     {
48         $file = new DDC353File;
49
50         $picture = new DDC353Picture;
51         $picture->setFile($file);
52
53         $em = $this->_em;
54         $em->persist($picture);
55         $em->flush();
56         $em->clear();
57
58         $fileId = $file->getFileId();
59         $pictureId = $picture->getPictureId();
60
61         $this->assertTrue($fileId > 0);
62
63         $picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $pictureId);
64         $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
65
66         $em->remove($picture);
67         $em->flush();
68     }
69 }
70
71 /**
72  * @Entity
73  */
74 class DDC353Picture
75 {
76     /**
77      * @Column(name="picture_id", type="integer")
78      * @Id @GeneratedValue
79      */
80     private $pictureId;
81
82     /**
83      * @ManyToOne(targetEntity="DDC353File", cascade={"persist", "remove"})
84      * @JoinColumns({
85      *   @JoinColumn(name="file_id", referencedColumnName="file_id")
86      * })
87      */
88     private $file;
89
90     /**
91      * Get pictureId
92      */
93     public function getPictureId()
94     {
95         return $this->pictureId;
96     }
97
98     /**
99      * Set product
100      */
101     public function setProduct($value)
102     {
103         $this->product = $value;
104     }
105
106     /**
107      * Get product
108      */
109     public function getProduct()
110     {
111         return $this->product;
112     }
113
114     /**
115      * Set file
116      */
117     public function setFile($value)
118     {
119         $this->file = $value;
120     }
121
122     /**
123      * Get file
124      */
125     public function getFile()
126     {
127         return $this->file;
128     }
129 }
130
131 /**
132  * @Entity
133  */
134 class DDC353File
135 {
136     /**
137      * @Column(name="file_id", type="integer")
138      * @Id
139      * @GeneratedValue(strategy="AUTO")
140      */
141     public $fileId;
142
143     /**
144      * Get fileId
145      */
146     public function getFileId()
147     {
148         return $this->fileId;
149     }
150 }