mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-27 18:50:43 +00:00
Fix CI (PHPUnit) (#918)
* Add shims for PHPUnit * Fix PHPUnit error: undefined method returnValue() 1) CurlTest\PHPCurlClassTest::testMock Error: Call to undefined method CurlTest\PHPCurlClassTest::returnValue() * 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 * Fix psalm errors * Add attributes for version constraint * Temporarily pin psalm to fix ci
This commit is contained in:
+1
-1
@@ -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": "*"
|
||||
|
||||
+14
-13
@@ -328,7 +328,7 @@ class Curl extends BaseCurl
|
||||
// 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 @@ class Curl extends BaseCurl
|
||||
}
|
||||
|
||||
// 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 @@ class Curl extends BaseCurl
|
||||
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 @@ class Curl extends BaseCurl
|
||||
$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 @@ class Curl extends BaseCurl
|
||||
|
||||
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 @@ class Curl extends BaseCurl
|
||||
}
|
||||
|
||||
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 @@ class Curl extends BaseCurl
|
||||
$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 @@ class Curl extends BaseCurl
|
||||
if (is_string($value)) {
|
||||
echo ' "' . $value . '"' . "\n";
|
||||
} elseif (is_int($value)) {
|
||||
echo ' ' . $value;
|
||||
echo ' ' . (string)$value;
|
||||
|
||||
$bit_flag_lookups = [
|
||||
'CURLOPT_HTTPAUTH' => 'CURLAUTH_',
|
||||
|
||||
@@ -111,7 +111,7 @@ class MultiCurl extends BaseCurl
|
||||
// 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 @@ class MultiCurl extends BaseCurl
|
||||
$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;
|
||||
|
||||
@@ -3186,24 +3186,14 @@ class PHPCurlClassTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertNotEmpty($cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
* @expectedException \PHPUnit\Framework\Error\Warning
|
||||
*/
|
||||
public function testRequiredOptionCurlOptReturnTransferEmitsWarning()
|
||||
{
|
||||
$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 {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
}, E_USER_WARNING);
|
||||
|
||||
@@ -3211,8 +3201,6 @@ class PHPCurlClassTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->setOpt(CURLOPT_RETURNTRANSFER, false);
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
public function testRequestMethodSuccessiveGetRequests()
|
||||
@@ -3966,7 +3954,7 @@ class PHPCurlClassTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$curl->expects($this->once())
|
||||
->method('getRawResponse')
|
||||
->will($this->returnValue('[]'));
|
||||
->willReturn('[]');
|
||||
|
||||
$this->assertEquals('[]', $curl->getRawResponse());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- TODO: Use errorLevel="1" -->
|
||||
<psalm
|
||||
ensureOverrideAttribute="false"
|
||||
errorLevel="4"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user