mirror of
https://github.com/guzzle/guzzle.git
synced 2025-01-16 13:00:46 +01:00
Fixes for PHP 8.4 deprecation (#3203)
This commit is contained in:
parent
354893b0c0
commit
53f5a4ece4
@ -5,6 +5,7 @@ $config = (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@PHP71Migration:risky' => true,
|
||||
'@PHPUnit75Migration:risky' => true,
|
||||
'@PSR12:risky' => true,
|
||||
'@Symfony' => true,
|
||||
'declare_strict_types' => false,
|
||||
'global_namespace_import' => false,
|
||||
|
@ -11,7 +11,7 @@ final class BodySummarizer implements BodySummarizerInterface
|
||||
*/
|
||||
private $truncateAt;
|
||||
|
||||
public function __construct(int $truncateAt = null)
|
||||
public function __construct(?int $truncateAt = null)
|
||||
{
|
||||
$this->truncateAt = $truncateAt;
|
||||
}
|
||||
@ -22,7 +22,7 @@ final class BodySummarizer implements BodySummarizerInterface
|
||||
public function summarize(MessageInterface $message): ?string
|
||||
{
|
||||
return $this->truncateAt === null
|
||||
? \GuzzleHttp\Psr7\Message::bodySummary($message)
|
||||
: \GuzzleHttp\Psr7\Message::bodySummary($message, $this->truncateAt);
|
||||
? Psr7\Message::bodySummary($message)
|
||||
: Psr7\Message::bodySummary($message, $this->truncateAt);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Client implements ClientInterface, \Psr\Http\Client\ClientInterface
|
||||
*
|
||||
* @param array $config Client configuration settings.
|
||||
*
|
||||
* @see \GuzzleHttp\RequestOptions for a list of available request options.
|
||||
* @see RequestOptions for a list of available request options.
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
@ -202,7 +202,7 @@ class Client implements ClientInterface, \Psr\Http\Client\ClientInterface
|
||||
*
|
||||
* @deprecated Client::getConfig will be removed in guzzlehttp/guzzle:8.0.
|
||||
*/
|
||||
public function getConfig(string $option = null)
|
||||
public function getConfig(?string $option = null)
|
||||
{
|
||||
return $option === null
|
||||
? $this->config
|
||||
|
@ -80,5 +80,5 @@ interface ClientInterface
|
||||
*
|
||||
* @deprecated ClientInterface::getConfig will be removed in guzzlehttp/guzzle:8.0.
|
||||
*/
|
||||
public function getConfig(string $option = null);
|
||||
public function getConfig(?string $option = null);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class CookieJar implements CookieJarInterface
|
||||
}, $this->getIterator()->getArrayCopy());
|
||||
}
|
||||
|
||||
public function clear(string $domain = null, string $path = null, string $name = null): void
|
||||
public function clear(?string $domain = null, ?string $path = null, ?string $name = null): void
|
||||
{
|
||||
if (!$domain) {
|
||||
$this->cookies = [];
|
||||
|
@ -62,7 +62,7 @@ interface CookieJarInterface extends \Countable, \IteratorAggregate
|
||||
* @param string|null $path Clears cookies matching a domain and path
|
||||
* @param string|null $name Clears cookies matching a domain, path, and name
|
||||
*/
|
||||
public function clear(string $domain = null, string $path = null, string $name = null): void;
|
||||
public function clear(?string $domain = null, ?string $path = null, ?string $name = null): void;
|
||||
|
||||
/**
|
||||
* Discard all sessions cookies.
|
||||
|
@ -14,7 +14,7 @@ class BadResponseException extends RequestException
|
||||
string $message,
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response,
|
||||
\Throwable $previous = null,
|
||||
?\Throwable $previous = null,
|
||||
array $handlerContext = []
|
||||
) {
|
||||
parent::__construct($message, $request, $response, $previous, $handlerContext);
|
||||
|
@ -25,7 +25,7 @@ class ConnectException extends TransferException implements NetworkExceptionInte
|
||||
public function __construct(
|
||||
string $message,
|
||||
RequestInterface $request,
|
||||
\Throwable $previous = null,
|
||||
?\Throwable $previous = null,
|
||||
array $handlerContext = []
|
||||
) {
|
||||
parent::__construct($message, 0, $previous);
|
||||
|
@ -32,8 +32,8 @@ class RequestException extends TransferException implements RequestExceptionInte
|
||||
public function __construct(
|
||||
string $message,
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response = null,
|
||||
\Throwable $previous = null,
|
||||
?ResponseInterface $response = null,
|
||||
?\Throwable $previous = null,
|
||||
array $handlerContext = []
|
||||
) {
|
||||
// Set the code of the exception if the response is set and not future.
|
||||
@ -63,10 +63,10 @@ class RequestException extends TransferException implements RequestExceptionInte
|
||||
*/
|
||||
public static function create(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response = null,
|
||||
\Throwable $previous = null,
|
||||
?ResponseInterface $response = null,
|
||||
?\Throwable $previous = null,
|
||||
array $handlerContext = [],
|
||||
BodySummarizerInterface $bodySummarizer = null
|
||||
?BodySummarizerInterface $bodySummarizer = null
|
||||
): self {
|
||||
if (!$response) {
|
||||
return new self(
|
||||
|
@ -52,21 +52,21 @@ class MockHandler implements \Countable
|
||||
* @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
|
||||
* @param callable|null $onRejected Callback to invoke when the return value is rejected.
|
||||
*/
|
||||
public static function createWithMiddleware(array $queue = null, callable $onFulfilled = null, callable $onRejected = null): HandlerStack
|
||||
public static function createWithMiddleware(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null): HandlerStack
|
||||
{
|
||||
return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
|
||||
}
|
||||
|
||||
/**
|
||||
* The passed in value must be an array of
|
||||
* {@see \Psr\Http\Message\ResponseInterface} objects, Exceptions,
|
||||
* {@see ResponseInterface} objects, Exceptions,
|
||||
* callables, or Promises.
|
||||
*
|
||||
* @param array<int, mixed>|null $queue The parameters to be passed to the append function, as an indexed array.
|
||||
* @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
|
||||
* @param callable|null $onRejected Callback to invoke when the return value is rejected.
|
||||
*/
|
||||
public function __construct(array $queue = null, callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function __construct(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||
{
|
||||
$this->onFulfilled = $onFulfilled;
|
||||
$this->onRejected = $onRejected;
|
||||
@ -200,7 +200,7 @@ class MockHandler implements \Countable
|
||||
private function invokeStats(
|
||||
RequestInterface $request,
|
||||
array $options,
|
||||
ResponseInterface $response = null,
|
||||
?ResponseInterface $response = null,
|
||||
$reason = null
|
||||
): void {
|
||||
if (isset($options['on_stats'])) {
|
||||
|
@ -83,8 +83,8 @@ class StreamHandler
|
||||
array $options,
|
||||
RequestInterface $request,
|
||||
?float $startTime,
|
||||
ResponseInterface $response = null,
|
||||
\Throwable $error = null
|
||||
?ResponseInterface $response = null,
|
||||
?\Throwable $error = null
|
||||
): void {
|
||||
if (isset($options['on_stats'])) {
|
||||
$stats = new TransferStats($request, $response, Utils::currentTime() - $startTime, $error, []);
|
||||
|
@ -44,7 +44,7 @@ class HandlerStack
|
||||
* handler is provided, the best handler for your
|
||||
* system will be utilized.
|
||||
*/
|
||||
public static function create(callable $handler = null): self
|
||||
public static function create(?callable $handler = null): self
|
||||
{
|
||||
$stack = new self($handler ?: Utils::chooseHandler());
|
||||
$stack->push(Middleware::httpErrors(), 'http_errors');
|
||||
@ -58,7 +58,7 @@ class HandlerStack
|
||||
/**
|
||||
* @param (callable(RequestInterface, array): PromiseInterface)|null $handler Underlying HTTP handler.
|
||||
*/
|
||||
public function __construct(callable $handler = null)
|
||||
public function __construct(?callable $handler = null)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
}
|
||||
@ -131,7 +131,7 @@ class HandlerStack
|
||||
* @param callable(callable): callable $middleware Middleware function
|
||||
* @param string $name Name to register for this middleware.
|
||||
*/
|
||||
public function unshift(callable $middleware, string $name = null): void
|
||||
public function unshift(callable $middleware, ?string $name = null): void
|
||||
{
|
||||
\array_unshift($this->stack, [$middleware, $name]);
|
||||
$this->cached = null;
|
||||
|
@ -68,7 +68,7 @@ class MessageFormatter implements MessageFormatterInterface
|
||||
* @param ResponseInterface|null $response Response that was received
|
||||
* @param \Throwable|null $error Exception that was received
|
||||
*/
|
||||
public function format(RequestInterface $request, ResponseInterface $response = null, \Throwable $error = null): string
|
||||
public function format(RequestInterface $request, ?ResponseInterface $response = null, ?\Throwable $error = null): string
|
||||
{
|
||||
$cache = [];
|
||||
|
||||
|
@ -14,5 +14,5 @@ interface MessageFormatterInterface
|
||||
* @param ResponseInterface|null $response Response that was received
|
||||
* @param \Throwable|null $error Exception that was received
|
||||
*/
|
||||
public function format(RequestInterface $request, ResponseInterface $response = null, \Throwable $error = null): string;
|
||||
public function format(RequestInterface $request, ?ResponseInterface $response = null, ?\Throwable $error = null): string;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ final class Middleware
|
||||
*
|
||||
* @return callable(callable): callable Returns a function that accepts the next handler.
|
||||
*/
|
||||
public static function httpErrors(BodySummarizerInterface $bodySummarizer = null): callable
|
||||
public static function httpErrors(?BodySummarizerInterface $bodySummarizer = null): callable
|
||||
{
|
||||
return static function (callable $handler) use ($bodySummarizer): callable {
|
||||
return static function ($request, array $options) use ($handler, $bodySummarizer) {
|
||||
@ -132,7 +132,7 @@ final class Middleware
|
||||
*
|
||||
* @return callable Returns a function that accepts the next handler.
|
||||
*/
|
||||
public static function tap(callable $before = null, callable $after = null): callable
|
||||
public static function tap(?callable $before = null, ?callable $after = null): callable
|
||||
{
|
||||
return static function (callable $handler) use ($before, $after): callable {
|
||||
return static function (RequestInterface $request, array $options) use ($handler, $before, $after) {
|
||||
@ -176,7 +176,7 @@ final class Middleware
|
||||
*
|
||||
* @return callable Returns a function that accepts the next handler.
|
||||
*/
|
||||
public static function retry(callable $decider, callable $delay = null): callable
|
||||
public static function retry(callable $decider, ?callable $delay = null): callable
|
||||
{
|
||||
return static function (callable $handler) use ($decider, $delay): RetryMiddleware {
|
||||
return new RetryMiddleware($decider, $handler, $delay);
|
||||
|
@ -61,7 +61,7 @@ final class RequestOptions
|
||||
* Specifies whether or not cookies are used in a request or what cookie
|
||||
* jar to use or what cookies to send. This option only works if your
|
||||
* handler has the `cookie` middleware. Valid values are `false` and
|
||||
* an instance of {@see \GuzzleHttp\Cookie\CookieJarInterface}.
|
||||
* an instance of {@see Cookie\CookieJarInterface}.
|
||||
*/
|
||||
public const COOKIES = 'cookies';
|
||||
|
||||
|
@ -40,7 +40,7 @@ class RetryMiddleware
|
||||
* and returns the number of
|
||||
* milliseconds to delay.
|
||||
*/
|
||||
public function __construct(callable $decider, callable $nextHandler, callable $delay = null)
|
||||
public function __construct(callable $decider, callable $nextHandler, ?callable $delay = null)
|
||||
{
|
||||
$this->decider = $decider;
|
||||
$this->nextHandler = $nextHandler;
|
||||
@ -110,7 +110,7 @@ class RetryMiddleware
|
||||
};
|
||||
}
|
||||
|
||||
private function doRetry(RequestInterface $request, array $options, ResponseInterface $response = null): PromiseInterface
|
||||
private function doRetry(RequestInterface $request, array $options, ?ResponseInterface $response = null): PromiseInterface
|
||||
{
|
||||
$options['delay'] = ($this->delay)(++$options['retries'], $response, $request);
|
||||
|
||||
|
@ -46,8 +46,8 @@ final class TransferStats
|
||||
*/
|
||||
public function __construct(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response = null,
|
||||
float $transferTime = null,
|
||||
?ResponseInterface $response = null,
|
||||
?float $transferTime = null,
|
||||
$handlerErrorData = null,
|
||||
array $handlerStats = []
|
||||
) {
|
||||
|
@ -71,7 +71,7 @@ final class Utils
|
||||
return \STDOUT;
|
||||
}
|
||||
|
||||
return \GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w');
|
||||
return Psr7\Utils::tryFopen('php://output', 'w');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class CurlFactoryTest extends TestCase
|
||||
'Hi' => ' 123',
|
||||
'Content-Length' => '7',
|
||||
], 'testing');
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$result = $f->create($request, ['sink' => $stream]);
|
||||
self::assertInstanceOf(EasyHandle::class, $result);
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
@ -118,7 +118,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testValidatesVerify()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('SSL CA bundle not found: /does/not/exist');
|
||||
@ -127,7 +127,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testCanSetVerifyToFile()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', 'http://foo.com'), ['verify' => __FILE__]);
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_CAINFO]);
|
||||
self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]);
|
||||
@ -136,7 +136,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testCanSetVerifyToDir()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', 'http://foo.com'), ['verify' => __DIR__]);
|
||||
self::assertEquals(__DIR__, $_SERVER['_curl'][\CURLOPT_CAPATH]);
|
||||
self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]);
|
||||
@ -145,7 +145,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsVerifyAsTrue()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['verify' => true]);
|
||||
self::assertEquals(2, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]);
|
||||
self::assertTrue($_SERVER['_curl'][\CURLOPT_SSL_VERIFYPEER]);
|
||||
@ -154,7 +154,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testCanDisableVerify()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['verify' => false]);
|
||||
self::assertEquals(0, $_SERVER['_curl'][\CURLOPT_SSL_VERIFYHOST]);
|
||||
self::assertFalse($_SERVER['_curl'][\CURLOPT_SSL_VERIFYPEER]);
|
||||
@ -162,14 +162,14 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsProxy()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['proxy' => 'http://bar.com']);
|
||||
self::assertEquals('http://bar.com', $_SERVER['_curl'][\CURLOPT_PROXY]);
|
||||
}
|
||||
|
||||
public function testAddsViaScheme()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), [
|
||||
'proxy' => ['http' => 'http://bar.com', 'https' => 'https://t'],
|
||||
]);
|
||||
@ -183,7 +183,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
private function checkNoProxyForHost($url, $noProxy, $assertUseProxy)
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', $url), [
|
||||
'proxy' => [
|
||||
'http' => 'http://bar.com',
|
||||
@ -223,7 +223,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testValidatesCryptoMethodInvalidMethod()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid crypto_method request option: unknown version provided');
|
||||
@ -232,21 +232,21 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsCryptoMethodTls10()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT]);
|
||||
self::assertEquals(\CURL_SSLVERSION_TLSv1_0, $_SERVER['_curl'][\CURLOPT_SSLVERSION]);
|
||||
}
|
||||
|
||||
public function testAddsCryptoMethodTls11()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT]);
|
||||
self::assertEquals(\CURL_SSLVERSION_TLSv1_1, $_SERVER['_curl'][\CURLOPT_SSLVERSION]);
|
||||
}
|
||||
|
||||
public function testAddsCryptoMethodTls12()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT]);
|
||||
self::assertEquals(\CURL_SSLVERSION_TLSv1_2, $_SERVER['_curl'][\CURLOPT_SSLVERSION]);
|
||||
}
|
||||
@ -256,14 +256,14 @@ class CurlFactoryTest extends TestCase
|
||||
*/
|
||||
public function testAddsCryptoMethodTls13()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]);
|
||||
self::assertEquals(\CURL_SSLVERSION_TLSv1_3, $_SERVER['_curl'][\CURLOPT_SSLVERSION]);
|
||||
}
|
||||
|
||||
public function testValidatesSslKey()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('SSL private key not found: /does/not/exist');
|
||||
@ -272,14 +272,14 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsSslKey()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => __FILE__]);
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]);
|
||||
}
|
||||
|
||||
public function testAddsSslKeyWithPassword()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__, 'test']]);
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]);
|
||||
self::assertEquals('test', $_SERVER['_curl'][\CURLOPT_SSLKEYPASSWD]);
|
||||
@ -287,7 +287,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsSslKeyWhenUsingArraySyntaxButNoPassword()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__]]);
|
||||
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLKEY]);
|
||||
@ -295,7 +295,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testValidatesCert()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('SSL certificate not found: /does/not/exist');
|
||||
@ -304,14 +304,14 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsCert()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['cert' => __FILE__]);
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLCERT]);
|
||||
}
|
||||
|
||||
public function testAddsCertWithPassword()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['cert' => [__FILE__, 'test']]);
|
||||
self::assertEquals(__FILE__, $_SERVER['_curl'][\CURLOPT_SSLCERT]);
|
||||
self::assertEquals('test', $_SERVER['_curl'][\CURLOPT_SSLCERTPASSWD]);
|
||||
@ -322,7 +322,7 @@ class CurlFactoryTest extends TestCase
|
||||
$certFile = tempnam(sys_get_temp_dir(), 'mock_test_cert');
|
||||
rename($certFile, $certFile .= '.der');
|
||||
try {
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['cert' => $certFile]);
|
||||
self::assertArrayHasKey(\CURLOPT_SSLCERTTYPE, $_SERVER['_curl']);
|
||||
self::assertEquals('DER', $_SERVER['_curl'][\CURLOPT_SSLCERTTYPE]);
|
||||
@ -336,7 +336,7 @@ class CurlFactoryTest extends TestCase
|
||||
$certFile = tempnam(sys_get_temp_dir(), 'mock_test_cert');
|
||||
rename($certFile, $certFile .= '.p12');
|
||||
try {
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), ['cert' => $certFile]);
|
||||
self::assertArrayHasKey(\CURLOPT_SSLCERTTYPE, $_SERVER['_curl']);
|
||||
self::assertEquals('P12', $_SERVER['_curl'][\CURLOPT_SSLCERTTYPE]);
|
||||
@ -347,7 +347,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testValidatesProgress()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('progress client option must be callable');
|
||||
@ -566,7 +566,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testFailsWhenCannotRewindRetryAfterNoResponse()
|
||||
{
|
||||
$factory = new Handler\CurlFactory(1);
|
||||
$factory = new CurlFactory(1);
|
||||
$stream = Psr7\Utils::streamFor('abc');
|
||||
$stream->read(1);
|
||||
$stream = new Psr7\NoSeekStream($stream);
|
||||
@ -574,7 +574,7 @@ class CurlFactoryTest extends TestCase
|
||||
$fn = static function ($request, $options) use (&$fn, $factory) {
|
||||
$easy = $factory->create($request, $options);
|
||||
|
||||
return Handler\CurlFactory::finish($fn, $easy, $factory);
|
||||
return CurlFactory::finish($fn, $easy, $factory);
|
||||
};
|
||||
|
||||
$this->expectException(RequestException::class);
|
||||
@ -601,10 +601,10 @@ class CurlFactoryTest extends TestCase
|
||||
},
|
||||
]);
|
||||
|
||||
$factory = new Handler\CurlFactory(1);
|
||||
$factory = new CurlFactory(1);
|
||||
$req = new Psr7\Request('PUT', Server::$url, [], $bd);
|
||||
$easy = $factory->create($req, []);
|
||||
$res = Handler\CurlFactory::finish($fn, $easy, $factory);
|
||||
$res = CurlFactory::finish($fn, $easy, $factory);
|
||||
$res = $res->wait();
|
||||
self::assertTrue($callHandler);
|
||||
self::assertTrue($called);
|
||||
@ -613,13 +613,13 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testFailsWhenRetryMoreThanThreeTimes()
|
||||
{
|
||||
$factory = new Handler\CurlFactory(1);
|
||||
$factory = new CurlFactory(1);
|
||||
$call = 0;
|
||||
$fn = static function ($request, $options) use (&$mock, &$call, $factory) {
|
||||
++$call;
|
||||
$easy = $factory->create($request, $options);
|
||||
|
||||
return Handler\CurlFactory::finish($mock, $easy, $factory);
|
||||
return CurlFactory::finish($mock, $easy, $factory);
|
||||
};
|
||||
$mock = new Handler\MockHandler([$fn, $fn, $fn]);
|
||||
$p = $mock(new Psr7\Request('PUT', Server::$url, [], 'test'), []);
|
||||
@ -653,7 +653,7 @@ class CurlFactoryTest extends TestCase
|
||||
{
|
||||
$m = new \ReflectionMethod(CurlFactory::class, 'finishError');
|
||||
$m->setAccessible(true);
|
||||
$factory = new Handler\CurlFactory(1);
|
||||
$factory = new CurlFactory(1);
|
||||
$easy = $factory->create(new Psr7\Request('GET', Server::$url), []);
|
||||
$easy->errno = \CURLE_COULDNT_CONNECT;
|
||||
$response = $m->invoke(
|
||||
@ -670,7 +670,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsTimeouts()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$f->create(new Psr7\Request('GET', Server::$url), [
|
||||
'timeout' => 0.1,
|
||||
'connect_timeout' => 0.2,
|
||||
@ -681,7 +681,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testAddsStreamingBody()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$bd = Psr7\FnStream::decorate(Psr7\Utils::streamFor('foo'), [
|
||||
'getSize' => static function () {
|
||||
return null;
|
||||
@ -695,7 +695,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testEnsuresDirExistsBeforeThrowingWarning()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Directory /does/not/exist/so does not exist for sink value of /does/not/exist/so/error.txt');
|
||||
@ -706,7 +706,7 @@ class CurlFactoryTest extends TestCase
|
||||
|
||||
public function testClosesIdleHandles()
|
||||
{
|
||||
$f = new Handler\CurlFactory(3);
|
||||
$f = new CurlFactory(3);
|
||||
$req = new Psr7\Request('GET', Server::$url);
|
||||
$easy = $f->create($req, []);
|
||||
$h1 = $easy->handle;
|
||||
@ -736,7 +736,7 @@ class CurlFactoryTest extends TestCase
|
||||
$handler = new Handler\CurlHandler();
|
||||
$promise = $handler($req, []);
|
||||
|
||||
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
|
||||
$this->expectException(RequestException::class);
|
||||
$this->expectExceptionMessage('An error was encountered while creating the response');
|
||||
$promise->wait();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class CurlHandlerTest extends TestCase
|
||||
public function testReusesHandles()
|
||||
{
|
||||
Server::flush();
|
||||
$response = new response(200);
|
||||
$response = new Response(200);
|
||||
Server::enqueue([$response, $response]);
|
||||
$a = new CurlHandler();
|
||||
$request = new Request('GET', Server::$url);
|
||||
@ -45,7 +45,7 @@ class CurlHandlerTest extends TestCase
|
||||
|
||||
public function testDoesSleep()
|
||||
{
|
||||
$response = new response(200);
|
||||
$response = new Response(200);
|
||||
Server::enqueue([$response]);
|
||||
$a = new CurlHandler();
|
||||
$request = new Request('GET', Server::$url);
|
||||
|
@ -570,7 +570,7 @@ class StreamHandlerTest extends TestCase
|
||||
|
||||
public function testDoesSleep()
|
||||
{
|
||||
$response = new response(200);
|
||||
$response = new Response(200);
|
||||
Server::enqueue([$response]);
|
||||
$a = new StreamHandler();
|
||||
$request = new Request('GET', Server::$url);
|
||||
@ -643,8 +643,8 @@ class StreamHandlerTest extends TestCase
|
||||
public function testInvokesOnStatsOnSuccess()
|
||||
{
|
||||
Server::flush();
|
||||
Server::enqueue([new Psr7\Response(200)]);
|
||||
$req = new Psr7\Request('GET', Server::$url);
|
||||
Server::enqueue([new Response(200)]);
|
||||
$req = new Request('GET', Server::$url);
|
||||
$gotStats = null;
|
||||
$handler = new StreamHandler();
|
||||
$promise = $handler($req, [
|
||||
@ -668,7 +668,7 @@ class StreamHandlerTest extends TestCase
|
||||
|
||||
public function testInvokesOnStatsOnError()
|
||||
{
|
||||
$req = new Psr7\Request('GET', 'http://127.0.0.1:123');
|
||||
$req = new Request('GET', 'http://127.0.0.1:123');
|
||||
$gotStats = null;
|
||||
$handler = new StreamHandler();
|
||||
$promise = $handler($req, [
|
||||
@ -698,8 +698,8 @@ class StreamHandlerTest extends TestCase
|
||||
public function testStreamIgnoresZeroTimeout()
|
||||
{
|
||||
Server::flush();
|
||||
Server::enqueue([new Psr7\Response(200)]);
|
||||
$req = new Psr7\Request('GET', Server::$url);
|
||||
Server::enqueue([new Response(200)]);
|
||||
$req = new Request('GET', Server::$url);
|
||||
$gotStats = null;
|
||||
$handler = new StreamHandler();
|
||||
$promise = $handler($req, [
|
||||
|
@ -113,7 +113,7 @@ class RedirectMiddlewareTest extends TestCase
|
||||
try {
|
||||
$promise->wait();
|
||||
self::fail();
|
||||
} catch (\GuzzleHttp\Exception\TooManyRedirectsException $e) {
|
||||
} catch (TooManyRedirectsException $e) {
|
||||
self::assertSame(302, $e->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"require": {
|
||||
"php": "^7.4 || ^8.0",
|
||||
"friendsofphp/php-cs-fixer": "3.40.2"
|
||||
"friendsofphp/php-cs-fixer": "3.52.1"
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist"
|
||||
|
Loading…
x
Reference in New Issue
Block a user