@@ -484,175 +484,108 @@ public function testDelegatorsDoNotTriggerForAliasTargetingFactoryBasedServiceUs
484
484
// as that when fetched by the canonical service name.
485
485
self ::assertSame ($ instance , $ container ->get ('service ' ));
486
486
}
487
-
488
- // @codingStandardsIgnoreStart
489
- public function testWhenInvokableWithDelegatorsResolvesToNonExistentClassNoExceptionIsRaisedIfCallbackNeverInvoked ()
490
- {
491
- // @codingStandardsIgnoreEnd
492
- $ container = $ this ->createContainer ([
493
- 'invokables ' => [
494
- TestAsset \NonExistent::class,
495
- ],
496
- 'delegators ' => [
497
- TestAsset \NonExistent::class => [
498
- TestAsset \DelegatorFactory::class,
499
- ],
500
- ],
501
- ]);
502
487
503
- self ::assertTrue ($ container ->has (TestAsset \NonExistent::class));
504
- $ instance = $ container ->get (TestAsset \NonExistent::class);
505
- self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
506
- }
507
-
508
- // @codingStandardsIgnoreStart
509
- public function testWhenInvokableWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedIfCallbackNeverInvoked ()
488
+ public function invalidService ()
510
489
{
511
- // @codingStandardsIgnoreEnd
512
- $ container = $ this ->createContainer ([
513
- 'invokables ' => [
514
- TestAsset \FactoryWithRequiredParameters::class,
515
- ],
516
- 'delegators ' => [
517
- TestAsset \FactoryWithRequiredParameters::class => [
518
- TestAsset \DelegatorFactory::class,
519
- ],
520
- ],
521
- ]);
490
+ yield 'non-existent-invokable ' => [
491
+ ['invokables ' => [TestAsset \NonExistent::class]],
492
+ TestAsset \NonExistent::class,
493
+ TestAsset \NonExistent::class,
494
+ ];
522
495
523
- self ::assertTrue ($ container ->has (TestAsset \FactoryWithRequiredParameters::class));
524
- $ instance = $ container ->get (TestAsset \FactoryWithRequiredParameters::class);
525
- self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
526
- }
527
-
528
- public function testWhenInvokableWithDelegatorsResolvesToNonExistentClassAnExceptionIsRaisedWhenCallbackIsInvoked ()
529
- {
530
- $ container = $ this ->createContainer ([
531
- 'invokables ' => [
532
- TestAsset \NonExistent::class,
533
- ],
534
- 'delegators ' => [
535
- TestAsset \NonExistent::class => [
536
- TestAsset \Delegator1Factory::class,
537
- ],
538
- ],
539
- ]);
496
+ yield 'non-existent-aliased-invokable ' => [
497
+ ['invokables ' => ['service ' => TestAsset \NonExistent::class]],
498
+ 'service ' ,
499
+ TestAsset \NonExistent::class,
500
+ ];
540
501
541
- self ::assertTrue ($ container ->has (TestAsset \NonExistent::class));
502
+ yield 'non-existent-factory ' => [
503
+ ['factories ' => ['service ' => TestAsset \NonExistent::class]],
504
+ 'service ' ,
505
+ 'service ' ,
506
+ ];
542
507
543
- Assert::expectedExceptions (
544
- function () use ($ container ) {
545
- $ container ->get (TestAsset \NonExistent::class);
546
- },
547
- [Error::class, ContainerExceptionInterface::class]
548
- );
549
- }
550
-
551
- // @codingStandardsIgnoreStart
552
- public function testWhenInvokableWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked ()
553
- {
554
- // @codingStandardsIgnoreEnd
555
- $ container = $ this ->createContainer ([
556
- 'invokables ' => [
557
- TestAsset \FactoryWithRequiredParameters::class,
558
- ],
559
- 'delegators ' => [
560
- 'service ' => [
561
- TestAsset \Delegator1Factory::class,
562
- ],
508
+ yield 'non-existent-aliased-factory ' => [
509
+ [
510
+ 'aliases ' => ['alias ' => 'service ' ],
511
+ 'factories ' => ['service ' => TestAsset \NonExistent::class],
563
512
],
564
- ]);
513
+ 'alias ' ,
514
+ 'service ' ,
515
+ ];
565
516
566
- self ::assertTrue ($ container ->has (TestAsset \FactoryWithRequiredParameters::class));
517
+ yield 'invalid-invokable ' => [
518
+ ['invokables ' => [TestAsset \FactoryWithRequiredParameters::class]],
519
+ TestAsset \FactoryWithRequiredParameters::class,
520
+ TestAsset \FactoryWithRequiredParameters::class,
521
+ ];
567
522
568
- Assert::expectedExceptions (
569
- function () use ($ container ) {
570
- $ container ->get (TestAsset \FactoryWithRequiredParameters::class);
571
- },
572
- [ArgumentCountError::class, ContainerExceptionInterface::class]
573
- );
574
- }
575
-
576
- // @codingStandardsIgnoreStart
577
- public function testWhenServiceWithDelegatorsResolvesToNonExistentFactoryClassNoExceptionIsRaisedIfCallbackNeverInvoked ()
578
- {
579
- // @codingStandardsIgnoreEnd
580
- $ container = $ this ->createContainer ([
581
- 'factories ' => [
582
- 'service ' => TestAsset \NonExistentFactory::class,
583
- ],
584
- 'delegators ' => [
585
- 'service ' => [
586
- TestAsset \DelegatorFactory::class,
587
- ],
588
- ],
589
- ]);
523
+ yield 'invalid-aliased-invokable ' => [
524
+ ['invokables ' => ['service ' => TestAsset \FactoryWithRequiredParameters::class]],
525
+ 'service ' ,
526
+ TestAsset \FactoryWithRequiredParameters::class,
527
+ ];
590
528
591
- self ::assertTrue ($ container ->has ('service ' ));
592
- $ instance = $ container ->get ('service ' );
593
- self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
594
- }
595
-
596
- // @codingStandardsIgnoreStart
597
- public function testWhenServiceWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedIfCallbackNeverInvoked ()
598
- {
599
- // @codingStandardsIgnoreEnd
600
- $ container = $ this ->createContainer ([
601
- 'factories ' => [
602
- 'service ' => TestAsset \FactoryWithRequiredParameters::class,
529
+ yield 'invalid-factory ' => [
530
+ ['factories ' => ['service ' => TestAsset \FactoryWithRequiredParameters::class]],
531
+ 'service ' ,
532
+ 'service ' ,
533
+ ];
534
+
535
+ yield 'invalid-aliased-factory ' => [
536
+ [
537
+ 'aliases ' => ['alias ' => 'service ' ],
538
+ 'factories ' => ['service ' => TestAsset \FactoryWithRequiredParameters::class],
603
539
],
540
+ 'alias ' ,
541
+ 'service ' ,
542
+ ];
543
+ }
544
+
545
+ /**
546
+ * @dataProvider invalidService
547
+ */
548
+ public function testWithDelegatorsResolvesToInvalidClassNoExceptionIsRaisedIfCallbackNeverInvoked (
549
+ array $ config ,
550
+ string $ serviceNameToTest ,
551
+ string $ delegatedServiceName
552
+ ) : void {
553
+ $ container = $ this ->createContainer ($ config + [
604
554
'delegators ' => [
605
- ' service ' => [
555
+ $ delegatedServiceName => [
606
556
TestAsset \DelegatorFactory::class,
607
557
],
608
558
],
609
559
]);
610
560
611
- self ::assertTrue ($ container ->has (' service ' ));
612
- $ instance = $ container ->get (' service ' );
561
+ self ::assertTrue ($ container ->has ($ serviceNameToTest ));
562
+ $ instance = $ container ->get ($ serviceNameToTest );
613
563
self ::assertInstanceOf (TestAsset \Delegator::class, $ instance );
614
564
}
615
-
616
- // @codingStandardsIgnoreStart
617
- public function testWhenServiceWithDelegatorsResolvesToNonExistentFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked ()
618
- {
619
- // @codingStandardsIgnoreEnd
620
- $ container = $ this ->createContainer ([
621
- 'factories ' => [
622
- 'service ' => TestAsset \NonExistentFactory::class,
623
- ],
624
- 'delegators ' => [
625
- 'service ' => [
626
- TestAsset \Delegator1Factory::class,
627
- ],
628
- ],
629
- ]);
630
565
631
- self ::assertTrue ($ container ->has ('service ' ));
632
- $ this ->expectException (ContainerExceptionInterface::class);
633
- $ container ->get ('service ' );
634
- }
635
-
636
- public function testWhenServiceWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked ()
637
- {
638
- $ container = $ this ->createContainer ([
639
- 'factories ' => [
640
- 'service ' => TestAsset \FactoryWithRequiredParameters::class,
641
- ],
566
+ /**
567
+ * @dataProvider invalidService
568
+ */
569
+ public function testWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedWhenCallbackIsInvoked (
570
+ array $ config ,
571
+ string $ serviceNameToTest ,
572
+ string $ delegatedServiceName
573
+ ) : void {
574
+ $ container = $ this ->createContainer ($ config + [
642
575
'delegators ' => [
643
- ' service ' => [
576
+ $ delegatedServiceName => [
644
577
TestAsset \Delegator1Factory::class,
645
578
],
646
579
],
647
580
]);
648
581
649
- self ::assertTrue ($ container ->has (' service ' ));
582
+ self ::assertTrue ($ container ->has ($ serviceNameToTest ));
650
583
651
584
Assert::expectedExceptions (
652
- function () use ($ container ) {
653
- $ container ->get (' service ' );
585
+ function () use ($ container, $ serviceNameToTest ) {
586
+ $ container ->get ($ serviceNameToTest );
654
587
},
655
- [ArgumentCountError ::class, ContainerExceptionInterface::class]
588
+ [Error ::class, ContainerExceptionInterface::class]
656
589
);
657
590
}
658
591
}
0 commit comments