Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1458Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\Tests\Models\CMS\CmsUser;
7 use Doctrine\Tests\Models\CMS\CmsGroup;
8
9 require_once __DIR__ . '/../../../TestInit.php';
10
11 class DDC1258Test extends \Doctrine\Tests\OrmFunctionalTestCase
12 {
13     public function setUp()
14     {
15         parent::setUp();
16         $this->_schemaTool->createSchema(array(
17             $this->_em->getClassMetadata(__NAMESPACE__ . '\TestEntity'),
18             $this->_em->getClassMetadata(__NAMESPACE__ . '\TestAdditionalEntity')
19         ));
20     }
21
22     public function testIssue()
23     {
24         $testEntity = new TestEntity();
25         $testEntity->setValue(3);
26         $testEntity->setAdditional(new TestAdditionalEntity());
27         $this->_em->persist($testEntity);
28         $this->_em->flush();
29         $this->_em->clear();
30
31         // So here the value is 3
32         $this->assertEquals(3, $testEntity->getValue());
33
34         $test = $this->_em->getRepository(__NAMESPACE__ . '\TestEntity')->find(1);
35
36         // New value is set
37         $test->setValue(5);
38
39         // So here the value is 5
40         $this->assertEquals(5, $test->getValue());
41
42         // Get the additional entity
43         $additional = $test->getAdditional();
44
45         // Still 5..
46         $this->assertEquals(5, $test->getValue());
47
48         // Force the proxy to load
49         $additional->getBool();
50
51         // The value should still be 5
52         $this->assertEquals(5, $test->getValue());
53     }
54 }
55
56
57 /**
58  * @Entity
59  */
60 class TestEntity
61 {
62     /**
63      * @Id
64      * @Column(type="integer")
65      * @GeneratedValue(strategy="AUTO")
66      */
67     protected $id;
68     /**
69      * @Column(type="integer")
70      */
71     protected $value;
72     /**
73      * @OneToOne(targetEntity="TestAdditionalEntity", inversedBy="entity", orphanRemoval=true, cascade={"persist", "remove"})
74      */
75     protected $additional;
76
77     public function getValue()
78     {
79         return $this->value;
80     }
81
82     public function setValue($value)
83     {
84         $this->value = $value;
85     }
86
87     public function getAdditional()
88     {
89         return $this->additional;
90     }
91
92     public function setAdditional($additional)
93     {
94         $this->additional = $additional;
95     }
96 }
97 /**
98  * @Entity
99  */
100 class TestAdditionalEntity
101 {
102     /**
103      * @Id
104      * @Column(type="integer")
105      * @GeneratedValue(strategy="AUTO")
106      */
107     protected $id;
108     /**
109      * @OneToOne(targetEntity="TestEntity", mappedBy="additional")
110      */
111     protected $entity;
112     /**
113      * @Column(type="boolean")
114      */
115     protected $bool;
116
117     public function __construct()
118     {
119         $this->bool = false;
120     }
121
122     public function getBool()
123     {
124         return $this->bool;
125     }
126
127     public function setBool($bool)
128     {
129         $this->bool = $bool;
130     }
131 }