minor #37013 [HttpClient] fix issues in tests (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fix issues in tests

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

a337ba5547 [HttpClient] fix issues in tests
This commit is contained in:
Nicolas Grekas 2020-05-30 20:39:29 +02:00
commit 68d14c8511
5 changed files with 15 additions and 15 deletions

View File

@ -151,6 +151,7 @@ before_install:
INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini
echo date.timezone = Europe/Paris >> $INI echo date.timezone = Europe/Paris >> $INI
echo memory_limit = -1 >> $INI echo memory_limit = -1 >> $INI
echo default_socket_timeout = 10 >> $INI
echo session.gc_probability = 0 >> $INI echo session.gc_probability = 0 >> $INI
echo opcache.enable_cli = 1 >> $INI echo opcache.enable_cli = 1 >> $INI
echo apc.enable_cli = 1 >> $INI echo apc.enable_cli = 1 >> $INI

View File

@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\HttpClient\Tests\DataCollector;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector; use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector;
use Symfony\Component\HttpClient\NativeHttpClient; use Symfony\Component\HttpClient\NativeHttpClient;
@ -19,9 +21,13 @@ use Symfony\Contracts\HttpClient\Test\TestHttpServer;
class HttpClientDataCollectorTest extends TestCase class HttpClientDataCollectorTest extends TestCase
{ {
public function testItCollectsRequestCount() public static function setUpBeforeClass(): void
{ {
TestHttpServer::start(); TestHttpServer::start();
}
public function testItCollectsRequestCount()
{
$httpClient1 = $this->httpClientThatHasTracedRequests([ $httpClient1 = $this->httpClientThatHasTracedRequests([
[ [
'method' => 'GET', 'method' => 'GET',
@ -50,7 +56,6 @@ class HttpClientDataCollectorTest extends TestCase
public function testItCollectsErrorCount() public function testItCollectsErrorCount()
{ {
TestHttpServer::start();
$httpClient1 = $this->httpClientThatHasTracedRequests([ $httpClient1 = $this->httpClientThatHasTracedRequests([
[ [
'method' => 'GET', 'method' => 'GET',
@ -80,7 +85,6 @@ class HttpClientDataCollectorTest extends TestCase
public function testItCollectsErrorCountByClient() public function testItCollectsErrorCountByClient()
{ {
TestHttpServer::start();
$httpClient1 = $this->httpClientThatHasTracedRequests([ $httpClient1 = $this->httpClientThatHasTracedRequests([
[ [
'method' => 'GET', 'method' => 'GET',
@ -113,7 +117,6 @@ class HttpClientDataCollectorTest extends TestCase
public function testItCollectsTracesByClient() public function testItCollectsTracesByClient()
{ {
TestHttpServer::start();
$httpClient1 = $this->httpClientThatHasTracedRequests([ $httpClient1 = $this->httpClientThatHasTracedRequests([
[ [
'method' => 'GET', 'method' => 'GET',
@ -146,7 +149,6 @@ class HttpClientDataCollectorTest extends TestCase
public function testItIsEmptyAfterReset() public function testItIsEmptyAfterReset()
{ {
TestHttpServer::start();
$httpClient1 = $this->httpClientThatHasTracedRequests([ $httpClient1 = $this->httpClientThatHasTracedRequests([
[ [
'method' => 'GET', 'method' => 'GET',

View File

@ -22,8 +22,6 @@ use Symfony\Contracts\HttpClient\Test\TestHttpServer;
class HttplugClientTest extends TestCase class HttplugClientTest extends TestCase
{ {
private static $server;
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
TestHttpServer::start(); TestHttpServer::start();

View File

@ -21,8 +21,6 @@ use Symfony\Contracts\HttpClient\Test\TestHttpServer;
class Psr18ClientTest extends TestCase class Psr18ClientTest extends TestCase
{ {
private static $server;
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
TestHttpServer::start(); TestHttpServer::start();

View File

@ -19,12 +19,12 @@ use Symfony\Component\Process\Process;
*/ */
class TestHttpServer class TestHttpServer
{ {
private static $started; private static $process;
public static function start() public static function start()
{ {
if (self::$started) { if (self::$process) {
return; self::$process->stop();
} }
$finder = new PhpExecutableFinder(); $finder = new PhpExecutableFinder();
@ -32,9 +32,10 @@ class TestHttpServer
$process->setWorkingDirectory(__DIR__.'/Fixtures/web'); $process->setWorkingDirectory(__DIR__.'/Fixtures/web');
$process->start(); $process->start();
register_shutdown_function([$process, 'stop']); do {
sleep('\\' === \DIRECTORY_SEPARATOR ? 10 : 1); usleep(50000);
} while (!@fopen('http://127.0.0.1:8057/', 'r'));
self::$started = true; self::$process = $process;
} }
} }