Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1392Test.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 /**
9  * @group DDC-1392
10  */
11 class DDC1392Test extends \Doctrine\Tests\OrmFunctionalTestCase
12 {
13     protected function setUp()
14     {
15         parent::setUp();
16
17         try {
18             $this->_schemaTool->createSchema(array(
19                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392File'),
20                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392Picture'),
21             ));
22         } catch (\Exception $ignored) {
23         }
24     }
25
26     public function testFailingCase()
27     {
28         $file = new DDC1392File;
29
30         $picture = new DDC1392Picture;
31         $picture->setFile($file);
32
33         $em = $this->_em;
34         $em->persist($picture);
35         $em->flush();
36         $em->clear();
37
38         $fileId = $file->getFileId();
39         $pictureId = $picture->getPictureId();
40
41         $this->assertTrue($fileId > 0);
42
43         $picture = $em->find(__NAMESPACE__ . '\DDC1392Picture', $pictureId);
44         $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
45
46         $file = $picture->getFile();
47
48         // With this activated there will be no problem
49         //$file->__load();
50
51         $picture->setFile(null);
52
53         $em->clear();
54
55         $em->merge($file);
56
57         $em->flush();
58
59         $q = $this->_em->createQuery("SELECT COUNT(e) FROM " . __NAMESPACE__ . '\DDC1392File e');
60         $result = $q->getSingleScalarResult();
61
62         self::assertEquals(1, $result);
63     }
64 }
65
66 /**
67  * @Entity
68  */
69 class DDC1392Picture
70 {
71     /**
72      * @Column(name="picture_id", type="integer")
73      * @Id @GeneratedValue
74      */
75     private $pictureId;
76
77     /**
78      * @ManyToOne(targetEntity="DDC1392File", cascade={"persist", "remove"})
79      * @JoinColumn(name="file_id", referencedColumnName="file_id")
80      */
81     private $file;
82
83     /**
84      * Get pictureId
85      */
86     public function getPictureId()
87     {
88         return $this->pictureId;
89     }
90
91     /**
92      * Set file
93      */
94     public function setFile($value = null)
95     {
96         $this->file = $value;
97     }
98
99     /**
100      * Get file
101      */
102     public function getFile()
103     {
104         return $this->file;
105     }
106 }
107
108 /**
109  * @Entity
110  */
111 class DDC1392File
112 {
113     /**
114      * @Column(name="file_id", type="integer")
115      * @Id
116      * @GeneratedValue(strategy="AUTO")
117      */
118     public $fileId;
119
120     /**
121      * Get fileId
122      */
123     public function getFileId()
124     {
125         return $this->fileId;
126     }
127 }