These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Doctrine\Tests\ODM\CouchDB\Functional; |
||
4 | |||
5 | class InheritenceTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
||
6 | { |
||
7 | View Code Duplication | public function testPersistInheritanceReferenceOne() |
|
8 | { |
||
9 | $child = new CODM25ChildA(); |
||
10 | $child->foo = "bar"; |
||
11 | $parent = new CODM25Parent(); |
||
12 | $parent->child = $child; |
||
13 | |||
14 | $dm = $this->createDocumentManager(); |
||
15 | $dm->persist($parent); |
||
16 | $dm->persist($parent->child); |
||
17 | $dm->flush(); |
||
18 | |||
19 | $dm->clear(); |
||
20 | |||
21 | $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id); |
||
22 | |||
23 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->child); |
||
24 | $this->assertEquals('bar', $parent->child->foo); |
||
25 | } |
||
26 | |||
27 | View Code Duplication | public function testPersistInheritanceReferenceMany() |
|
28 | { |
||
29 | $child1 = new CODM25ChildA(); |
||
30 | $child1->foo = "bar"; |
||
31 | $child2 = new CODM25ChildA(); |
||
32 | $child2->foo = "baz"; |
||
33 | $parent = new CODM25Parent(); |
||
34 | $parent->childs[] = $child1; |
||
35 | $parent->childs[] = $child2; |
||
36 | |||
37 | $dm = $this->createDocumentManager(); |
||
38 | $dm->persist($parent); |
||
39 | $dm->persist($parent->childs[0]); |
||
40 | $dm->persist($parent->childs[1]); |
||
41 | $dm->flush(); |
||
42 | |||
43 | $dm->clear(); |
||
44 | |||
45 | $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id); |
||
46 | |||
47 | $this->assertEquals(2, count($parent->childs)); |
||
48 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->childs[0]); |
||
49 | $this->assertEquals('bar', $parent->childs[0]->foo); |
||
50 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->childs[1]); |
||
51 | $this->assertEquals('baz', $parent->childs[1]->foo); |
||
52 | } |
||
53 | |||
54 | View Code Duplication | public function testPersistInheritanceEmbededOne() |
|
55 | { |
||
56 | $child = new CODM25ChildA(); |
||
57 | $child->foo = "bar"; |
||
58 | $parent = new CODM25Parent(); |
||
59 | $parent->embed = $child; |
||
60 | |||
61 | $dm = $this->createDocumentManager(); |
||
62 | $dm->persist($parent); |
||
63 | $dm->persist($parent->embed); |
||
64 | $dm->flush(); |
||
65 | |||
66 | $dm->clear(); |
||
67 | |||
68 | $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id); |
||
69 | |||
70 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embed); |
||
71 | $this->assertEquals('bar', $parent->embed->foo); |
||
72 | } |
||
73 | |||
74 | View Code Duplication | public function testPersistInheritanceEmbedMany() |
|
75 | { |
||
76 | $child1 = new CODM25ChildA(); |
||
77 | $child1->foo = "bar"; |
||
78 | $child2 = new CODM25ChildA(); |
||
79 | $child2->foo = "baz"; |
||
80 | $parent = new CODM25Parent(); |
||
81 | $parent->embeds[] = $child1; |
||
82 | $parent->embeds[] = $child2; |
||
83 | |||
84 | $dm = $this->createDocumentManager(); |
||
85 | $dm->persist($parent); |
||
86 | $dm->persist($parent->embeds[0]); |
||
87 | $dm->persist($parent->embeds[1]); |
||
88 | $dm->flush(); |
||
89 | |||
90 | $dm->clear(); |
||
91 | |||
92 | $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id); |
||
93 | |||
94 | $this->assertEquals(2, count($parent->embeds)); |
||
95 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embeds[0]); |
||
96 | $this->assertEquals('bar', $parent->embeds[0]->foo); |
||
97 | $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embeds[1]); |
||
98 | $this->assertEquals('baz', $parent->embeds[1]->foo); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @Document |
||
104 | */ |
||
105 | class CODM25Parent |
||
0 ignored issues
–
show
|
|||
106 | { |
||
107 | /** @Id */ |
||
108 | public $id; |
||
109 | |||
110 | /** @ReferenceOne(targetDocument="CODM25Child") */ |
||
111 | public $child; |
||
112 | |||
113 | /** @ReferenceMany(targetDocument="CODM25Child") */ |
||
114 | public $childs; |
||
115 | |||
116 | /** |
||
117 | * @EmbedOne(targetDocument="CODM25Child") |
||
118 | */ |
||
119 | public $embed; |
||
120 | |||
121 | /** |
||
122 | * @EmbedMany(targetDocument="CODM25Child") |
||
123 | */ |
||
124 | public $embeds; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @Document |
||
129 | * @InheritanceRoot |
||
130 | */ |
||
131 | abstract class CODM25Child |
||
0 ignored issues
–
show
|
|||
132 | { |
||
133 | /** @Id */ |
||
134 | public $id; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @Document |
||
139 | */ |
||
140 | class CODM25ChildA extends CODM25Child |
||
0 ignored issues
–
show
|
|||
141 | { |
||
142 | /** @Field */ |
||
143 | public $foo; |
||
144 | } |
||
145 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.