@@ -73,6 +73,10 @@ class FooExtension extends Nette\DI\CompilerExtension
7373 $ builder ->addDefinition ('one8 ' )
7474 ->setFactory ('Lorem ' , [1 ])
7575 ->addSetup ('__construct ' , [2 ]);
76+ $ builder ->addDefinition ('one9 ' )
77+ ->setFactory ('Lorem ' , [1 ]);
78+ $ builder ->addDefinition ('one10 ' )
79+ ->setFactory ('Lorem ' , [1 ]);
7680
7781 $ builder ->addDefinition ('two1 ' )
7882 ->setType ('Lorem ' )
@@ -101,6 +105,12 @@ class FooExtension extends Nette\DI\CompilerExtension
101105 $ builder ->addDefinition ('two9 ' )
102106 ->setType ('Lorem ' )
103107 ->setFactory ('Factory::createLorem ' , [1 , 2 ]);
108+ $ builder ->addDefinition ('two10 ' )
109+ ->setType ('Lorem ' )
110+ ->setFactory ('Factory::createLorem ' , [1 ]);
111+ $ builder ->addDefinition ('two11 ' )
112+ ->setType ('Lorem ' )
113+ ->setFactory ('Factory::createLorem ' , [1 ]);
104114
105115 $ builder ->addDefinition ('three1 ' )
106116 ->setFactory ('Factory::createLorem ' , [1 ]);
@@ -116,6 +126,10 @@ class FooExtension extends Nette\DI\CompilerExtension
116126 ->setFactory ('Factory::createLorem ' , [1 ]);
117127 $ builder ->addDefinition ('three7 ' )
118128 ->setFactory ('Factory::createLorem ' , [1 ]);
129+ $ builder ->addDefinition ('three8 ' )
130+ ->setFactory ('Factory::createLorem ' , [1 ]);
131+ $ builder ->addDefinition ('three9 ' )
132+ ->setFactory ('Factory::createLorem ' , [1 ]);
119133 }
120134}
121135
@@ -166,6 +180,16 @@ Assert::same([
166180 'Ipsum::__construct ' ,
167181], Notes::fetch ());
168182
183+ Assert::exception (function () use ($ container ) {
184+ $ container ->getService ('one9 ' );
185+ }, TypeError::class, 'Return value of %a%::createServiceOne9() must be an instance of Ipsum, instance of Lorem returned ' );
186+ Notes::fetch ();
187+
188+ Assert::type (Ipsum::class, $ container ->getService ('one10 ' ));
189+ Assert::same ([
190+ 'Ipsum::__construct ' ,
191+ ], Notes::fetch ());
192+
169193
170194Assert::type (Ipsum::class, $ container ->getService ('two1 ' ));
171195Assert::same ([
@@ -217,6 +241,16 @@ Assert::same([
217241 'Lorem::__construct 2 new ' ,
218242], Notes::fetch ());
219243
244+ Assert::exception (function () use ($ container ) {
245+ $ container ->getService ('two11 ' );
246+ }, TypeError::class, 'Return value of %a%::createServiceTwo11() must be an instance of Ipsum, instance of Lorem returned ' );
247+ Notes::fetch ();
248+
249+ Assert::type (Ipsum::class, $ container ->getService ('two12 ' ));
250+ Assert::same ([
251+ 'Ipsum::__construct ' ,
252+ ], Notes::fetch ());
253+
220254
221255
222256Assert::type (Ipsum::class, $ container ->getService ('three1 ' ));
@@ -253,3 +287,13 @@ Assert::type(Ipsum::class, $container->getService('three7'));
253287Assert::same ([
254288 'Ipsum::__construct 2 ' ,
255289], Notes::fetch ());
290+
291+ Assert::exception (function () use ($ container ) {
292+ $ container ->getService ('three8 ' );
293+ }, TypeError::class, 'Return value of %a%::createServiceThree8() must be an instance of Ipsum, instance of Lorem returned ' );
294+ Notes::fetch ();
295+
296+ Assert::type (Ipsum::class, $ container ->getService ('three9 ' ));
297+ Assert::same ([
298+ 'Ipsum::__construct ' ,
299+ ], Notes::fetch ());
0 commit comments