@@ -42,6 +42,14 @@ public function setUp()
42
42
$ this ->objectManagerMock = $ this ->getMockBuilder ('\Magento\Framework\ObjectManagerInterface ' )
43
43
->disableOriginalConstructor ()
44
44
->getMock ();
45
+ $ this ->objectManagerMock ->expects ($ this ->any ())
46
+ ->method ('create ' )
47
+ ->willReturnCallback (
48
+ function ($ className ) use ($ objectManager ) {
49
+ return $ objectManager ->getObject ($ className );
50
+ }
51
+ );
52
+
45
53
/** @var \Magento\Framework\Reflection\TypeProcessor $typeProcessor */
46
54
$ typeProcessor = $ objectManager ->getObject ('Magento\Framework\Reflection\TypeProcessor ' );
47
55
$ cache = $ this ->getMockBuilder ('Magento\Framework\App\Cache\Type\Webapi ' )
@@ -119,12 +127,6 @@ public function testNonExistentPropertiesWithoutDefaultArgumentValue()
119
127
120
128
public function testNestedDataProperties ()
121
129
{
122
- $ this ->setupFactory (
123
- [
124
- 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Nested ' ,
125
- '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple ' ,
126
- ]
127
- );
128
130
$ data = ['nested ' => ['details ' => ['entityId ' => 15 , 'name ' => 'Test ' ]]];
129
131
$ result = $ this ->serviceInputProcessor ->process (
130
132
'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService ' ,
@@ -167,7 +169,6 @@ public function testSimpleArrayProperties()
167
169
168
170
public function testAssociativeArrayProperties ()
169
171
{
170
- $ this ->setupFactory (['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple ' ]);
171
172
$ data = ['associativeArray ' => ['key ' => 'value ' , 'key_two ' => 'value_two ' ]];
172
173
$ result = $ this ->serviceInputProcessor ->process (
173
174
'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService ' ,
@@ -186,7 +187,6 @@ public function testAssociativeArrayProperties()
186
187
187
188
public function testAssociativeArrayPropertiesWithItem ()
188
189
{
189
- $ this ->setupFactory (['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray ' ]);
190
190
$ data = ['associativeArray ' => ['item ' => 'value ' ]];
191
191
$ result = $ this ->serviceInputProcessor ->process (
192
192
'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService ' ,
@@ -204,7 +204,6 @@ public function testAssociativeArrayPropertiesWithItem()
204
204
205
205
public function testAssociativeArrayPropertiesWithItemArray ()
206
206
{
207
- $ this ->setupFactory (['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray ' ]);
208
207
$ data = ['associativeArray ' => ['item ' => ['value1 ' ,'value2 ' ]]];
209
208
$ result = $ this ->serviceInputProcessor ->process (
210
209
'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService ' ,
@@ -223,11 +222,6 @@ public function testAssociativeArrayPropertiesWithItemArray()
223
222
224
223
public function testArrayOfDataObjectProperties ()
225
224
{
226
- $ this ->setupFactory (
227
- [
228
- '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple '
229
- ]
230
- );
231
225
$ data = [
232
226
'dataObjects ' => [
233
227
['entityId ' => 14 , 'name ' => 'First ' ],
@@ -259,7 +253,6 @@ public function testArrayOfDataObjectProperties()
259
253
260
254
public function testNestedSimpleArrayProperties ()
261
255
{
262
- $ this ->setupFactory (['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray ' ]);
263
256
$ data = ['arrayData ' => ['ids ' => [1 , 2 , 3 , 4 ]]];
264
257
$ result = $ this ->serviceInputProcessor ->process (
265
258
'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService ' ,
@@ -281,7 +274,6 @@ public function testNestedSimpleArrayProperties()
281
274
282
275
public function testNestedAssociativeArrayProperties ()
283
276
{
284
- $ this ->setupFactory (['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray ' ]);
285
277
$ data = [
286
278
'associativeArrayData ' => ['associativeArray ' => ['key ' => 'value ' , 'key2 ' => 'value2 ' ]],
287
279
];
@@ -305,12 +297,6 @@ public function testNestedAssociativeArrayProperties()
305
297
306
298
public function testNestedArrayOfDataObjectProperties ()
307
299
{
308
- $ this ->setupFactory (
309
- [
310
- 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\DataArray ' ,
311
- '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple ' ,
312
- ]
313
- );
314
300
$ data = [
315
301
'dataObjects ' => [
316
302
'items ' => [['entityId ' => 1 , 'name ' => 'First ' ], ['entityId ' => 2 , 'name ' => 'Second ' ]],
@@ -352,14 +338,6 @@ public function testNestedArrayOfDataObjectProperties()
352
338
*/
353
339
public function testCustomAttributesProperties ($ customAttributeType , $ inputData , $ expectedObject )
354
340
{
355
- $ this ->setupFactory (
356
- [
357
- 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\ObjectWithCustomAttributes ' ,
358
- '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple ' ,
359
- 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple ' ,
360
- 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray ' ,
361
- ]
362
- );
363
341
$ this ->customAttributeTypeLocator ->expects ($ this ->any ())->method ('getType ' )->willReturn ($ customAttributeType );
364
342
365
343
$ result = $ this ->serviceInputProcessor ->process (
@@ -521,27 +499,4 @@ protected function getObjectWithCustomAttributes($type, $value = [])
521
499
]]
522
500
);
523
501
}
524
- protected function setupFactory (array $ classNames )
525
- {
526
- $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
527
-
528
- $ returnValueMap = [];
529
- foreach ($ classNames as $ className ) {
530
- $ factoryMock = $ this ->getMockBuilder ($ className . 'Factory ' )
531
- ->setMethods (['create ' ])
532
- ->disableOriginalConstructor ()
533
- ->getMock ();
534
- $ factoryMock ->expects ($ this ->any ())
535
- ->method ('create ' )
536
- ->willReturnCallback (
537
- function () use ($ objectManager , $ className ) {
538
- return $ objectManager ->getObject ($ className );
539
- }
540
- );
541
- $ returnValueMap [] = [$ className . 'Factory ' , $ factoryMock ];
542
- }
543
- $ this ->objectManagerMock ->expects ($ this ->any ())
544
- ->method ('get ' )
545
- ->will ($ this ->returnValueMap ($ returnValueMap ));
546
- }
547
502
}
0 commit comments