@@ -2833,6 +2833,7 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstance(): void
28332833
28342834 $ this ->assertInstanceOf (HttpServerRunner::class, $ runner );
28352835
2836+ assert ($ runner instanceof HttpServerRunner);
28362837 $ ref = new \ReflectionProperty ($ runner , 'listenAddress ' );
28372838 if (PHP_VERSION_ID < 80100 ) {
28382839 $ ref ->setAccessible (true );
@@ -2852,6 +2853,7 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithCustomLis
28522853
28532854 $ this ->assertInstanceOf (HttpServerRunner::class, $ runner );
28542855
2856+ assert ($ runner instanceof HttpServerRunner);
28552857 $ ref = new \ReflectionProperty ($ runner , 'listenAddress ' );
28562858 if (PHP_VERSION_ID < 80100 ) {
28572859 $ ref ->setAccessible (true );
@@ -2888,7 +2890,10 @@ public function testGetRunnerReturnsHttpServerRunnerInstanceFromPsrContainer():
28882890 $ runner = new HttpServerRunner (new LogStreamHandler ('php://output ' ), null );
28892891
28902892 $ psr = $ this ->createMock (ContainerInterface::class);
2891- $ psr ->expects ($ this ->once ())->method ('has ' )->with (HttpServerRunner::class)->willReturn (true );
2893+ $ psr ->expects ($ this ->exactly (2 ))->method ('has ' )->willReturnMap ([
2894+ ['X_EXPERIMENTAL_RUNNER ' , false ],
2895+ [HttpServerRunner::class, true ],
2896+ ]);
28922897 $ psr ->expects ($ this ->once ())->method ('get ' )->with (HttpServerRunner::class)->willReturn ($ runner );
28932898
28942899 assert ($ psr instanceof ContainerInterface);
@@ -2902,7 +2907,8 @@ public function testGetRunnerReturnsHttpServerRunnerInstanceFromPsrContainer():
29022907 public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithDefaultListenAddressIfPsrContainerHasNoEntry (): void
29032908 {
29042909 $ psr = $ this ->createMock (ContainerInterface::class);
2905- $ psr ->expects ($ this ->exactly (2 ))->method ('has ' )->willReturnMap ([
2910+ $ psr ->expects ($ this ->exactly (3 ))->method ('has ' )->willReturnMap ([
2911+ ['X_EXPERIMENTAL_RUNNER ' , false ],
29062912 [HttpServerRunner::class, false ],
29072913 ['X_LISTEN ' , false ],
29082914 ]);
@@ -2915,6 +2921,7 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithDefaultLi
29152921
29162922 $ this ->assertInstanceOf (HttpServerRunner::class, $ runner );
29172923
2924+ assert ($ runner instanceof HttpServerRunner);
29182925 $ ref = new \ReflectionProperty ($ runner , 'listenAddress ' );
29192926 if (PHP_VERSION_ID < 80100 ) {
29202927 $ ref ->setAccessible (true );
@@ -2927,7 +2934,8 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithDefaultLi
29272934 public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithCustomListenAddressIfPsrContainerHasNoEntryButCustomListenAddress (): void
29282935 {
29292936 $ psr = $ this ->createMock (ContainerInterface::class);
2930- $ psr ->expects ($ this ->exactly (2 ))->method ('has ' )->willReturnMap ([
2937+ $ psr ->expects ($ this ->exactly (3 ))->method ('has ' )->willReturnMap ([
2938+ ['X_EXPERIMENTAL_RUNNER ' , false ],
29312939 [HttpServerRunner::class, false ],
29322940 ['X_LISTEN ' , true ],
29332941 ]);
@@ -2940,6 +2948,7 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithCustomLis
29402948
29412949 $ this ->assertInstanceOf (HttpServerRunner::class, $ runner );
29422950
2951+ assert ($ runner instanceof HttpServerRunner);
29432952 $ ref = new \ReflectionProperty ($ runner , 'listenAddress ' );
29442953 if (PHP_VERSION_ID < 80100 ) {
29452954 $ ref ->setAccessible (true );
@@ -2949,6 +2958,55 @@ public function testGetRunnerReturnsDefaultHttpServerRunnerInstanceWithCustomLis
29492958 $ this ->assertEquals ('127.0.0.1:8081 ' , $ listenAddress );
29502959 }
29512960
2961+ public function testGetRunnerReturnsCustomRunnerInstanceFromEnvironmentVariable (): void
2962+ {
2963+ $ runner = new class {
2964+ public function __invoke (): void {}
2965+ };
2966+
2967+ $ container = new Container ([
2968+ 'X_EXPERIMENTAL_RUNNER ' => get_class ($ runner ),
2969+ get_class ($ runner ) => $ runner
2970+ ]);
2971+
2972+ $ ret = $ container ->getRunner ();
2973+
2974+ $ this ->assertSame ($ runner , $ ret );
2975+ }
2976+
2977+ public function testGetRunnerThrowsForInvalidEnvironmentVariableType (): void
2978+ {
2979+ $ container = new Container ([
2980+ 'X_EXPERIMENTAL_RUNNER ' => 42
2981+ ]);
2982+
2983+ $ this ->expectException (\TypeError::class);
2984+ $ this ->expectExceptionMessage ('Return value of ' . Container::class . '::getEnv() for $X_EXPERIMENTAL_RUNNER must be of type string|null, int returned ' );
2985+ $ container ->getRunner ();
2986+ }
2987+
2988+ public function testGetRunnerThrowsForUnknownClassNameInEnvironmentVariable (): void
2989+ {
2990+ $ container = new Container ([
2991+ 'X_EXPERIMENTAL_RUNNER ' => 'UnknownClass '
2992+ ]);
2993+
2994+ $ this ->expectException (\Error::class);
2995+ $ this ->expectExceptionMessage ('Class UnknownClass not found ' );
2996+ $ container ->getRunner ();
2997+ }
2998+
2999+ public function testGetRunnerThrowsForClassNotCallableInEnvironmentVariable (): void
3000+ {
3001+ $ container = new Container ([
3002+ 'X_EXPERIMENTAL_RUNNER ' => \stdClass::class
3003+ ]);
3004+
3005+ $ this ->expectException (\TypeError::class);
3006+ $ this ->expectExceptionMessage ('Return value of ' . Container::class . '::getRunner() must be of type callable, stdClass returned ' );
3007+ $ container ->getRunner ();
3008+ }
3009+
29523010 public function testInvokeContainerAsMiddlewareReturnsFromNextRequestHandler (): void
29533011 {
29543012 $ request = new ServerRequest ('GET ' , 'http://example.com/ ' );
0 commit comments