1212use Selective \Container \Exceptions \InvalidDefinitionException ;
1313use Selective \Container \Exceptions \NotFoundException ;
1414use Selective \Container \Resolver \ConstructorResolver ;
15+ use Selective \Container \Resolver \DefinitionResolverInterface ;
1516use Selective \Container \Test \TestCase \Service \MyAbstractService ;
1617use Selective \Container \Test \TestCase \Service \MyService ;
1718use Selective \Container \Test \TestCase \Service \MyServiceA ;
@@ -290,16 +291,7 @@ public function testAutowireWithInvalidInternalClass(): void
290291 $ container = new Container ();
291292 $ container ->addResolver (new ConstructorResolver ($ container ));
292293
293- // https://3v4l.org/1AXpr
294- if (version_compare (PHP_VERSION , '8.0.0 ' ) >= 0 ) {
295- // PHP 8+
296- $ this ->assertInstanceOf (Exception::class, $ container ->get (Exception::class));
297- } else {
298- // PHP 7.x
299- // Cannot determine default value for internal functions
300- $ this ->expectException (InvalidDefinitionException::class);
301- $ container ->get (Exception::class);
302- }
294+ $ this ->assertInstanceOf (Exception::class, $ container ->get (Exception::class));
303295 }
304296
305297 /**
@@ -312,15 +304,7 @@ public function testAutowireWithInvalidInternalInterface(): void
312304 $ container = new Container ();
313305 $ container ->addResolver (new ConstructorResolver ($ container ));
314306
315- if (version_compare (PHP_VERSION , '8.0.0 ' ) >= 0 ) {
316- // PHP 8+
317- $ this ->assertInstanceOf (NotFoundException::class, $ container ->get (NotFoundException::class));
318- } else {
319- // PHP 7.x
320- // Cannot determine default value for internal functions
321- $ this ->expectException (InvalidDefinitionException::class);
322- $ container ->get (NotFoundException::class);
323- }
307+ $ this ->assertInstanceOf (NotFoundException::class, $ container ->get (NotFoundException::class));
324308 }
325309
326310 /**
@@ -353,4 +337,25 @@ public function testAutowireWithNotExistingClass(): void
353337 $ container ->addResolver (new ConstructorResolver ($ container ));
354338 $ container ->get ('Nada\Foo ' );
355339 }
340+
341+ /**
342+ * Test.
343+ *
344+ * @return void
345+ */
346+ public function testAutowireReturnsNull (): void
347+ {
348+ $ container = new Container ();
349+
350+ $ resolver = $ this ->createMock (DefinitionResolverInterface::class);
351+ $ resolver ->method ('isResolvable ' )->willReturn (false );
352+ $ resolver ->expects ($ this ->once ())
353+ ->method ('resolve ' )
354+ ->with (stdClass::class)
355+ ->willReturn (null );
356+
357+ $ container ->addResolver ($ resolver );
358+
359+ $ this ->assertNull ($ container ->get (stdClass::class));
360+ }
356361}
0 commit comments