Merge pull request #766 from zachborboa/master

Update ci to work with PHPUnit 10
This commit is contained in:
Zach Borboa
2023-02-18 05:36:35 -08:00
committed by GitHub
12 changed files with 106 additions and 24 deletions
+6
View File
@@ -34,6 +34,12 @@
"Curl\\": "src/Curl/"
}
},
"autoload-dev": {
"files": [
"./tests/Helper.php",
"./tests/User.php"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
+21 -3
View File
@@ -8,7 +8,7 @@ use Curl\Url;
use Helper\Test;
use Helper\User;
class CurlTest extends \PHPUnit\Framework\TestCase
class PHPCurlClassTest extends \PHPUnit\Framework\TestCase
{
private $skip_slow_tests;
@@ -98,8 +98,8 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$test = new Test();
$user_agent = $test->server('server', 'GET', ['key' => 'HTTP_USER_AGENT']);
$this->assertRegExp('/' . $php_version . '/', $user_agent);
$this->assertRegExp('/' . $curl_version . '/', $user_agent);
$this->assertMatchesRegularExpression('/' . $php_version . '/', $user_agent);
$this->assertMatchesRegularExpression('/' . $curl_version . '/', $user_agent);
}
public function testGet()
@@ -3092,6 +3092,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
}
/**
* @requires PHPUnit < 10
* @expectedException \PHPUnit\Framework\Error\Warning
*/
public function testRequiredOptionCurlOptReturnTransferEmitsWarning()
@@ -3102,6 +3103,23 @@ class CurlTest extends \PHPUnit\Framework\TestCase
$curl->setOpt(CURLOPT_RETURNTRANSFER, false);
}
/**
* @requires PHPUnit >= 10
*/
public function testRequiredOptionCurlOptReturnTransferEmitsWarningPHPUnit10Plus()
{
set_error_handler(static function (int $errno, string $errstr): never {
throw new \Exception($errstr, $errno);
}, E_USER_WARNING);
$this->expectExceptionMessage('CURLOPT_RETURNTRANSFER is a required option');
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, false);
restore_error_handler();
}
public function testRequestMethodSuccessiveGetRequests()
{
$test = new Test();
+1 -1
View File
@@ -6,7 +6,7 @@ use Curl\Curl;
use Curl\MultiCurl;
use Helper\Test;
class MultiCurlTest extends \PHPUnit\Framework\TestCase
class PHPMultiCurlClassTest extends \PHPUnit\Framework\TestCase
{
private $skip_slow_tests;
+39 -7
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
remove_expectWarning() {
# Fix "Call to undefined method CurlTest\CurlTest::expectWarning()".
sed -i'' -e"/->expectWarning(/d" "./PHPCurlClass/PHP"*
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e "/->expectWarning(/d" "./PHPCurlClass/PHP"*
}
replace_assertStringContainsString() {
@@ -8,19 +10,38 @@ replace_assertStringContainsString() {
# +->assertContains(
find='->assertStringContainsString('
replace='->assertContains('
sed -i'' -e"s/${find}/${replace}/" "./PHPCurlClass/PHP"*
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
}
replace_assertMatchesRegularExpression() {
# -->assertMatchesRegularExpression(
# +->assertRegExp(
find='->assertMatchesRegularExpression('
replace='->assertRegExp('
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e"s/${find}/${replace}/" "./PHPCurlClass/PHP"*
}
phpunit_v6_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
replace_assertStringContainsString
}
phpunit_v7_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v8_1_shim() {
phpunit_v8_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v9_shim() {
replace_assertMatchesRegularExpression
}
phpunit_v10_shim() {
remove_expectWarning
}
@@ -59,7 +80,7 @@ for i in $(seq 0 $(("${server_count}" - 1))); do
port=8000
(( port += $i ))
php -S "127.0.0.1:${port}" -t PHPCurlClass/ &> /dev/null &
php -S "127.0.0.1:${port}" server.php &> /dev/null &
pids["${i}"]="${!}"
done
@@ -77,12 +98,22 @@ fi
phpunit_version="$("${phpunit_to_use}" --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
echo "phpunit_version: ${phpunit_version}"
extra_args="${@}"
if [[ "${phpunit_version}" == "6.5."* ]]; then
phpunit_v6_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "7.5."* ]]; then
phpunit_v7_5_shim
elif [[ "${phpunit_version}" == "8.1."* ]]; then
phpunit_v8_1_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "8.5."* ]]; then
phpunit_v8_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "9."* ]]; then
phpunit_v9_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
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}"
fi
if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then
@@ -92,7 +123,8 @@ fi
# Run tests.
"${phpunit_to_use}" --version
"${phpunit_to_use}" \
--configuration "phpunit.xml"
--configuration "phpunit.xml" \
${phpunit_args}
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpunit command failed"
errors+=("phpunit command failed")
+1 -1
View File
@@ -1,7 +1,7 @@
<phpunit bootstrap="../vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="PHPCurlClass">
<directory suffix=".php">./PHPCurlClass/</directory>
<directory suffix="Test.php">../tests/</directory>
</testsuite>
</testsuites>
<php>
+36 -8
View File
@@ -2,7 +2,7 @@
remove_expectWarning() {
# Fix "Call to undefined method CurlTest\CurlTest::expectWarning()".
sed -i'' -e"/->expectWarning(/d" "./PHPCurlClass/PHP"*
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e "/->expectWarning(/d" "./PHPCurlClass/PHP"*
}
replace_assertStringContainsString() {
@@ -10,19 +10,38 @@ replace_assertStringContainsString() {
# +->assertContains(
find='->assertStringContainsString('
replace='->assertContains('
sed -i'' -e"s/${find}/${replace}/" "./PHPCurlClass/PHP"*
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
}
replace_assertMatchesRegularExpression() {
# -->assertMatchesRegularExpression(
# +->assertRegExp(
find='->assertMatchesRegularExpression('
replace='->assertRegExp('
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e"s/${find}/${replace}/" "./PHPCurlClass/PHP"*
}
phpunit_v6_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
replace_assertStringContainsString
}
phpunit_v7_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v8_1_shim() {
phpunit_v8_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v9_shim() {
replace_assertMatchesRegularExpression
}
phpunit_v10_shim() {
remove_expectWarning
}
@@ -58,7 +77,7 @@ for i in $(seq 0 $(("${server_count}" - 1))); do
port=8000
(( port += $i ))
php -S "127.0.0.1:${port}" -t PHPCurlClass/ &> /dev/null &
php -S "127.0.0.1:${port}" server.php &> /dev/null &
pids["${i}"]="${!}"
done
@@ -76,12 +95,22 @@ fi
phpunit_version="$("${phpunit_to_use}" --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
echo "phpunit_version: ${phpunit_version}"
extra_args="${@}"
if [[ "${phpunit_version}" == "6.5."* ]]; then
phpunit_v6_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "7.5."* ]]; then
phpunit_v7_5_shim
elif [[ "${phpunit_version}" == "8.1."* ]]; then
phpunit_v8_1_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "8.5."* ]]; then
phpunit_v8_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "9."* ]]; then
phpunit_v9_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
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}"
fi
if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then
@@ -89,11 +118,10 @@ if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then
fi
# Run tests.
extra_args="${@}"
"${phpunit_to_use}" --version
"${phpunit_to_use}" \
--configuration "phpunit.xml" \
${extra_args}
${phpunit_args}
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpunit command failed"
errors+=("phpunit command failed")
@@ -11,8 +11,6 @@ require_once 'ContentRangeServer.php';
require_once 'RangeHeader.php';
require_once 'Helper.php';
use Helper\Test;
$http_raw_post_data = file_get_contents('php://input');
$_PUT = [];
$_PATCH = [];
@@ -146,12 +144,12 @@ if ($test === 'http_basic_auth') {
]);
exit;
} elseif ($test === 'post_file_path_upload') {
echo Helper\mime_type($_FILES[$key]['tmp_name']);
echo \Helper\mime_type($_FILES[$key]['tmp_name']);
exit;
} elseif ($test === 'put_file_handle') {
$tmp_filename = tempnam('/tmp', 'php-curl-class.');
file_put_contents($tmp_filename, $http_raw_post_data);
echo Helper\mime_type($tmp_filename);
echo \Helper\mime_type($tmp_filename);
unlink($tmp_filename);
exit;
} elseif ($test === 'request_method') {