Skip to content

Commit

Permalink
Correct PIPEWAIT and add test for trait
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed Nov 19, 2024
1 parent fe216d9 commit 93c328b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/CurlInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions tests/CurlInstanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace whikloj\BagItTools\Test;

use whikloj\BagItTools\CurlInstance;

class CurlInstanceTest extends BagItTestFramework
{
public function testCreateCurl()
{
$mock = new class
{
use CurlInstance;
}; // anonymous class

$handle = $mock->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);
}
}

0 comments on commit 93c328b

Please sign in to comment.