Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1383Test.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-1383
10  */
11 class DDC1383Test 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__ . '\DDC1383AbstractEntity'),
20                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383Entity'),
21             ));
22         } catch(\Exception $ignored) {}
23     }
24
25     public function testFailingCase()
26     {
27                 $parent = new DDC1383Entity();
28                 $child = new DDC1383Entity();
29
30                 $child->setReference($parent);
31
32                 $this->_em->persist($parent);
33                 $this->_em->persist($child);
34
35                 $id = $child->getId();
36
37                 $this->_em->flush();
38                 $this->_em->clear();
39
40                 // Try merging the parent entity
41                 $child = $this->_em->merge($child);
42                 $parent = $child->getReference();
43
44                 // Parent is not instance of the abstract class
45                 self::assertTrue($parent instanceof DDC1383AbstractEntity,
46                                 "Entity class is " . get_class($parent) . ', "DDC1383AbstractEntity" was expected');
47
48                 // Parent is NOT instance of entity
49                 self::assertTrue($parent instanceof DDC1383Entity,
50                                 "Entity class is " . get_class($parent) . ', "DDC1383Entity" was expected');
51     }
52 }
53
54 /**
55  * @Entity
56  * @InheritanceType("JOINED")
57  * @DiscriminatorColumn(name="discr", type="integer")
58  * @DiscriminatorMap({1 = "DDC1383Entity"})
59  */
60 abstract class DDC1383AbstractEntity
61 {
62         /**
63          * @Id
64          * @Column(type="integer")
65          * @GeneratedValue
66          */
67         protected $id;
68
69         public function getId()
70         {
71                 return $this->id;
72         }
73
74         public function setId($id)
75         {
76                 $this->id = $id;
77         }
78 }
79
80 /**
81  * @Entity
82  */
83 class DDC1383Entity extends DDC1383AbstractEntity
84 {
85         /**
86          * @ManyToOne(targetEntity="DDC1383AbstractEntity")
87          */
88         protected $reference;
89
90         public function getReference()
91         {
92                 return $this->reference;
93         }
94
95         public function setReference(DDC1383AbstractEntity $reference)
96         {
97                 $this->reference = $reference;
98         }
99 }