From 93c328bdda22e756c5289355cf42feca20591599 Mon Sep 17 00:00:00 2001 From: Jared Whiklo Date: Tue, 19 Nov 2024 14:32:38 -0600 Subject: [PATCH] Correct PIPEWAIT and add test for trait --- src/CurlInstance.php | 10 +++++----- tests/CurlInstanceTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/CurlInstanceTest.php diff --git a/src/CurlInstance.php b/src/CurlInstance.php index 202fce4..ccb60ce 100644 --- a/src/CurlInstance.php +++ b/src/CurlInstance.php @@ -94,18 +94,18 @@ private static function setupCurl(string $curlVersion): array if (!defined('CURLMOPT_MAX_TOTAL_CONNECTIONS')) { define('CURLMOPT_MAX_TOTAL_CONNECTIONS', 13); } - if (!defined('CURL_PIPEWAIT')) { - define('CURL_PIPEWAIT', 237); + if (!defined('CURLOPT_PIPEWAIT')) { + define('CURLOPT_PIPEWAIT', 237); } $curlOptions = [ CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, ]; if ( - version_compare('7.0', PHP_VERSION) <= 0 && - version_compare('7.43.0', $curlVersion) <= 0 + version_compare('7.0', PHP_VERSION, '<=') && + version_compare('7.43.0', $curlVersion, '<=') ) { - $curlOptions[CURL_PIPEWAIT] = true; + $curlOptions[CURLOPT_PIPEWAIT] = true; } return $curlOptions; } diff --git a/tests/CurlInstanceTest.php b/tests/CurlInstanceTest.php new file mode 100644 index 0000000..981222f --- /dev/null +++ b/tests/CurlInstanceTest.php @@ -0,0 +1,30 @@ +createCurl('http://example.com'); + $this->assertInstanceOf(\CurlHandle::class, $handle); + } + + public function testCurlMulti() + { + $mock = new class + { + use CurlInstance; + }; // anonymous class + + $handle = $mock->createMultiCurl(); + $this->assertInstanceOf(\CurlMultiHandle::class, $handle); + } +}