@@ -314,4 +314,131 @@ public function testCreateVariadicFromDiConfig()
314
314
$ this ->assertSame ($ oneScalar1 , $ variadic ->getOneScalarByKey (0 ));
315
315
$ this ->assertSame ($ oneScalar2 , $ variadic ->getOneScalarByKey (1 ));
316
316
}
317
+
318
+ /**
319
+ * Test create objects with non variadic and variadic argument in constructor
320
+ *
321
+ * @param $createArgs
322
+ * @param $expectedFooValue
323
+ * @param $expectedArg0
324
+ * @param $expectedArg1
325
+ * @dataProvider testCreateUsingSemiVariadicDataProvider
326
+ */
327
+ public function testCreateUsingSemiVariadic (
328
+ $ createArgs ,
329
+ $ expectedFooValue ,
330
+ $ expectedArg0 ,
331
+ $ expectedArg1
332
+ ) {
333
+ $ type = \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::class;
334
+ $ definitions = $ this ->createMock (\Magento \Framework \ObjectManager \DefinitionInterface::class);
335
+
336
+ $ definitions ->expects ($ this ->once ())->method ('getParameters ' )->with ($ type )->will (
337
+ $ this ->returnValue (
338
+ [
339
+ [
340
+ 'foo ' ,
341
+ null ,
342
+ false ,
343
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::DEFAULT_FOO_VALUE ,
344
+ false
345
+ ],
346
+ [
347
+ 'oneScalars ' ,
348
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \OneScalar::class,
349
+ false ,
350
+ [],
351
+ true
352
+ ],
353
+ ]
354
+ )
355
+ );
356
+ $ factory = new Developer ($ this ->config , null , $ definitions );
357
+
358
+ /**
359
+ * @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\SemiVariadic $semiVariadic
360
+ */
361
+ $ semiVariadic = is_null ($ createArgs )
362
+ ? $ factory ->create ($ type )
363
+ : $ factory ->create ($ type , $ createArgs );
364
+
365
+ $ this ->assertSame ($ expectedFooValue , $ semiVariadic ->getFoo ());
366
+ $ this ->assertSame ($ expectedArg0 , $ semiVariadic ->getOneScalarByKey (0 ));
367
+ $ this ->assertSame ($ expectedArg1 , $ semiVariadic ->getOneScalarByKey (1 ));
368
+ }
369
+
370
+ /**
371
+ * @return array
372
+ */
373
+ public function testCreateUsingSemiVariadicDataProvider ()
374
+ {
375
+ $ oneScalar1 = $ this ->createMock (\Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \OneScalar::class);
376
+ $ oneScalar2 = $ this ->createMock (\Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \OneScalar::class);
377
+
378
+ return [
379
+ 'without_args ' => [
380
+ null ,
381
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::DEFAULT_FOO_VALUE ,
382
+ null ,
383
+ null ,
384
+ ],
385
+ 'with_empty_args ' => [
386
+ [],
387
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::DEFAULT_FOO_VALUE ,
388
+ null ,
389
+ null ,
390
+ ],
391
+ 'only_with_foo_value ' => [
392
+ [
393
+ 'foo ' => 'baz '
394
+ ],
395
+ 'baz ' ,
396
+ null ,
397
+ null ,
398
+ ],
399
+ 'only_with_oneScalars_empty_value ' => [
400
+ [
401
+ 'oneScalars ' => []
402
+ ],
403
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::DEFAULT_FOO_VALUE ,
404
+ null ,
405
+ null ,
406
+ ],
407
+ 'only_with_oneScalars_full_value ' => [
408
+ [
409
+ 'oneScalars ' => [
410
+ $ oneScalar1 ,
411
+ $ oneScalar2 ,
412
+ ]
413
+ ],
414
+ \Magento \Framework \ObjectManager \Test \Unit \Factory \Fixture \SemiVariadic::DEFAULT_FOO_VALUE ,
415
+ $ oneScalar1 ,
416
+ $ oneScalar2 ,
417
+ ],
418
+ 'with_all_values_defined_in_right_order ' => [
419
+ [
420
+ 'foo ' => 'baz ' ,
421
+ 'oneScalars ' => [
422
+ $ oneScalar1 ,
423
+ $ oneScalar2 ,
424
+ ]
425
+ ],
426
+ 'baz ' ,
427
+ $ oneScalar1 ,
428
+ $ oneScalar2 ,
429
+ ],
430
+ 'with_all_values_defined_in_reverse_order ' => [
431
+ [
432
+ 'oneScalars ' => [
433
+ $ oneScalar1 ,
434
+ $ oneScalar2 ,
435
+ ],
436
+ 'foo ' => 'baz ' ,
437
+ ],
438
+ 'baz ' ,
439
+ $ oneScalar1 ,
440
+ $ oneScalar2 ,
441
+ ],
442
+ ];
443
+ }
317
444
}
0 commit comments