Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / ReadOnlyTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional;
4
5 require_once __DIR__ . '/../../TestInit.php';
6
7 /**
8  * Functional Query tests.
9  *
10  * @group DDC-692
11  */
12 class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase
13 {
14     protected function setUp()
15     {
16         parent::setUp();
17
18         try {
19             $this->_schemaTool->createSchema(array(
20                 $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'),
21             ));
22         } catch(\Exception $e) {
23         }
24     }
25
26     public function testReadOnlyEntityNeverChangeTracked()
27     {
28         $readOnly = new ReadOnlyEntity("Test1", 1234);
29         $this->_em->persist($readOnly);
30         $this->_em->flush();
31
32         $readOnly->name = "Test2";
33         $readOnly->numericValue = 4321;
34
35         $this->_em->flush();
36         $this->_em->clear();
37
38         $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id);
39         $this->assertEquals("Test1", $dbReadOnly->name);
40         $this->assertEquals(1234, $dbReadOnly->numericValue);
41     }
42
43     /**
44      * @group DDC-1659
45      */
46     public function testClearReadOnly()
47     {
48         $readOnly = new ReadOnlyEntity("Test1", 1234);
49         $this->_em->persist($readOnly);
50         $this->_em->flush();
51         $this->_em->getUnitOfWork()->markReadOnly($readOnly);
52
53         $this->_em->clear();
54
55         $this->assertFalse($this->_em->getUnitOfWork()->isReadOnly($readOnly));
56     }
57
58     /**
59      * @group DDC-1659
60      */
61     public function testClearEntitiesReadOnly()
62     {
63         $readOnly = new ReadOnlyEntity("Test1", 1234);
64         $this->_em->persist($readOnly);
65         $this->_em->flush();
66         $this->_em->getUnitOfWork()->markReadOnly($readOnly);
67
68         $this->_em->clear(get_class($readOnly));
69
70         $this->assertFalse($this->_em->getUnitOfWork()->isReadOnly($readOnly));
71     }
72 }
73
74 /**
75  * @Entity(readOnly=true)
76  */
77 class ReadOnlyEntity
78 {
79     /**
80      * @Id @GeneratedValue @Column(type="integer")
81      * @var int
82      */
83     public $id;
84     /** @column(type="string") */
85     public $name;
86     /** @Column(type="integer") */
87     public $numericValue;
88
89     public function __construct($name, $number)
90     {
91         $this->name = $name;
92         $this->numericValue = $number;
93     }
94 }