Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1509Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\ORM\UnitOfWork;
6
7 /**
8  * @group DDC-1509
9  */
10 class DDC1509Test extends \Doctrine\Tests\OrmFunctionalTestCase
11 {
12
13     protected function setUp()
14     {
15         parent::setUp();
16
17         try {
18             $this->_schemaTool->createSchema(array(
19                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509AbstractFile'),
20                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'),
21                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'),
22             ));
23         } catch (\Exception $ignored) {
24
25         }
26     }
27
28     public function testFailingCase()
29     {
30         $file = new DDC1509File;
31         $thumbnail = new DDC1509File;
32
33         $picture = new DDC1509Picture;
34         $picture->setFile($file);
35         $picture->setThumbnail($thumbnail);
36
37
38         /* @var $em \Doctrine\ORM\EntityManager */
39         $em = $this->_em;
40         $em->persist($picture);
41         $em->flush();
42         $em->clear();
43
44         $id = $picture->getPictureId();
45
46         $pic = $em->merge($picture);
47         /* @var $pic DDC1509Picture */
48
49         $this->assertNotNull($pic->getThumbnail());
50         $this->assertNotNull($pic->getFile());
51     }
52
53 }
54
55 /**
56  * @Entity
57  */
58 class DDC1509Picture
59 {
60
61     /**
62      * @Column(type="integer")
63      * @Id
64      * @GeneratedValue(strategy="AUTO")
65      */
66     private $id;
67
68     /**
69      * @ManyToOne(targetEntity="DDC1509AbstractFile", cascade={"persist", "remove"})
70      */
71     private $thumbnail;
72
73     /**
74      * @ManyToOne(targetEntity="DDC1509AbstractFile", cascade={"persist", "remove"})
75      */
76     private $file;
77
78     /**
79      * Get pictureId
80      */
81     public function getPictureId()
82     {
83         return $this->id;
84     }
85
86     /**
87      * Set file
88      */
89     public function setFile($value = null)
90     {
91         $this->file = $value;
92     }
93
94     /**
95      * Get file
96      */
97     public function getFile()
98     {
99         return $this->file;
100     }
101
102     public function getThumbnail()
103     {
104         return $this->thumbnail;
105     }
106
107     public function setThumbnail($thumbnail)
108     {
109         $this->thumbnail = $thumbnail;
110     }
111
112 }
113
114 /**
115  * @Entity
116  * @InheritanceType("SINGLE_TABLE")
117  * @DiscriminatorColumn(name="discr", type="string")
118  * @DiscriminatorMap({"file" = "DDC1509File"})
119  */
120 class DDC1509AbstractFile
121 {
122
123     /**
124      * @Column(type="integer")
125      * @Id
126      * @GeneratedValue(strategy="AUTO")
127      */
128     public $id;
129
130     /**
131      * Get fileId
132      */
133     public function getFileId()
134     {
135         return $this->id;
136     }
137
138 }
139
140 /**
141  * @Entity
142  */
143 class DDC1509File extends DDC1509AbstractFile
144 {
145
146 }