From 0ae4f2e6502f66eee9f8eebcd81a1c4b02c8e96d Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 16 Feb 2025 21:42:32 -0500 Subject: [PATCH 1/6] Add shims for PHPUnit --- tests/run.sh | 2 ++ tests/run_phpunit.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/run.sh b/tests/run.sh index 334c7f2fd..bfccc1eff 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -33,6 +33,8 @@ source "run_static_analysis_check_phpstan.sh" source "run_static_analysis_check_psalm.sh" +set +x + source "display_errors.inc.sh" if [[ "${CI_PHP_FUTURE_RELEASE}" != "true" ]]; then diff --git a/tests/run_phpunit.sh b/tests/run_phpunit.sh index 01b8bd2b7..d30f8ff48 100755 --- a/tests/run_phpunit.sh +++ b/tests/run_phpunit.sh @@ -57,6 +57,14 @@ phpunit_v10_shim() { remove_expectWarning } +phpunit_v11_shim() { + :; +} + +phpunit_v12_shim() { + remove_expectWarning +} + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${SCRIPT_DIR}" @@ -101,6 +109,12 @@ elif [[ "${phpunit_version}" == "9."* ]]; then elif [[ "${phpunit_version}" == "10."* ]]; then phpunit_v10_shim phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings --fail-on-risky ${extra_args}" +elif [[ "${phpunit_version}" == "11."* ]]; then + phpunit_v11_shim + phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings --fail-on-risky ${extra_args}" +elif [[ "${phpunit_version}" == "12."* ]]; then + phpunit_v12_shim + phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings --fail-on-risky ${extra_args}" fi # Run tests. From f1e96aa79e4c182e0f8b86418b368a24d0735e52 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Mon, 17 Feb 2025 12:48:35 -0500 Subject: [PATCH 2/6] Fix PHPUnit error: undefined method returnValue() 1) CurlTest\PHPCurlClassTest::testMock Error: Call to undefined method CurlTest\PHPCurlClassTest::returnValue() --- tests/PHPCurlClass/PHPCurlClassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 857b01975..f36707f7a 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -3966,7 +3966,7 @@ public function testMock() $curl->expects($this->once()) ->method('getRawResponse') - ->will($this->returnValue('[]')); + ->willReturn('[]'); $this->assertEquals('[]', $curl->getRawResponse()); } From 971671257310e280c6a3867aa5946ac817c54fdb Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Mon, 17 Feb 2025 13:19:47 -0500 Subject: [PATCH 3/6] Fix PHPUnit risky test by restoring error handler before exception thrown There was 1 risky test: 1) CurlTest\PHPCurlClassTest::testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnit10Plus Test code or tested code did not remove its own error handlers --- tests/PHPCurlClass/PHPCurlClassTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index f36707f7a..fa78f67e1 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -3190,7 +3190,7 @@ public function testCookieJarAfterClose() * @requires PHPUnit < 10 * @expectedException \PHPUnit\Framework\Error\Warning */ - public function testRequiredOptionCurlOptReturnTransferEmitsWarning() + public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnitLessThan10() { $this->expectWarning(\PHPUnit\Framework\Error\Warning::class); @@ -3204,6 +3204,7 @@ public function testRequiredOptionCurlOptReturnTransferEmitsWarning() public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnit10Plus() { set_error_handler(static function (int $errno, string $errstr): never { + restore_error_handler(); throw new \Exception($errstr, $errno); }, E_USER_WARNING); @@ -3211,8 +3212,6 @@ public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnit10Plus $curl = new Curl(); $curl->setOpt(CURLOPT_RETURNTRANSFER, false); - - restore_error_handler(); } public function testRequestMethodSuccessiveGetRequests() From eefc91908f00d655ae04b87b4f52e05109dd00df Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Mon, 17 Feb 2025 15:37:48 -0500 Subject: [PATCH 4/6] Fix psalm errors --- src/Curl/Curl.php | 27 ++++++++++++++------------- src/Curl/MultiCurl.php | 4 ++-- tests/psalm.xml | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index d71118f1c..579e99887 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -328,7 +328,7 @@ public function download($url, $mixed_filename) // Attempt to resume download only when a temporary download file exists and is not empty. if (is_file($download_filename) && $filesize = filesize($download_filename)) { $first_byte_position = $filesize; - $range = $first_byte_position . '-'; + $range = (string)$first_byte_position . '-'; $this->setRange($range); $this->fileHandle = fopen($download_filename, 'ab'); } else { @@ -385,7 +385,7 @@ public function fastDownload($url, $filename, $connections = 4) } // Divide chunk_size across the number of connections. - $chunk_size = ceil($content_length / $connections); + $chunk_size = (int)ceil($content_length / $connections); // Keep track of file name parts. $part_file_names = []; @@ -399,9 +399,9 @@ public function fastDownload($url, $filename, $connections = 4) if ($part_number === $connections) { $range_end = ''; } - $range = $range_start . '-' . $range_end; + $range = (string)$range_start . '-' . (string)$range_end; - $part_file_name = $filename . '.part' . $part_number; + $part_file_name = $filename . '.part' . (string)$part_number; // Save the file name of this part. $part_file_names[] = $part_file_name; @@ -1294,13 +1294,13 @@ public function diagnose($return = false) $response_headers_count = count($this->responseHeaders); echo - 'Request contained ' . $request_options_count . ' ' . ( + 'Request contained ' . (string)$request_options_count . ' ' . ( $request_options_count === 1 ? 'option:' : 'options:' ) . "\n"; if ($request_options_count) { $i = 1; foreach ($this->options as $option => $value) { - echo ' ' . $i . ' '; + echo ' ' . (string)$i . ' '; $this->displayCurlOptionValue($option, $value); $i += 1; } @@ -1308,13 +1308,13 @@ public function diagnose($return = false) echo 'Sent an HTTP ' . $request_method . ' request to "' . $request_url . '".' . "\n" . - 'Request contained ' . $request_headers_count . ' ' . ( + 'Request contained ' . (string)$request_headers_count . ' ' . ( $request_headers_count === 1 ? 'header:' : 'headers:' ) . "\n"; if ($request_headers_count) { $i = 1; foreach ($this->requestHeaders as $key => $value) { - echo ' ' . $i . ' ' . $key . ': ' . $value . "\n"; + echo ' ' . (string)$i . ' ' . $key . ': ' . $value . "\n"; $i += 1; } } @@ -1346,13 +1346,13 @@ public function diagnose($return = false) } echo - 'Response contains ' . $response_headers_count . ' ' . ( + 'Response contains ' . (string)$response_headers_count . ' ' . ( $response_headers_count === 1 ? 'header:' : 'headers:' ) . "\n"; if ($this->responseHeaders !== null) { $i = 1; foreach ($this->responseHeaders as $key => $value) { - echo ' ' . $i . ' ' . $key . ': ' . $value . "\n"; + echo ' ' . (string)$i . ' ' . $key . ': ' . $value . "\n"; $i += 1; } } @@ -1409,12 +1409,13 @@ public function diagnose($return = false) $messages_count = count($messages); if ($messages_count) { echo - 'Found ' . $messages_count . ' ' . ($messages_count === 1 ? 'message' : 'messages') . + 'Found ' . (string)$messages_count . ' ' . + ($messages_count === 1 ? 'message' : 'messages') . ' in response:' . "\n"; $i = 1; foreach ($messages as $message) { - echo ' ' . $i . ' ' . $message . "\n"; + echo ' ' . (string)$i . ' ' . $message . "\n"; $i += 1; } } @@ -1713,7 +1714,7 @@ public function displayCurlOptionValue($option, $value = null) if (is_string($value)) { echo ' "' . $value . '"' . "\n"; } elseif (is_int($value)) { - echo ' ' . $value; + echo ' ' . (string)$value; $bit_flag_lookups = [ 'CURLOPT_HTTPAUTH' => 'CURLAUTH_', diff --git a/src/Curl/MultiCurl.php b/src/Curl/MultiCurl.php index f6c00a8c8..d84c09bfd 100644 --- a/src/Curl/MultiCurl.php +++ b/src/Curl/MultiCurl.php @@ -111,7 +111,7 @@ public function addDownload($url, $mixed_filename) // Attempt to resume download only when a temporary download file exists and is not empty. if (is_file($download_filename) && $filesize = filesize($download_filename)) { $first_byte_position = $filesize; - $range = $first_byte_position . '-'; + $range = (string)$first_byte_position . '-'; $curl->setRange($range); $curl->fileHandle = fopen($download_filename, 'ab'); @@ -587,7 +587,7 @@ public function setRateLimit($rate_limit) $interval_seconds = $interval * 3600; } - $this->rateLimit = $max_requests . '/' . $interval . $unit; + $this->rateLimit = (string)$max_requests . '/' . (string)$interval . $unit; $this->rateLimitEnabled = true; $this->maxRequests = $max_requests; $this->interval = $interval; diff --git a/tests/psalm.xml b/tests/psalm.xml index e2f098d3b..c1a61e7fe 100644 --- a/tests/psalm.xml +++ b/tests/psalm.xml @@ -1,6 +1,7 @@ Date: Mon, 17 Feb 2025 15:53:14 -0500 Subject: [PATCH 5/6] Add attributes for version constraint --- tests/PHPCurlClass/PHPCurlClassTest.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index fa78f67e1..4991d646b 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -3186,21 +3186,10 @@ public function testCookieJarAfterClose() $this->assertNotEmpty($cookies); } - /** - * @requires PHPUnit < 10 - * @expectedException \PHPUnit\Framework\Error\Warning - */ - public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnitLessThan10() - { - $this->expectWarning(\PHPUnit\Framework\Error\Warning::class); - - $curl = new Curl(); - $curl->setOpt(CURLOPT_RETURNTRANSFER, false); - } - /** * @requires PHPUnit >= 10 */ + #[RequiresPhpunit('>= 10')] public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnit10Plus() { set_error_handler(static function (int $errno, string $errstr): never { From 7fe108023eddef626403e2988e7b33367c861d43 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Mon, 17 Feb 2025 15:17:40 -0500 Subject: [PATCH 6/6] Temporarily pin psalm to fix ci --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0e7a8bbc2..bc7ef3661 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "phpstan/phpstan": "*", "phpunit/phpunit": "*", "squizlabs/php_codesniffer": "*", - "vimeo/psalm": ">=5.26.1" + "vimeo/psalm": ">=5.26.1,<6.7" }, "suggest": { "ext-mbstring": "*"