9
9
use ReflectionClass ;
10
10
11
11
use function dirname ;
12
- use function str_replace ;
12
+ use function register_shutdown_function ;
13
13
14
14
/**
15
15
* @deprecated User HttpResource instead
16
16
*/
17
17
trait BuiltinServerStartTrait
18
18
{
19
- /**
20
- * Hosting built server URL
21
- *
22
- * User can change it in unit test
23
- *
24
- * @var string
25
- */
26
- protected static $ httpHost = 'http://127.0.0.1:8088 ' ;
19
+ /** @var string */
20
+ private static $ host = '127.0.0.1:8088 ' ;
21
+
22
+ /** @var string */
23
+ private $ httpHost = 'http://127.0.0.1:8088 ' ;
27
24
28
25
/** @var BuiltinServer */
29
26
private static $ server ;
30
27
31
28
public static function setUpBeforeClass (): void
32
29
{
33
- $ host = str_replace (['http:// ' , 'https:// ' ], '' , self ::$ httpHost );
34
30
$ dir = dirname ((new ReflectionClass (static ::class))->getFileName ());
35
- self ::$ server = new BuiltinServer ($ host , $ dir . '/index.php ' );
31
+ self ::$ server = new BuiltinServer (self :: $ host , $ dir . '/index.php ' );
36
32
self ::$ server ->start ();
33
+ register_shutdown_function (static function () {
34
+ self ::$ server ->stop ();
35
+ });
37
36
}
38
37
39
38
public static function tearDownAfterClass (): void
@@ -43,6 +42,6 @@ public static function tearDownAfterClass(): void
43
42
44
43
public function getHttpResourceClient (InjectorInterface $ injector , string $ class ): ResourceInterface
45
44
{
46
- return new HttpResourceClient (self :: $ httpHost , $ injector , $ class );
45
+ return new HttpResourceClient ($ this -> httpHost , $ injector , $ class );
47
46
}
48
47
}
0 commit comments