1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edm\EntityContainer; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType; |
9
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
10
|
|
|
use Mockery as m; |
11
|
|
|
|
12
|
|
|
class EntitySetAnonymousTypeTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testSetBadName() |
15
|
|
|
{ |
16
|
|
|
$expected = "Name must be a valid TSimpleIdentifier"; |
17
|
|
|
$actual = null; |
18
|
|
|
|
19
|
|
|
$foo = new EntitySetAnonymousType(); |
20
|
|
|
$name = " _ "; |
21
|
|
|
|
22
|
|
|
try { |
23
|
|
|
$foo->setName($name); |
24
|
|
|
} catch (\InvalidArgumentException $e) { |
25
|
|
|
$actual = $e->getMessage(); |
26
|
|
|
} |
27
|
|
|
$this->assertEquals($expected, $actual); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSetBadEntityType() |
31
|
|
|
{ |
32
|
|
|
$expected = "Entity type must be a valid TQualifiedName"; |
33
|
|
|
$actual = null; |
34
|
|
|
|
35
|
|
|
$foo = new EntitySetAnonymousType(); |
36
|
|
|
$name = " _ "; |
37
|
|
|
|
38
|
|
|
try { |
39
|
|
|
$foo->setEntityType($name); |
40
|
|
|
} catch (\InvalidArgumentException $e) { |
41
|
|
|
$actual = $e->getMessage(); |
42
|
|
|
} |
43
|
|
|
$this->assertEquals($expected, $actual); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSetBadGetterAccess() |
47
|
|
|
{ |
48
|
|
|
$expected = "Getter access must be a valid TAccess"; |
49
|
|
|
$actual = null; |
50
|
|
|
|
51
|
|
|
$foo = new EntitySetAnonymousType(); |
52
|
|
|
$name = " _ "; |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
$foo->setGetterAccess($name); |
56
|
|
|
} catch (\InvalidArgumentException $e) { |
57
|
|
|
$actual = $e->getMessage(); |
58
|
|
|
} |
59
|
|
|
$this->assertEquals($expected, $actual); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadName() |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$expectedStarts = "Name must be a valid TSimpleIdentifier"; |
65
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
66
|
|
|
$actual = null; |
67
|
|
|
|
68
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
69
|
|
|
$foo->shouldReceive('isTSimpleIdentifierValid')->andReturn(true, false)->twice(); |
70
|
|
|
|
71
|
|
|
$foo->setName(" _ "); |
72
|
|
|
|
73
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
74
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
75
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadEntityType() |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$expectedStarts = "Entity type must be a valid TQualifiedName"; |
81
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
82
|
|
|
$actual = null; |
83
|
|
|
|
84
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
85
|
|
|
$foo->shouldReceive('isTQualifiedNameValid')->andReturn(true, false)->twice(); |
86
|
|
|
|
87
|
|
|
$foo->setEntityType(" _ "); |
88
|
|
|
|
89
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
90
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
91
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadGetterAccess() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$expectedStarts = "Getter access must be a valid TAccess"; |
97
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
98
|
|
|
$actual = null; |
99
|
|
|
|
100
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
101
|
|
|
$foo->shouldReceive('isTAccessOk')->andReturn(true, false)->twice(); |
102
|
|
|
|
103
|
|
|
$foo->setGetterAccess(" _ "); |
104
|
|
|
|
105
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
106
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
107
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
public function testSetBadTypeAnnotation() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$expected = ""; |
113
|
|
|
$actual = null; |
114
|
|
|
|
115
|
|
|
$type = m::mock(TTypeAnnotationType::class)->makePartial(); |
116
|
|
|
$type->shouldReceive('isOK')->andReturn(false); |
117
|
|
|
|
118
|
|
|
$foo = new EntitySetAnonymousType(); |
119
|
|
|
|
120
|
|
|
try { |
121
|
|
|
$foo->setTypeAnnotation([$type]); |
|
|
|
|
122
|
|
|
} catch (\InvalidArgumentException $e) { |
123
|
|
|
$actual = $e->getMessage(); |
124
|
|
|
} |
125
|
|
|
$this->assertEquals($expected, $actual); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public function testAddBadTypeAnnotation() |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$expected = ''; |
131
|
|
|
$actual = null; |
132
|
|
|
|
133
|
|
|
$type = m::mock(TTypeAnnotationType::class)->makePartial(); |
134
|
|
|
$type->shouldReceive('isOK')->andReturn(false); |
135
|
|
|
|
136
|
|
|
$foo = new EntitySetAnonymousType(); |
137
|
|
|
|
138
|
|
|
try { |
139
|
|
|
$foo->addToTypeAnnotation($type); |
|
|
|
|
140
|
|
|
} catch (\InvalidArgumentException $e) { |
141
|
|
|
$actual = $e->getMessage(); |
142
|
|
|
} |
143
|
|
|
$this->assertEquals($expected, $actual); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
View Code Duplication |
public function testAddGoodTypeAnnotation() |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
$type = m::mock(TTypeAnnotationType::class)->makePartial(); |
149
|
|
|
$type->shouldReceive('isOK')->andReturn(true); |
150
|
|
|
|
151
|
|
|
$foo = new EntitySetAnonymousType(); |
152
|
|
|
|
153
|
|
|
$foo->addToTypeAnnotation($type); |
|
|
|
|
154
|
|
|
$this->assertTrue($foo->issetTypeAnnotation(0)); |
155
|
|
|
$foo->unsetTypeAnnotation(0); |
156
|
|
|
$this->assertFalse($foo->issetTypeAnnotation(0)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
View Code Duplication |
public function testAddBadDocumentation() |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
$expected = ''; |
162
|
|
|
$actual = null; |
163
|
|
|
|
164
|
|
|
$doc = m::mock(TDocumentationType::class); |
165
|
|
|
$doc->shouldReceive('isOK')->andReturn(false); |
|
|
|
|
166
|
|
|
|
167
|
|
|
$foo = new EntitySetAnonymousType(); |
168
|
|
|
|
169
|
|
|
try { |
170
|
|
|
$foo->addToDocumentation($doc); |
171
|
|
|
} catch (\InvalidArgumentException $e) { |
172
|
|
|
$actual = $e->getMessage(); |
173
|
|
|
} |
174
|
|
|
$this->assertEquals($expected, $actual); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
View Code Duplication |
public function testAddGoodDocumentation() |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
$doc = m::mock(TDocumentationType::class); |
180
|
|
|
$doc->shouldReceive('isOK')->andReturn(true); |
|
|
|
|
181
|
|
|
|
182
|
|
|
$foo = new EntitySetAnonymousType(); |
183
|
|
|
|
184
|
|
|
$foo->addToDocumentation($doc); |
185
|
|
|
$this->assertTrue($foo->issetDocumentation(0)); |
186
|
|
|
$foo->unsetDocumentation(0); |
187
|
|
|
$this->assertFalse($foo->issetDocumentation(0)); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
View Code Duplication |
public function testSetBadDocumentation() |
|
|
|
|
191
|
|
|
{ |
192
|
|
|
$expected = ''; |
193
|
|
|
$actual = null; |
194
|
|
|
|
195
|
|
|
$doc = m::mock(TDocumentationType::class); |
196
|
|
|
$doc->shouldReceive('isOK')->andReturn(false); |
|
|
|
|
197
|
|
|
|
198
|
|
|
$foo = new EntitySetAnonymousType(); |
199
|
|
|
|
200
|
|
|
try { |
201
|
|
|
$foo->setDocumentation([$doc]); |
|
|
|
|
202
|
|
|
} catch (\InvalidArgumentException $e) { |
203
|
|
|
$actual = $e->getMessage(); |
204
|
|
|
} |
205
|
|
|
$this->assertEquals($expected, $actual); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
View Code Duplication |
public function testSetBadValueAnnotation() |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
$expected = ""; |
211
|
|
|
$actual = null; |
212
|
|
|
|
213
|
|
|
$type = m::mock(TValueAnnotationType::class)->makePartial(); |
214
|
|
|
$type->shouldReceive('isOK')->andReturn(false); |
215
|
|
|
|
216
|
|
|
$foo = new EntitySetAnonymousType(); |
217
|
|
|
|
218
|
|
|
try { |
219
|
|
|
$foo->setValueAnnotation([$type]); |
|
|
|
|
220
|
|
|
} catch (\InvalidArgumentException $e) { |
221
|
|
|
$actual = $e->getMessage(); |
222
|
|
|
} |
223
|
|
|
$this->assertEquals($expected, $actual); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
View Code Duplication |
public function testAddBadValueAnnotation() |
|
|
|
|
227
|
|
|
{ |
228
|
|
|
$expected = ''; |
229
|
|
|
$actual = null; |
230
|
|
|
|
231
|
|
|
$type = m::mock(TValueAnnotationType::class)->makePartial(); |
232
|
|
|
$type->shouldReceive('isOK')->andReturn(false); |
233
|
|
|
|
234
|
|
|
$foo = new EntitySetAnonymousType(); |
235
|
|
|
|
236
|
|
|
try { |
237
|
|
|
$foo->addToValueAnnotation($type); |
|
|
|
|
238
|
|
|
} catch (\InvalidArgumentException $e) { |
239
|
|
|
$actual = $e->getMessage(); |
240
|
|
|
} |
241
|
|
|
$this->assertEquals($expected, $actual); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
View Code Duplication |
public function testAddGoodValueAnnotation() |
|
|
|
|
245
|
|
|
{ |
246
|
|
|
$type = m::mock(TValueAnnotationType::class)->makePartial(); |
247
|
|
|
$type->shouldReceive('isOK')->andReturn(true); |
248
|
|
|
|
249
|
|
|
$foo = new EntitySetAnonymousType(); |
250
|
|
|
|
251
|
|
|
$foo->addToValueAnnotation($type); |
|
|
|
|
252
|
|
|
$this->assertTrue($foo->issetValueAnnotation(0)); |
253
|
|
|
$foo->unsetValueAnnotation(0); |
254
|
|
|
$this->assertFalse($foo->issetValueAnnotation(0)); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
View Code Duplication |
public function testIsOkTooManyDocumentation() |
|
|
|
|
258
|
|
|
{ |
259
|
|
|
$expected = 'Supplied array not a valid array: ' |
260
|
|
|
.'AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType'; |
261
|
|
|
$actual = null; |
262
|
|
|
|
263
|
|
|
$doc = m::mock(TDocumentationType::class); |
264
|
|
|
$doc->shouldReceive('isOK')->andReturn(true); |
|
|
|
|
265
|
|
|
|
266
|
|
|
$foo = new EntitySetAnonymousType(); |
267
|
|
|
$foo->addToDocumentation($doc); |
268
|
|
|
$foo->addToDocumentation($doc); |
269
|
|
|
|
270
|
|
|
$this->assertFalse($foo->isOK($actual)); |
271
|
|
|
$this->assertEquals($expected, $actual); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
View Code Duplication |
public function testIsOKBadTypeAnnotations() |
|
|
|
|
275
|
|
|
{ |
276
|
|
|
$expected = ''; |
277
|
|
|
$actual = null; |
278
|
|
|
|
279
|
|
|
$type = m::mock(TTypeAnnotationType::class)->makePartial(); |
280
|
|
|
$type->shouldReceive('isOK')->andReturn(true, false)->twice(); |
281
|
|
|
|
282
|
|
|
$foo = new EntitySetAnonymousType(); |
283
|
|
|
$foo->addToTypeAnnotation($type); |
|
|
|
|
284
|
|
|
|
285
|
|
|
$this->assertFalse($foo->isOK($actual)); |
286
|
|
|
$this->assertEquals($expected, $actual); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
View Code Duplication |
public function testIsOKBadValueAnnotations() |
|
|
|
|
290
|
|
|
{ |
291
|
|
|
$expected = ''; |
292
|
|
|
$actual = null; |
293
|
|
|
|
294
|
|
|
$type = m::mock(TValueAnnotationType::class)->makePartial(); |
295
|
|
|
$type->shouldReceive('isOK')->andReturn(true, false)->twice(); |
296
|
|
|
|
297
|
|
|
$foo = new EntitySetAnonymousType(); |
298
|
|
|
$foo->addToValueAnnotation($type); |
|
|
|
|
299
|
|
|
|
300
|
|
|
$this->assertFalse($foo->isOK($actual)); |
301
|
|
|
$this->assertEquals($expected, $actual); |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.