Skip to content

Commit

Permalink
stop all server process when tests terminate
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Mar 26, 2024
1 parent 7ba3d8e commit cd01164
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
Expand Up @@ -24,6 +24,11 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
}

public function testItCollectsRequestCount()
{
$httpClient1 = $this->httpClientThatHasTracedRequests([
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/HttplugClientTest.php
Expand Up @@ -32,6 +32,11 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
}

public function testSendRequest()
{
$client = new HttplugClient(new NativeHttpClient());
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php
Expand Up @@ -28,6 +28,11 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
}

public function testSendRequest()
{
$factory = new Psr17Factory();
Expand Down
Expand Up @@ -27,6 +27,11 @@

class RetryableHttpClientTest extends TestCase
{
public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
}

public function testRetryOnError()
{
$client = new RetryableHttpClient(
Expand Down
Expand Up @@ -29,6 +29,11 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
}

public function testItTracesRequest()
{
$httpClient = $this->createMock(HttpClientInterface::class);
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php
Expand Up @@ -28,6 +28,11 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stopAll();
}

abstract protected function getHttpClient(string $testCase): HttpClientInterface;

public function testGetRequest()
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Contracts/HttpClient/Test/TestHttpServer.php
Expand Up @@ -43,4 +43,18 @@ public static function start(int $port = 8057)

return $process;
}

public static function stop(int $port = 8057)
{
if (isset(self::$process[$port])) {
self::$process[$port]->stop();
}
}

public static function stopAll()
{
foreach (self::$process as $process) {
$process->stop();
}
}
}

0 comments on commit cd01164

Please sign in to comment.