1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edm\EntityContainer; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportParameterType; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType; |
9
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType; |
10
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
11
|
|
|
use Mockery as m; |
12
|
|
|
|
13
|
|
|
class FunctionImportAnonymousTypeTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testIsComposableRoundTripTrue() |
16
|
|
|
{ |
17
|
|
|
$foo = new FunctionImportAnonymousType(); |
18
|
|
|
|
19
|
|
|
$foo->setIsComposable('foo'); |
|
|
|
|
20
|
|
|
$this->assertTrue($foo->getIsComposable()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testIsComposableRoundTripFalse() |
24
|
|
|
{ |
25
|
|
|
$foo = new FunctionImportAnonymousType(); |
26
|
|
|
|
27
|
|
|
$foo->setIsComposable(null); |
|
|
|
|
28
|
|
|
$this->assertFalse($foo->getIsComposable()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testIsSideEffectingRoundTripTrue() |
32
|
|
|
{ |
33
|
|
|
$foo = new FunctionImportAnonymousType(); |
34
|
|
|
|
35
|
|
|
$foo->setIsSideEffecting('foo'); |
|
|
|
|
36
|
|
|
$this->assertTrue($foo->getIsSideEffecting()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testIsSideEffectingRoundTripFalse() |
40
|
|
|
{ |
41
|
|
|
$foo = new FunctionImportAnonymousType(); |
42
|
|
|
|
43
|
|
|
$foo->setIsSideEffecting(null); |
|
|
|
|
44
|
|
|
$this->assertFalse($foo->getIsSideEffecting()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testIsBindableRoundTripTrue() |
48
|
|
|
{ |
49
|
|
|
$foo = new FunctionImportAnonymousType(); |
50
|
|
|
|
51
|
|
|
$foo->setIsBindable('foo'); |
|
|
|
|
52
|
|
|
$this->assertTrue($foo->getIsBindable()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testIsBindableRoundTripFalse() |
56
|
|
|
{ |
57
|
|
|
$foo = new FunctionImportAnonymousType(); |
58
|
|
|
|
59
|
|
|
$foo->setIsBindable(null); |
|
|
|
|
60
|
|
|
$this->assertFalse($foo->getIsBindable()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testMethodAccessRoundTrip() |
64
|
|
|
{ |
65
|
|
|
$foo = new FunctionImportAnonymousType(); |
66
|
|
|
|
67
|
|
|
$foo->setMethodAccess('Public'); |
68
|
|
|
$this->assertEquals('Public', $foo->getMethodAccess()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetMethodAccessBadData() |
72
|
|
|
{ |
73
|
|
|
$expected = "Method access must be a valid TAccess"; |
74
|
|
|
$actual = null; |
75
|
|
|
|
76
|
|
|
$foo = new FunctionImportAnonymousType(); |
77
|
|
|
|
78
|
|
|
try { |
79
|
|
|
$foo->setMethodAccess("cheezburger"); |
80
|
|
|
} catch (\InvalidArgumentException $e) { |
81
|
|
|
$actual = $e->getMessage(); |
82
|
|
|
} |
83
|
|
|
$this->assertEquals($expected, $actual); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testSetEntitySetBadData() |
87
|
|
|
{ |
88
|
|
|
$expected = ""; |
89
|
|
|
$actual = null; |
90
|
|
|
|
91
|
|
|
$entitySet = m::mock(TOperandType::class)->makePartial(); |
92
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(false)->once(); |
93
|
|
|
|
94
|
|
|
$foo = new FunctionImportAnonymousType(); |
95
|
|
|
|
96
|
|
|
try { |
97
|
|
|
$foo->setEntitySet($entitySet); |
|
|
|
|
98
|
|
|
} catch (\InvalidArgumentException $e) { |
99
|
|
|
$actual = $e->getMessage(); |
100
|
|
|
} |
101
|
|
|
$this->assertEquals($expected, $actual); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testSetEntitySetRoundTrip() |
105
|
|
|
{ |
106
|
|
|
$entitySet = m::mock(TOperandType::class)->makePartial(); |
107
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(true)->twice(); |
108
|
|
|
|
109
|
|
|
$foo = new FunctionImportAnonymousType(); |
110
|
|
|
|
111
|
|
|
$foo->setEntitySet($entitySet); |
|
|
|
|
112
|
|
|
$result = $foo->getEntitySet(); |
113
|
|
|
$this->assertTrue($result->isOK()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testAddToReturnTypeBadData() |
117
|
|
|
{ |
118
|
|
|
$expected = ""; |
119
|
|
|
$actual = null; |
120
|
|
|
|
121
|
|
|
$entitySet = m::mock(TFunctionImportReturnTypeType::class)->makePartial(); |
122
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(false)->once(); |
123
|
|
|
|
124
|
|
|
$foo = new FunctionImportAnonymousType(); |
125
|
|
|
|
126
|
|
|
try { |
127
|
|
|
$foo->addToReturnType($entitySet); |
|
|
|
|
128
|
|
|
} catch (\InvalidArgumentException $e) { |
129
|
|
|
$actual = $e->getMessage(); |
130
|
|
|
} |
131
|
|
|
$this->assertEquals($expected, $actual); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testUnsetMissingReturnTypeIndex() |
135
|
|
|
{ |
136
|
|
|
$foo = new FunctionImportAnonymousType(); |
137
|
|
|
|
138
|
|
|
$foo->unsetReturnType(0); |
139
|
|
|
$this->assertFalse($foo->issetReturnType(0)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testGetReturnTypeEmptyArray() |
143
|
|
|
{ |
144
|
|
|
$foo = new FunctionImportAnonymousType(); |
145
|
|
|
$this->assertEquals(0, count($foo->getReturnType())); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
View Code Duplication |
public function testSetReturnTypeBadData() |
|
|
|
|
149
|
|
|
{ |
150
|
|
|
$expected = ""; |
151
|
|
|
$actual = null; |
152
|
|
|
|
153
|
|
|
$entitySet = m::mock(TFunctionImportReturnTypeType::class)->makePartial(); |
154
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(false)->once(); |
155
|
|
|
|
156
|
|
|
$foo = new FunctionImportAnonymousType(); |
157
|
|
|
|
158
|
|
|
try { |
159
|
|
|
$foo->setReturnType([$entitySet]); |
|
|
|
|
160
|
|
|
} catch (\InvalidArgumentException $e) { |
161
|
|
|
$actual = $e->getMessage(); |
162
|
|
|
} |
163
|
|
|
$this->assertEquals($expected, $actual); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testSetNameBadData() |
167
|
|
|
{ |
168
|
|
|
$expected = "Name must be a valid TSimpleIdentifier"; |
169
|
|
|
$actual = null; |
170
|
|
|
|
171
|
|
|
$foo = new FunctionImportAnonymousType(); |
172
|
|
|
|
173
|
|
|
try { |
174
|
|
|
$foo->setName(" _ "); |
175
|
|
|
} catch (\InvalidArgumentException $e) { |
176
|
|
|
$actual = $e->getMessage(); |
177
|
|
|
} |
178
|
|
|
$this->assertEquals($expected, $actual); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function testIsTFunctionImportAttributesValid() |
182
|
|
|
{ |
183
|
|
|
$expected = "Name must be a valid TSimpleIdentifier:" |
184
|
|
|
." AlgoWeb\\ODataMetadata\\MetadataV3\\edm\\EntityContainer\\FunctionImportAnonymousType"; |
185
|
|
|
$actual = null; |
186
|
|
|
|
187
|
|
|
$foo = new FunctionImportAnonymousType(); |
188
|
|
|
$foo->isTFunctionImportAttributesValid($actual); |
189
|
|
|
$this->assertEquals($expected, $actual); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function testIsComposableAndSideEffecting() |
193
|
|
|
{ |
194
|
|
|
$expected = "Cannot both be composable and side-effecting"; |
195
|
|
|
$actual = null; |
196
|
|
|
|
197
|
|
|
$foo = new FunctionImportAnonymousType(); |
198
|
|
|
$foo->setName("Name"); |
199
|
|
|
$foo->setIsComposable(true); |
200
|
|
|
$foo->setIsSideEffecting(true); |
201
|
|
|
|
202
|
|
|
$foo->isTFunctionImportAttributesValid($actual); |
203
|
|
|
$this->assertEquals($expected, $actual); |
204
|
|
|
$this->assertEquals("Name", $foo->getName()); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function testIsTFunctionImportAttributesValidWithAccessSet() |
208
|
|
|
{ |
209
|
|
|
$foo = new FunctionImportAnonymousType(); |
210
|
|
|
$foo->setName("Name"); |
211
|
|
|
$foo->setMethodAccess('Public'); |
212
|
|
|
|
213
|
|
|
$msg = null; |
214
|
|
|
$this->assertTrue($foo->isTFunctionImportAttributesValid($msg)); |
215
|
|
|
$this->assertNull($msg); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function testIsTFunctionImportAttributesValidWithBadEntitySet() |
219
|
|
|
{ |
220
|
|
|
$expectedStarts = "Entity set must be either null or an instance of TOperandType:"; |
221
|
|
|
$expectedEnds = "AlgoWeb\\ODataMetadata\\MetadataV3\\edm\\EntityContainer\\FunctionImportAnonymousType"; |
222
|
|
|
$actual = null; |
223
|
|
|
|
224
|
|
|
$entitySet = m::mock(TOperandType::class)->makePartial(); |
225
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(true, false)->twice(); |
226
|
|
|
|
227
|
|
|
$foo = new FunctionImportAnonymousType(); |
228
|
|
|
$foo->setName("Name"); |
229
|
|
|
$foo->setMethodAccess('Public'); |
230
|
|
|
$foo->setEntitySet($entitySet); |
|
|
|
|
231
|
|
|
|
232
|
|
|
$this->assertFalse($foo->isTFunctionImportAttributesValid($actual)); |
233
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
234
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
View Code Duplication |
public function testIsTFunctionImportAttributesValidWithBadReturnType() |
|
|
|
|
238
|
|
|
{ |
239
|
|
|
$expected = ""; |
240
|
|
|
$actual = null; |
241
|
|
|
|
242
|
|
|
$entitySet = m::mock(TFunctionImportReturnTypeType::class)->makePartial(); |
243
|
|
|
$entitySet->shouldReceive('isOK')->andReturn(true, false)->once(); |
244
|
|
|
|
245
|
|
|
$foo = new FunctionImportAnonymousType(); |
246
|
|
|
$foo->setName("Name"); |
247
|
|
|
$foo->setMethodAccess('Public'); |
248
|
|
|
$foo->addToReturnType($entitySet); |
|
|
|
|
249
|
|
|
|
250
|
|
|
$this->assertFalse($foo->isTFunctionImportAttributesValid($actual)); |
251
|
|
|
$this->assertEquals($expected, $actual); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
View Code Duplication |
public function testSetBadDocumentation() |
|
|
|
|
255
|
|
|
{ |
256
|
|
|
$expected = ""; |
257
|
|
|
$actual = null; |
258
|
|
|
|
259
|
|
|
$documentation = m::mock(TDocumentationType::class); |
260
|
|
|
$documentation->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
261
|
|
|
|
262
|
|
|
$foo = new FunctionImportAnonymousType(); |
263
|
|
|
|
264
|
|
|
try { |
265
|
|
|
$foo->setDocumentation($documentation); |
266
|
|
|
} catch (\InvalidArgumentException $e) { |
267
|
|
|
$actual = $e->getMessage(); |
268
|
|
|
} |
269
|
|
|
$this->assertEquals($expected, $actual); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
View Code Duplication |
public function testAddBadParameter() |
|
|
|
|
273
|
|
|
{ |
274
|
|
|
$expected = ""; |
275
|
|
|
$actual = null; |
276
|
|
|
|
277
|
|
|
$function = m::mock(TFunctionImportParameterType::class); |
278
|
|
|
$function->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
279
|
|
|
|
280
|
|
|
$foo = new FunctionImportAnonymousType(); |
281
|
|
|
|
282
|
|
|
try { |
283
|
|
|
$foo->addToParameter($function); |
284
|
|
|
} catch (\InvalidArgumentException $e) { |
285
|
|
|
$actual = $e->getMessage(); |
286
|
|
|
} |
287
|
|
|
$this->assertEquals($expected, $actual); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
View Code Duplication |
public function testAddGoodParameter() |
|
|
|
|
291
|
|
|
{ |
292
|
|
|
$function = m::mock(TFunctionImportParameterType::class); |
293
|
|
|
$function->shouldReceive('isOK')->andReturn(true)->once(); |
|
|
|
|
294
|
|
|
|
295
|
|
|
$foo = new FunctionImportAnonymousType(); |
296
|
|
|
$foo->addToParameter($function); |
297
|
|
|
$this->assertTrue($foo->issetParameter(0)); |
298
|
|
|
$this->assertFalse($foo->issetParameter(1)); |
299
|
|
|
$this->assertEquals(1, count($foo->getParameter())); |
300
|
|
|
$foo->unsetParameter(0); |
301
|
|
|
$this->assertEquals(0, count($foo->getParameter())); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
View Code Duplication |
public function testSetBadParameterArray() |
|
|
|
|
305
|
|
|
{ |
306
|
|
|
$expected = ""; |
307
|
|
|
$actual = null; |
308
|
|
|
|
309
|
|
|
$function = m::mock(TFunctionImportParameterType::class); |
310
|
|
|
$function->shouldReceive('isOK')->andReturn(false)->once(); |
|
|
|
|
311
|
|
|
|
312
|
|
|
$foo = new FunctionImportAnonymousType(); |
313
|
|
|
|
314
|
|
|
try { |
315
|
|
|
$foo->setParameter([$function]); |
|
|
|
|
316
|
|
|
} catch (\InvalidArgumentException $e) { |
317
|
|
|
$actual = $e->getMessage(); |
318
|
|
|
} |
319
|
|
|
$this->assertEquals($expected, $actual); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
public function testIsOkUnderParameterNameCollision() |
323
|
|
|
{ |
324
|
|
|
$expected = "Name collision in parameters array"; |
325
|
|
|
$actual = null; |
326
|
|
|
|
327
|
|
|
$function = m::mock(TFunctionImportParameterType::class)->makePartial(); |
328
|
|
|
$function->shouldReceive('isOK')->andReturn(true)->once(); |
329
|
|
|
$function->shouldReceive('getName')->andReturn('noname'); |
330
|
|
|
$this->assertTrue($function instanceof TFunctionImportParameterType); |
331
|
|
|
|
332
|
|
|
$func2 = m::mock(TFunctionImportParameterType::class)->makePartial(); |
333
|
|
|
$func2->shouldReceive('isOK')->andReturn(true)->once(); |
334
|
|
|
$func2->shouldReceive('getName')->andReturn('name'); |
335
|
|
|
$this->assertTrue($func2 instanceof TFunctionImportParameterType); |
336
|
|
|
|
337
|
|
|
$func3 = m::mock(TFunctionImportParameterType::class)->makePartial(); |
338
|
|
|
$func3->shouldReceive('isOK')->andReturn(true)->once(); |
339
|
|
|
$func3->shouldReceive('getName')->andReturn('name'); |
340
|
|
|
$this->assertTrue($func3 instanceof TFunctionImportParameterType); |
341
|
|
|
|
342
|
|
|
$foo = m::mock(FunctionImportAnonymousType::class)->makePartial()->shouldAllowMockingProtectedMethods(); |
343
|
|
|
$foo->shouldReceive('isObjectNullOrOK')->andReturn(true); |
344
|
|
|
$foo->shouldReceive('isValidArrayOK')->andReturn(true); |
345
|
|
|
$foo->shouldReceive('isTFunctionImportAttributesValid')->andReturn(true); |
346
|
|
|
$foo->setParameter([]); |
347
|
|
|
$foo->addToParameter($function); |
348
|
|
|
$foo->addToParameter($func2); |
349
|
|
|
$foo->addToParameter($func3); |
350
|
|
|
|
351
|
|
|
$this->assertFalse($foo->isOK($actual)); |
352
|
|
|
$this->assertEquals($expected, $actual); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
View Code Duplication |
public function testIsNotOkFromBadDocumentation() |
|
|
|
|
356
|
|
|
{ |
357
|
|
|
$expected = ""; |
358
|
|
|
$actual = null; |
359
|
|
|
|
360
|
|
|
$documentation = m::mock(TDocumentationType::class); |
361
|
|
|
$documentation->shouldReceive('isOK')->andReturn(true, false)->once(); |
|
|
|
|
362
|
|
|
|
363
|
|
|
$foo = new FunctionImportAnonymousType(); |
364
|
|
|
$foo->setDocumentation($documentation); |
365
|
|
|
|
366
|
|
|
$this->assertFalse($foo->isOK($actual)); |
367
|
|
|
$this->assertEquals($expected, $actual); |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: