Fix and update Composer autoload
This commit is contained in:
committed by
Frédéric Guillot
parent
3e139ab6f4
commit
4cfdb88813
@@ -24,7 +24,9 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
*/
|
||||
abstract class HttpClientTestCase extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
private static $server;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
TestHttpServer::start();
|
||||
}
|
||||
@@ -70,31 +72,6 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testHeadRequest()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('HEAD', 'http://localhost:8057/head', [
|
||||
'headers' => ['Foo' => 'baR'],
|
||||
'user_data' => $data = new \stdClass(),
|
||||
'buffer' => false,
|
||||
]);
|
||||
|
||||
$this->assertSame([], $response->getInfo('response_headers'));
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$info = $response->getInfo();
|
||||
$this->assertSame('HTTP/1.1 200 OK', $info['response_headers'][0]);
|
||||
$this->assertSame('Host: localhost:8057', $info['response_headers'][1]);
|
||||
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
$this->assertSame('localhost:8057', $headers['host'][0]);
|
||||
$this->assertSame(['application/json'], $headers['content-type']);
|
||||
$this->assertTrue(0 < $headers['content-length'][0]);
|
||||
|
||||
$this->assertSame('', $response->getContent());
|
||||
}
|
||||
|
||||
public function testNonBufferedGetRequest()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
@@ -110,70 +87,6 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testBufferSink()
|
||||
{
|
||||
$sink = fopen('php://temp', 'w+');
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057', [
|
||||
'buffer' => $sink,
|
||||
'headers' => ['Foo' => 'baR'],
|
||||
]);
|
||||
|
||||
$body = $response->toArray();
|
||||
$this->assertSame('baR', $body['HTTP_FOO']);
|
||||
|
||||
rewind($sink);
|
||||
$sink = stream_get_contents($sink);
|
||||
$this->assertSame($sink, $response->getContent());
|
||||
}
|
||||
|
||||
public function testConditionalBuffering()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057');
|
||||
$firstContent = $response->getContent();
|
||||
$secondContent = $response->getContent();
|
||||
|
||||
$this->assertSame($firstContent, $secondContent);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057', ['buffer' => function () { return false; }]);
|
||||
$response->getContent();
|
||||
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testReentrantBufferCallback()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057', ['buffer' => function () use (&$response) {
|
||||
$response->cancel();
|
||||
|
||||
return true;
|
||||
}]);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testThrowingBufferCallback()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057', ['buffer' => function () {
|
||||
throw new \Exception('Boo.');
|
||||
}]);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
$this->expectExceptionMessage('Boo');
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testUnsupportedOption()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
@@ -239,16 +152,6 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$this->assertSame(404, $response->getStatusCode());
|
||||
$this->assertSame(['application/json'], $response->getHeaders(false)['content-type']);
|
||||
$this->assertNotEmpty($response->getContent(false));
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/404');
|
||||
|
||||
try {
|
||||
foreach ($client->stream($response) as $chunk) {
|
||||
$this->assertTrue($chunk->isFirst());
|
||||
}
|
||||
$this->fail(ClientExceptionInterface::class.' expected');
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function testIgnoreErrors()
|
||||
@@ -320,18 +223,6 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$response->getStatusCode();
|
||||
}
|
||||
|
||||
public function test304()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/304', [
|
||||
'headers' => ['If-Match' => '"abc"'],
|
||||
'buffer' => false,
|
||||
]);
|
||||
|
||||
$this->assertSame(304, $response->getStatusCode());
|
||||
$this->assertSame('', $response->getContent(false));
|
||||
}
|
||||
|
||||
public function testRedirects()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
@@ -555,7 +446,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
|
||||
$body = $response->toArray();
|
||||
|
||||
$this->assertStringContainsString('json', $body['content-type']);
|
||||
$this->assertContains('json', $body['content-type']);
|
||||
unset($body['content-type']);
|
||||
$this->assertSame(['foo' => 'bar', 'REQUEST_METHOD' => 'POST'], $body);
|
||||
}
|
||||
@@ -614,39 +505,13 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$response->getHeaders();
|
||||
}
|
||||
|
||||
public function testInfoOnCanceledResponse()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/timeout-header');
|
||||
|
||||
$this->assertFalse($response->getInfo('canceled'));
|
||||
$response->cancel();
|
||||
$this->assertTrue($response->getInfo('canceled'));
|
||||
}
|
||||
|
||||
public function testCancelInStream()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/404');
|
||||
|
||||
foreach ($client->stream($response) as $chunk) {
|
||||
$response->cancel();
|
||||
}
|
||||
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
|
||||
foreach ($client->stream($response) as $chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
public function testOnProgressCancel()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
|
||||
'on_progress' => function ($dlNow) {
|
||||
if (0 < $dlNow) {
|
||||
throw new \Exception('Aborting the request.');
|
||||
throw new \Exception('Aborting the request');
|
||||
}
|
||||
},
|
||||
]);
|
||||
@@ -656,7 +521,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
}
|
||||
$this->fail(ClientExceptionInterface::class.' expected');
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->assertSame('Aborting the request.', $e->getPrevious()->getMessage());
|
||||
$this->assertSame('Aborting the request', $e->getPrevious()->getMessage());
|
||||
}
|
||||
|
||||
$this->assertNotNull($response->getInfo('error'));
|
||||
@@ -670,7 +535,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$response = $client->request('GET', 'http://localhost:8057/timeout-body', [
|
||||
'on_progress' => function ($dlNow) {
|
||||
if (0 < $dlNow) {
|
||||
throw new \Error('BUG.');
|
||||
throw new \Error('BUG');
|
||||
}
|
||||
},
|
||||
]);
|
||||
@@ -680,7 +545,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
}
|
||||
$this->fail('Error expected');
|
||||
} catch (\Error $e) {
|
||||
$this->assertSame('BUG.', $e->getMessage());
|
||||
$this->assertSame('BUG', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertNotNull($response->getInfo('error'));
|
||||
@@ -700,34 +565,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
|
||||
$response = null;
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
$client->request('GET', 'http://symfony.com:8057/', ['timeout' => 1]);
|
||||
}
|
||||
|
||||
public function testIdnResolve()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [
|
||||
'resolve' => ['0-------------------------------------------------------------0.com' => '127.0.0.1'],
|
||||
]);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$response = $client->request('GET', 'http://Bücher.example:8057/', [
|
||||
'resolve' => ['xn--bcher-kva.example' => '127.0.0.1'],
|
||||
]);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testNotATimeout()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/timeout-header', [
|
||||
'timeout' => 0.9,
|
||||
]);
|
||||
sleep(1);
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$client->request('GET', 'http://symfony.com:8057/', ['timeout' => 3]);
|
||||
}
|
||||
|
||||
public function testTimeoutOnAccess()
|
||||
@@ -786,53 +624,18 @@ abstract class HttpClientTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testTimeoutWithActiveConcurrentStream()
|
||||
{
|
||||
$p1 = TestHttpServer::start(8067);
|
||||
$p2 = TestHttpServer::start(8077);
|
||||
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$streamingResponse = $client->request('GET', 'http://localhost:8067/max-duration');
|
||||
$blockingResponse = $client->request('GET', 'http://localhost:8077/timeout-body', [
|
||||
'timeout' => 0.25,
|
||||
]);
|
||||
|
||||
$this->assertSame(200, $streamingResponse->getStatusCode());
|
||||
$this->assertSame(200, $blockingResponse->getStatusCode());
|
||||
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
|
||||
try {
|
||||
$blockingResponse->getContent();
|
||||
} finally {
|
||||
$p1->stop();
|
||||
$p2->stop();
|
||||
}
|
||||
}
|
||||
|
||||
public function testDestruct()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$downloaded = 0;
|
||||
$start = microtime(true);
|
||||
$client->request('GET', 'http://localhost:8057/timeout-long');
|
||||
$client = null;
|
||||
$duration = microtime(true) - $start;
|
||||
|
||||
$this->assertGreaterThan(1, $duration);
|
||||
$this->assertLessThan(4, $duration);
|
||||
}
|
||||
|
||||
public function testGetContentAfterDestruct()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
try {
|
||||
$client->request('GET', 'http://localhost:8057/404');
|
||||
$this->fail(ClientExceptionInterface::class.' expected');
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->assertSame('GET', $e->getResponse()->toArray(false)['REQUEST_METHOD']);
|
||||
}
|
||||
$this->assertLessThan(3, $duration);
|
||||
}
|
||||
|
||||
public function testProxy()
|
||||
@@ -844,7 +647,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
|
||||
$body = $response->toArray();
|
||||
$this->assertSame('localhost:8057', $body['HTTP_HOST']);
|
||||
$this->assertMatchesRegularExpression('#^http://(localhost|127\.0\.0\.1):8057/$#', $body['REQUEST_URI']);
|
||||
$this->assertRegexp('#^http://(localhost|127\.0\.0\.1):8057/$#', $body['REQUEST_URI']);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/', [
|
||||
'proxy' => 'http://foo:b%3Dar@localhost:8057',
|
||||
@@ -888,11 +691,11 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
$this->assertSame(['Accept-Encoding'], $headers['vary']);
|
||||
$this->assertStringContainsString('gzip', $headers['content-encoding'][0]);
|
||||
$this->assertContains('gzip', $headers['content-encoding'][0]);
|
||||
|
||||
$body = $response->toArray();
|
||||
|
||||
$this->assertStringContainsString('gzip', $body['HTTP_ACCEPT_ENCODING']);
|
||||
$this->assertContains('gzip', $body['HTTP_ACCEPT_ENCODING']);
|
||||
}
|
||||
|
||||
public function testBaseUri()
|
||||
@@ -918,36 +721,6 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$this->assertSame('/?a=a&b=b', $body['REQUEST_URI']);
|
||||
}
|
||||
|
||||
public function testInformationalResponse()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/103');
|
||||
|
||||
$this->assertSame('Here the body', $response->getContent());
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testInformationalResponseStream()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/103');
|
||||
|
||||
$chunks = [];
|
||||
foreach ($client->stream($response) as $chunk) {
|
||||
$chunks[] = $chunk;
|
||||
}
|
||||
|
||||
$this->assertSame(103, $chunks[0]->getInformationalStatus()[0]);
|
||||
$this->assertSame(['</style.css>; rel=preload; as=style', '</script.js>; rel=preload; as=script'], $chunks[0]->getInformationalStatus()[1]['link']);
|
||||
$this->assertTrue($chunks[1]->isFirst());
|
||||
$this->assertSame('Here the body', $chunks[2]->getContent());
|
||||
$this->assertTrue($chunks[3]->isLast());
|
||||
$this->assertNull($chunks[3]->getInformationalStatus());
|
||||
|
||||
$this->assertSame(['date', 'content-length'], array_keys($response->getHeaders()));
|
||||
$this->assertContains('Link: </style.css>; rel=preload; as=style', $response->getInfo('response_headers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension zlib
|
||||
*/
|
||||
@@ -961,7 +734,7 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
$this->assertSame(['Accept-Encoding'], $headers['vary']);
|
||||
$this->assertStringContainsString('gzip', $headers['content-encoding'][0]);
|
||||
$this->assertContains('gzip', $headers['content-encoding'][0]);
|
||||
|
||||
$body = $response->getContent();
|
||||
$this->assertSame("\x1F", $body[0]);
|
||||
@@ -981,24 +754,4 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$this->expectException(TransportExceptionInterface::class);
|
||||
$response->getContent();
|
||||
}
|
||||
|
||||
public function testMaxDuration()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
$response = $client->request('GET', 'http://localhost:8057/max-duration', [
|
||||
'max_duration' => 0.1,
|
||||
]);
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
try {
|
||||
$response->getContent();
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
$duration = microtime(true) - $start;
|
||||
|
||||
$this->assertLessThan(10, $duration);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user