pax_global_header00006660000000000000000000000064152225016240014511gustar00rootroot0000000000000052 comment=aef39afc319a84c452e71337b71f6cfb6b474093 php-http-client-integration-tests-46398b4/000077500000000000000000000000001522250162400204775ustar00rootroot00000000000000php-http-client-integration-tests-46398b4/.php_cs.dist000066400000000000000000000004051522250162400227150ustar00rootroot00000000000000setRiskyAllowed(true) ->setRules([ '@PSR2' => true, ]) ->setFinder( PhpCsFixer\Finder::create() ->in(__DIR__.'/src') ->name('*.php') ) ; return $config; php-http-client-integration-tests-46398b4/CHANGELOG.md000066400000000000000000000070241522250162400223130ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). # 4.x ## [4.1.1] - 2026-07-05 - Allow that HEAD requests sent by a client do not have the Content-Length header ## [4.1.0] - 2026-06-24 - Allow installation with guzzlehttp/psr7 version 3 ## [4.0.0] - 2025-12-09 - Allow PHPUnit > 9 - Removed deprecated PhpUnitBackwardCompatibleTrait - Replaced deprecated HttpBaseTest::$messageFactory with $requestFactory and $streamFactory - Parameter type and return type declarations on all test classes # 3.x ## [3.2.1] - 2026-07-05 - Allow that HEAD requests sent by a client do not have the Content-Length header ## [3.2.0] - 2026-06-24 - Allow installation with guzzlehttp/psr7 version 3 ## [3.1.3] - 2025-12-08 - Fixed BC breaks accidentally introduced in 3.1.2 ## [3.1.2] - 2025-12-08 - Allow PHPUnit > 9 - Deprecate PhpUnitBackwardCompatibleTrait ## [3.1.1] - 2024-09-01 - Switched to `httpbin.org` for tests now that its fixed. (Reverts [#56](https://github.com/php-http/client-integration-tests/pull/56)) ## [3.1.0] - 2024-03-05 - Removed builds for abandoned guzzle5 and guzzle6 adapters - Support PSR-17 factories ## [3.0.1] - 2021-03-21 - Allow to be installed with Guzzle PSR-7 2.0 ## [3.0.0] - 2020-10-01 - Only support HTTPlug 2.0 and PSR-18 - HTTPlug 2.0 is now optional (only require it if you need to test async) - HttpClientTest now relies only on PSR-18 (no need for HTTPlug) - Added support for PHPUnit 8 and 9 ## [2.0.1] - 2018-12-27 - Use `__toString()` instead of `getContents()` ## [2.0.0] - 2018-11-03 ## [1.0.0] - 2018-11-03 ### Changed - Don't test `TRACE` requests with request bodies, as they're not valid requests according to the [RFC](https://tools.ietf.org/html/rfc7231#section-4.3.8). - Make the test suite PHPUnit 6 compatible ## [0.6.2] - 2017-07-10 ## [0.6.1] - 2017-07-10 ## [0.6.0] - 2017-05-29 ## [0.5.1] - 2016-07-18 ### Fixed - Old name ## [0.5.0] - 2016-07-18 ### Changed - Renamed to client-integration-tests - Improved pacakge ## [0.4.0] - 2016-03-02 ### Removed - Discovery dependency ## [0.3.1] - 2016-02-11 ### Changed - Updated message dependency ## [0.3.0] - 2016-01-21 ### Changed - Updated discovery dependency ## [0.2.0] - 2016-01-13 ### Changed - Updated to latest HTTPlug version - Updated package files ## 0.1.0 - 2015-06-12 ### Added - Initial release [Unreleased]: https://github.com/php-http/client-integration-tests/compare/v2.0.0...HEAD [2.0.0]: https://github.com/php-http/client-integration-tests/compare/v1.0.0...v2.0.0 [1.0.0]: https://github.com/php-http/client-integration-tests/compare/v0.6.2...v1.0.0 [0.6.2]: https://github.com/php-http/client-integration-tests/compare/v0.6.1...v0.6.2 [0.6.1]: https://github.com/php-http/client-integration-tests/compare/v0.6.0...v0.6.1 [0.6.0]: https://github.com/php-http/client-integration-tests/compare/v0.5.1...v0.6.0 [0.5.1]: https://github.com/php-http/client-integration-tests/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/php-http/client-integration-tests/compare/v0.4.0...v0.5.0 [0.4.0]: https://github.com/php-http/client-integration-tests/compare/v0.3.1...v0.4.0 [0.3.1]: https://github.com/php-http/client-integration-tests/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/php-http/client-integration-tests/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/php-http/client-integration-tests/compare/v0.1.0...v0.2.0 php-http-client-integration-tests-46398b4/LICENSE000066400000000000000000000021661522250162400215110ustar00rootroot00000000000000Copyright (c) 2014-2015 Eric GELOEN Copyright (c) 2015-2016 PHP HTTP Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. php-http-client-integration-tests-46398b4/README.md000066400000000000000000000025661522250162400217670ustar00rootroot00000000000000# HTTP Client integration tests [![Latest Version](https://img.shields.io/github/release/php-http/client-integration-tests.svg?style=flat-square)](https://github.com/php-http/client-integration-tests/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/client-integration-tests.svg?style=flat-square)](https://packagist.org/packages/php-http/client-integration-tests) **HTTP Client integration tests.** ## Install Via Composer ```bash composer require php-http/client-integration-tests ``` ## Usage This package should not be used on its own. It provides integration tests for HTTP Clients. ### Running tests for HTTP Adapters Start the HTTP Test server: ```bash vendor/bin/http_test_server ``` Install an adapter. ```bash composer require php-http/curl-client laminas/laminas-diactoros ``` Run the tests. ```bash ./vendor/bin/phpunit --testsuite curl --printer "Http\Client\Tests\ResultPrinter" ``` ## Contributing Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). ## Security If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org). ## License The MIT License (MIT). Please see [License File](LICENSE) for more information. php-http-client-integration-tests-46398b4/bin/000077500000000000000000000000001522250162400212475ustar00rootroot00000000000000php-http-client-integration-tests-46398b4/bin/http_test_server000077500000000000000000000014341522250162400246030ustar00rootroot00000000000000#!/bin/bash DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # Installed as a dependency if [ -f "$DIR/../autoload.php" ]; then php -S 127.0.0.1:10000 -t "$DIR/../php-http/client-integration-tests/fixture" # Development elif [ -f "$DIR/../vendor/autoload.php" ]; then php -S 127.0.0.1:10000 -t "$DIR/../fixture" # Installed as a dependency, but not accessed using the symlink (e.g. Windows) elif [ -f "$DIR/../composer.json" -a -f "$DIR/../fixture/server.php" ] && grep -q php-http/client-integration-tests "$DIR/../composer.json"; then php -S 127.0.0.1:10000 -t "$DIR/../fixture" # Not working else echo "*** Can't find the fixture folder ***" >&2 echo "Please write your own way to start a PHP web server on port 10000 for the 'fixture' directory." >&2 exit 1 fi php-http-client-integration-tests-46398b4/composer.json000066400000000000000000000034111522250162400232200ustar00rootroot00000000000000{ "name": "php-http/client-integration-tests", "description": "HTTP Client integration tests", "license": "MIT", "keywords": ["http", "client", "integration", "tests"], "homepage": "http://httplug.io", "authors": [ { "name": "Eric GELOEN", "email": "geloen.eric@gmail.com" }, { "name": "Márk Sági-Kazár", "email": "mark.sagikazar@gmail.com" } ], "require": { "php": "^7.4 || ^8.0", "ext-json": "*", "phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0", "php-http/message": "^1.0 || ^2.0", "guzzlehttp/psr7": "^1.9 || ^2.0 || ^3.0", "th3n3rd/cartesian-product": "^0.3" }, "suggest": { "php-http/httplug": "To test async client" }, "require-dev": { "php-http/httplug": "^2.0", "nyholm/psr7": "^1.8.2" }, "autoload": { "psr-4": { "Http\\Client\\Tests\\": "src/" } }, "autoload-dev": { "psr-4": { "Http\\Client\\Curl\\Tests\\": "vendor/php-http/curl-client/tests/", "Http\\Client\\Socket\\Tests\\": "vendor/php-http/socket-client/tests/", "Http\\Adapter\\Guzzle5\\Tests\\": "vendor/php-http/guzzle5-adapter/tests/", "Http\\Adapter\\Guzzle6\\Tests\\": "vendor/php-http/guzzle6-adapter/tests/", "Http\\Adapter\\Buzz\\Tests\\": "vendor/php-http/buzz-adapter/tests/", "Http\\Adapter\\React\\Tests\\": "vendor/php-http/react-adapter/tests/", "Http\\Adapter\\Cake\\Tests\\": "vendor/php-http/cachephp-adapter/tests/", "Http\\Adapter\\Zend\\Tests\\": "vendor/php-http/zend-adapter/tests/" } }, "bin": [ "bin/http_test_server" ] } php-http-client-integration-tests-46398b4/fixture/000077500000000000000000000000001522250162400221655ustar00rootroot00000000000000php-http-client-integration-tests-46398b4/fixture/files/000077500000000000000000000000001522250162400232675ustar00rootroot00000000000000php-http-client-integration-tests-46398b4/fixture/files/file1.txt000066400000000000000000000000041522250162400250220ustar00rootroot00000000000000foo php-http-client-integration-tests-46398b4/fixture/files/file2.txt000066400000000000000000000000041522250162400250230ustar00rootroot00000000000000bar php-http-client-integration-tests-46398b4/fixture/files/file3.txt000066400000000000000000000000041522250162400250240ustar00rootroot00000000000000baz php-http-client-integration-tests-46398b4/fixture/files/resource.txt000066400000000000000000000000321522250162400256520ustar00rootroot00000000000000abcdefghijklmnopqrstuvwxyzphp-http-client-integration-tests-46398b4/fixture/server.php000066400000000000000000000026621522250162400242120ustar00rootroot00000000000000 * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. */ require_once __DIR__.'/../src/PHPUnitUtility.php'; use Http\Client\Tests\PHPUnitUtility; $file = fopen(PHPUnitUtility::getFile(true, 'php-http-adapter.log'), 'c'); flock($file, LOCK_EX); ftruncate($file, 0); $serverError = isset($_GET['server_error']) ? $_GET['server_error'] : false; $clientError = isset($_GET['client_error']) ? $_GET['client_error'] : false; $delay = isset($_GET['delay']) ? $_GET['delay'] : 0; $redirect = isset($_GET['redirect']) ? $_GET['redirect'] : false; if ($serverError) { header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error', true, 500); } if ($clientError) { header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request', true, 400); } if ($delay > 0) { usleep($delay * 1000000); } if ($redirect) { header($_SERVER['SERVER_PROTOCOL'].' 302 Found', true, 302); header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']); echo 'Redirect'; } else { echo 'Ok'; } fwrite( $file, json_encode(array( 'SERVER' => $_SERVER, 'GET' => $_GET, 'POST' => $_POST, 'FILES' => $_FILES, 'INPUT' => file_get_contents('php://input'), )) ); fflush($file); flock($file, LOCK_UN); fclose($file); php-http-client-integration-tests-46398b4/src/000077500000000000000000000000001522250162400212665ustar00rootroot00000000000000php-http-client-integration-tests-46398b4/src/HttpAsyncClientTest.php000066400000000000000000000133731522250162400257220ustar00rootroot00000000000000httpAsyncClient = $this->createHttpAsyncClient(); } protected function tearDown(): void { unset($this->httpAdapter); } abstract protected function createHttpAsyncClient(): HttpAsyncClient; public function testSuccessiveCallMustUseResponseInterface(): void { $request = self::$requestFactory->createRequest('GET', self::getUri()); foreach (self::$defaultHeaders as $name => $value) { $request = $request->withHeader($name, $value); } $promise = $this->httpAsyncClient->sendAsyncRequest($request); $this->assertInstanceOf(Promise::class, $promise); $response = null; $promise->then()->then()->then(function ($r) use (&$response) { $response = $r; return $r; }); $promise->wait(false); $this->assertResponse( $response, [ 'body' => 'Ok', ] ); } public function testSuccessiveInvalidCallMustUseException(): void { $request = self::$requestFactory->createRequest('GET', $this->getInvalidUri()); foreach (self::$defaultHeaders as $name => $value) { $request = $request->withHeader($name, $value); } $promise = $this->httpAsyncClient->sendAsyncRequest($request); $this->assertInstanceOf(Promise::class, $promise); $exception = null; $response = null; $promise->then()->then()->then(function ($r) use (&$response) { $response = $r; return $r; }, function ($e) use (&$exception) { $exception = $e; throw $e; }); $promise->wait(false); $this->assertNull($response); $this->assertNotNull($exception); $this->assertInstanceOf(Exception::class, $exception); } /** * @dataProvider requestProvider * @group integration */ #[DataProvider('requestProvider')] #[Group('integration')] public function testAsyncSendRequest(string $method, string $uri, array $headers, ?string $body): void { if (null != $body) { $headers['Content-Length'] = (string) strlen($body); } $request = self::$requestFactory->createRequest($method, $uri); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } if (null !== $body) { $request = $request->withBody(self::$streamFactory->createStream($body)); } $promise = $this->httpAsyncClient->sendAsyncRequest($request); $this->assertInstanceOf(Promise::class, $promise); $response = null; $promise->then(function ($r) use (&$response) { $response = $r; return $response; }); $promise->wait(); $this->assertResponse( $response, [ 'body' => 'HEAD' === $method ? null : 'Ok', ] ); $this->assertRequest($method, $headers, $body, '1.1'); } /** * @group integration */ #[Group('integration')] public function testSendAsyncWithInvalidUri(): void { $request = self::$requestFactory->createRequest('GET', $this->getInvalidUri()); foreach (self::$defaultHeaders as $name => $value) { $request = $request->withHeader($name, $value); } $exception = null; $response = null; $promise = $this->httpAsyncClient->sendAsyncRequest($request); $this->assertInstanceOf(Promise::class, $promise); $promise->then(function ($r) use (&$response) { $response = $r; return $response; }, function ($e) use (&$exception) { $exception = $e; throw $e; }); $promise->wait(false); $this->assertNull($response); $this->assertNotNull($exception); $this->assertInstanceOf(Exception::class, $exception); } /** * @dataProvider requestWithOutcomeProvider * @group integration */ #[Group('integration')] #[DataProvider('requestWithOutcomeProvider')] public function testSendAsyncRequestWithOutcome(array $uriAndOutcome, string $protocolVersion, array $headers, ?string $body): void { if ('1.0' === $protocolVersion) { $body = null; } if (null != $body) { $headers['Content-Length'] = (string) strlen($body); } $request = self::$requestFactory->createRequest($method = 'GET', $uriAndOutcome[0]); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } if (null !== $body) { $request = $request->withBody(self::$streamFactory->createStream($body)); } $request = $request->withProtocolVersion($protocolVersion); $outcome = $uriAndOutcome[1]; $outcome['protocolVersion'] = $protocolVersion; $response = null; $promise = $this->httpAsyncClient->sendAsyncRequest($request); $promise->then(function ($r) use (&$response) { $response = $r; return $response; }); $this->assertInstanceOf(Promise::class, $promise); $promise->wait(); $this->assertResponse( $response, $outcome ); $this->assertRequest($method, $headers, $body, $protocolVersion); } } php-http-client-integration-tests-46398b4/src/HttpBaseTest.php000066400000000000000000000162611522250162400243570ustar00rootroot00000000000000 '1.1', 'statusCode' => 200, 'reasonPhrase' => 'OK', 'headers' => ['Content-Type' => 'text/html'], 'body' => 'Ok', ]; protected static array $defaultHeaders = [ 'Connection' => 'close', 'User-Agent' => 'PHP HTTP Adapter', 'Content-Length' => '0', ]; /** * {@inheritdoc} */ public static function setUpBeforeClass(): void { self::$logPath = PHPUnitUtility::getFile(true, 'php-http-adapter.log'); self::$requestFactory = self::$streamFactory = new HttpFactory(); } /** * {@inheritdoc} */ public static function tearDownAfterClass(): void { if (file_exists(self::$logPath)) { unlink(self::$logPath); } } public static function requestProvider(): array { $sets = [ 'methods' => self::getMethods(), 'uris' => [self::getUri()], 'headers' => self::getHeaders(), 'body' => self::getBodies(), ]; $cartesianProduct = new CartesianProduct($sets); $cases = $cartesianProduct->compute(); // Filter all TRACE requests with a body, as they're not HTTP spec compliant return array_filter($cases, function ($case) { if ('TRACE' === $case[0] && null !== $case[3]) { return false; } return true; }); } public static function requestWithOutcomeProvider(): array { $sets = [ 'urisAndOutcomes' => self::getUrisAndOutcomes(), 'protocolVersions' => self::getProtocolVersions(), 'headers' => self::getHeaders(), 'body' => self::getBodies(), ]; $cartesianProduct = new CartesianProduct($sets); return $cartesianProduct->compute(); } private static function getMethods(): array { return [ 'GET', 'HEAD', 'TRACE', 'POST', 'PUT', 'DELETE', 'OPTIONS', ]; } /** * @param string[] $query * * @return string|null */ protected static function getUri(array $query = []): ?string { return !empty($query) ? PHPUnitUtility::getUri().'?'.http_build_query($query, '', '&') : PHPUnitUtility::getUri(); } protected function getInvalidUri(): string { return 'http://invalid.php-http.org'; } private static function getUrisAndOutcomes(): array { return [ [ self::getUri(['client_error' => true]), [ 'statusCode' => 400, 'reasonPhrase' => 'Bad Request', ], ], [ self::getUri(['server_error' => true]), [ 'statusCode' => 500, 'reasonPhrase' => 'Internal Server Error', ], ], [ self::getUri(['redirect' => true]), [ 'statusCode' => 302, 'reasonPhrase' => 'Found', 'body' => 'Redirect', ], ], ]; } private static function getProtocolVersions(): array { return ['1.1', '1.0']; } /** * @return string[] */ private static function getHeaders(): array { $headers = self::$defaultHeaders; $headers['Accept-Charset'] = 'utf-8'; $headers['Accept-Language'] = 'en'; return [ self::$defaultHeaders, $headers, ]; } private static function getBodies(): array { return [ null, http_build_query(self::getData(), '', '&'), ]; } private static function getData(): array { return ['param1' => 'foo', 'param2' => ['bar', ['baz']]]; } protected function assertResponse(ResponseInterface $response, array $options = []) { $options = array_merge($this->defaultOptions, $options); // The response version may be greater or equal to the request version. See https://tools.ietf.org/html/rfc2145#section-2.3 $this->assertTrue(substr($options['protocolVersion'], 0, 1) === substr($response->getProtocolVersion(), 0, 1) && 1 !== version_compare($options['protocolVersion'], $response->getProtocolVersion())); $this->assertSame($options['statusCode'], $response->getStatusCode()); $this->assertSame($options['reasonPhrase'], $response->getReasonPhrase()); $this->assertNotEmpty($response->getHeaders()); foreach ($options['headers'] as $name => $value) { $this->assertTrue($response->hasHeader($name)); $this->assertStringStartsWith($value, $response->getHeaderLine($name)); } if (null === $options['body']) { $this->assertEmpty($response->getBody()->__toString()); } else { self::assertStringContainsString($options['body'], $response->getBody()->__toString()); } } /** * @param string[] $headers */ protected function assertRequest( string $method, array $headers = [], ?string $body = null, string $protocolVersion = '1.1' ) { $request = $this->getRequest(); $actualProtocolVersion = substr($request['SERVER']['SERVER_PROTOCOL'], 5); $this->assertTrue(substr($protocolVersion, 0, 1) === substr($actualProtocolVersion, 0, 1) && 1 !== version_compare($protocolVersion, $actualProtocolVersion)); $this->assertSame($method, $request['SERVER']['REQUEST_METHOD']); $defaultHeaders = [ 'Connection' => 'close', 'User-Agent' => 'PHP HTTP Adapter', ]; $headers = array_merge($defaultHeaders, $headers); foreach ($headers as $name => $value) { if (is_int($name)) { list($name, $value) = explode(':', $value); } $name = strtoupper(str_replace('-', '_', 'http-'.$name)); if (in_array($method, ['TRACE', 'HEAD'], true) && 'HTTP_CONTENT_LENGTH' === $name && !isset($request['SERVER'][$name])) { continue; } $this->assertArrayHasKey($name, $request['SERVER']); $this->assertSame($value, $request['SERVER'][$name], "Failed asserting value for {$name}."); } } protected function getRequest(): array { $file = fopen(self::$logPath, 'r'); flock($file, LOCK_EX); $request = json_decode(stream_get_contents($file), true); flock($file, LOCK_UN); fclose($file); return $request; } } php-http-client-integration-tests-46398b4/src/HttpClientTest.php000066400000000000000000000063141522250162400247210ustar00rootroot00000000000000 */ abstract class HttpClientTest extends HttpBaseTest { protected ClientInterface $httpAdapter; protected function setUp(): void { $this->httpAdapter = $this->createHttpAdapter(); } protected function tearDown(): void { unset($this->httpAdapter); } abstract protected function createHttpAdapter(): ClientInterface; /** * @dataProvider requestProvider * @group integration */ #[Group('integration')] #[DataProvider('requestProvider')] public function testSendRequest(string $method, string $uri, array $headers, ?string $body) { if (null != $body) { $headers['Content-Length'] = (string) strlen($body); } $request = self::$requestFactory->createRequest($method, $uri); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } if (null !== $body) { $request = $request->withBody(self::$streamFactory->createStream($body)); } $response = $this->httpAdapter->sendRequest($request); $this->assertResponse( $response, [ 'body' => 'HEAD' === $method ? null : 'Ok', ] ); $this->assertRequest($method, $headers, $body, '1.1'); } /** * @dataProvider requestWithOutcomeProvider * @group integration */ #[Group('integration')] #[DataProvider('requestWithOutcomeProvider')] public function testSendRequestWithOutcome(array $uriAndOutcome, string $protocolVersion, array $headers, ?string $body): void { if ('1.0' === $protocolVersion) { $body = null; } if (null != $body) { $headers['Content-Length'] = (string) strlen($body); } $request = self::$requestFactory->createRequest($method = 'GET', $uriAndOutcome[0]); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } if (null !== $body) { $request = $request->withBody(self::$streamFactory->createStream($body)); } $request->withProtocolVersion($protocolVersion); $response = $this->httpAdapter->sendRequest($request); $outcome = $uriAndOutcome[1]; $outcome['protocolVersion'] = $protocolVersion; $this->assertResponse($response, $outcome); $this->assertRequest($method, $headers, $body, $protocolVersion); } /** * @group integration */ #[Group('integration')] public function testSendWithInvalidUri(): void { $request = self::$requestFactory->createRequest( 'GET', $this->getInvalidUri(), ); foreach (self::$defaultHeaders as $name => $value) { $request = $request->withHeader($name, $value); } $this->expectException(NetworkExceptionInterface::class); $this->httpAdapter->sendRequest($request); } } php-http-client-integration-tests-46398b4/src/HttpFeatureTest.php000066400000000000000000000133531522250162400250770ustar00rootroot00000000000000createRequest( 'GET', 'https://httpbin.org/get' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } /** * @feature Send a POST Request */ public function testPost(): void { $testData = 'Test data'; $request = self::$messageFactory->createRequest('POST', 'https://httpbin.org/post'); $request = $request->withHeader('Content-Length', strlen($testData)); $request = $request->withBody(self::$streamFactory->createStream($testData)); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $contents = json_decode($response->getBody()->__toString()); $this->assertEquals($testData, $contents->data); } /** * @feature Send a PATCH Request */ public function testPatch(): void { $request = self::$messageFactory->createRequest( 'PATCH', 'https://httpbin.org/patch' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } /** * @feature Send a PUT Request */ public function testPut(): void { $request = self::$messageFactory->createRequest( 'PUT', 'https://httpbin.org/put' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } /** * @feature Send a DELETE Request */ public function testDelete(): void { $request = self::$messageFactory->createRequest( 'DELETE', 'https://httpbin.org/delete' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } /** * @feature Auto fixing content length header */ public function testAutoSetContentLength(): void { $testData = 'Test data'; $request = self::$messageFactory->createRequest( 'POST', 'https://httpbin.org/post', ); $request = $request->withBody(self::$streamFactory->createStream($testData)); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $contents = json_decode($response->getBody()->__toString()); $this->assertEquals($testData, $contents->data); } /** * @feature Encoding in UTF8 */ public function testEncoding(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/encoding/utf8' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $this->assertStringContainsString('€', $response->getBody()->__toString()); } /** * @feature Gzip content decoding */ public function testGzip(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/gzip' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $this->assertStringContainsString('gzip', $response->getBody()->__toString()); } /** * @feature Deflate content decoding */ public function testDeflate(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/deflate' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $this->assertStringContainsString('deflate', $response->getBody()->__toString()); } /** * @feature Follow redirection */ public function testRedirect(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/redirect/1' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } /** * @feature Dechunk stream body */ public function testChunked(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/stream/1' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); $content = @json_decode($response->getBody()->__toString()); $this->assertNotNull($content); } /** * @feature Ssl connection */ public function testSsl(): void { $request = self::$messageFactory->createRequest( 'GET', 'https://httpbin.org/get' ); $response = $this->createClient()->sendRequest($request); $this->assertSame(200, $response->getStatusCode()); } } php-http-client-integration-tests-46398b4/src/PHPUnitUtility.php000066400000000000000000000013521522250162400246530ustar00rootroot00000000000000 */ class PHPUnitUtility { /** * Gets the uri. * * @return string|bool The uri or FALSE if there is none. */ public static function getUri() { return array_key_exists('TEST_SERVER', $_SERVER) ? $_SERVER['TEST_SERVER'] : false; } /** * Gets the file. * * @param bool $tmp TRUE if the file should be in the "/tmp" directory else FALSE. * * @return string The file. */ public static function getFile(bool $tmp = true, ?string $name = null): string { return ($tmp ? realpath(sys_get_temp_dir()) : '').'/'.(null === $name ? uniqid() : $name); } }