From 7341e29f2f87c8932baea93895e5ded4c482bf49 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 7 Jun 2021 11:04:09 +0200 Subject: [PATCH] Fix tests (bis) --- src/Symfony/Component/HttpClient/composer.json | 1 + .../Tests/File/MimeType/MimeTypeTest.php | 3 ++- .../Mime/Tests/FileBinaryMimeTypeGuesserTest.php | 5 +++++ .../HttpClient/Test/Fixtures/web/index.php | 5 +++-- .../HttpClient/Test/HttpClientTestCase.php | 14 +++++++++----- .../Contracts/HttpClient/Test/TestHttpServer.php | 5 +++-- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/HttpClient/composer.json b/src/Symfony/Component/HttpClient/composer.json index a6209060a5..6c45b6dee3 100644 --- a/src/Symfony/Component/HttpClient/composer.json +++ b/src/Symfony/Component/HttpClient/composer.json @@ -33,6 +33,7 @@ "php-http/httplug": "^1.0|^2.0", "psr/http-client": "^1.0", "symfony/dependency-injection": "^4.3|^5.0", + "symfony/http-client-contracts": "^1.1.11|~2.1.4|~2.2.1|~2.3.2|^2.4.1", "symfony/http-kernel": "^4.4.13", "symfony/process": "^4.2|^5.0" }, diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php index bbc74e74a6..42d5c436cd 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php @@ -65,7 +65,8 @@ class MimeTypeTest extends TestCase public function testGuessWithDuplicatedFileType() { - $this->assertSame('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')); + $type = MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'); + $this->assertTrue(\in_array($type, ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'], true)); } public function testGuessWithIncorrectPath() diff --git a/src/Symfony/Component/Mime/Tests/FileBinaryMimeTypeGuesserTest.php b/src/Symfony/Component/Mime/Tests/FileBinaryMimeTypeGuesserTest.php index 0742732895..5d225038d4 100644 --- a/src/Symfony/Component/Mime/Tests/FileBinaryMimeTypeGuesserTest.php +++ b/src/Symfony/Component/Mime/Tests/FileBinaryMimeTypeGuesserTest.php @@ -20,4 +20,9 @@ class FileBinaryMimeTypeGuesserTest extends AbstractMimeTypeGuesserTest { return new FileBinaryMimeTypeGuesser(); } + + public function testGuessWithDuplicatedFileType() + { + $this->markTestSkipped('Result varies depending on the OS'); + } } diff --git a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php index 30a7049758..a5cf236a35 100644 --- a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php +++ b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php @@ -30,6 +30,7 @@ foreach ($_SERVER as $k => $v) { } $json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); +$localhost = gethostbyname('localhost'); switch ($vars['REQUEST_URI']) { default: @@ -41,7 +42,7 @@ switch ($vars['REQUEST_URI']) { case '/': case '/?a=a&b=b': - case 'http://127.0.0.1:8057/': + case "http://$localhost:8057/": case 'http://localhost:8057/': ob_start('ob_gzhandler'); break; @@ -74,7 +75,7 @@ switch ($vars['REQUEST_URI']) { case '/301': if ('Basic Zm9vOmJhcg==' === $vars['HTTP_AUTHORIZATION']) { - header('Location: http://127.0.0.1:8057/302', true, 301); + header("Location: http://$localhost:8057/302", true, 301); } break; diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index f3e75c9337..af19e387f8 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -335,6 +335,7 @@ abstract class HttpClientTestCase extends TestCase public function testRedirects() { $client = $this->getHttpClient(__FUNCTION__); + $localhost = gethostbyname('localhost'); $response = $client->request('POST', 'http://localhost:8057/301', [ 'auth_basic' => 'foo:bar', 'body' => function () { @@ -352,7 +353,7 @@ abstract class HttpClientTestCase extends TestCase $expected = [ 'HTTP/1.1 301 Moved Permanently', - 'Location: http://127.0.0.1:8057/302', + "Location: http://$localhost:8057/302", 'Content-Type: application/json', 'HTTP/1.1 302 Found', 'Location: http://localhost:8057/', @@ -425,6 +426,7 @@ abstract class HttpClientTestCase extends TestCase public function testMaxRedirects() { $client = $this->getHttpClient(__FUNCTION__); + $localhost = gethostbyname('localhost'); $response = $client->request('GET', 'http://localhost:8057/301', [ 'max_redirects' => 1, 'auth_basic' => 'foo:bar', @@ -442,7 +444,7 @@ abstract class HttpClientTestCase extends TestCase $expected = [ 'HTTP/1.1 301 Moved Permanently', - 'Location: http://127.0.0.1:8057/302', + "Location: http://$localhost:8057/302", 'Content-Type: application/json', 'HTTP/1.1 302 Found', 'Location: http://localhost:8057/', @@ -691,8 +693,9 @@ abstract class HttpClientTestCase extends TestCase public function testResolve() { $client = $this->getHttpClient(__FUNCTION__); + $localhost = gethostbyname('localhost'); $response = $client->request('GET', 'http://symfony.com:8057/', [ - 'resolve' => ['symfony.com' => '127.0.0.1'], + 'resolve' => ['symfony.com' => $localhost], ]); $this->assertSame(200, $response->getStatusCode()); @@ -706,15 +709,16 @@ abstract class HttpClientTestCase extends TestCase public function testIdnResolve() { $client = $this->getHttpClient(__FUNCTION__); + $localhost = gethostbyname('localhost'); $response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [ - 'resolve' => ['0-------------------------------------------------------------0.com' => '127.0.0.1'], + 'resolve' => ['0-------------------------------------------------------------0.com' => $localhost], ]); $this->assertSame(200, $response->getStatusCode()); $response = $client->request('GET', 'http://Bücher.example:8057/', [ - 'resolve' => ['xn--bcher-kva.example' => '127.0.0.1'], + 'resolve' => ['xn--bcher-kva.example' => $localhost], ]); $this->assertSame(200, $response->getStatusCode()); diff --git a/src/Symfony/Contracts/HttpClient/Test/TestHttpServer.php b/src/Symfony/Contracts/HttpClient/Test/TestHttpServer.php index 06a11444e3..a521a96683 100644 --- a/src/Symfony/Contracts/HttpClient/Test/TestHttpServer.php +++ b/src/Symfony/Contracts/HttpClient/Test/TestHttpServer.php @@ -31,15 +31,16 @@ class TestHttpServer }); } + $localhost = gethostbyname('localhost'); $finder = new PhpExecutableFinder(); - $process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:'.$port])); + $process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', "$localhost:$port"])); $process->setWorkingDirectory(__DIR__.'/Fixtures/web'); $process->start(); self::$process[$port] = $process; do { usleep(50000); - } while (!@fopen('http://127.0.0.1:'.$port, 'r')); + } while (!@fopen("http://$localhost:$port", 'r')); return $process; }