Update tests to work with PHPUnit 10

This commit is contained in:
Zach Borboa
2023-02-16 05:58:35 -08:00
parent acf5443a68
commit 4ed7644250
12 changed files with 68 additions and 20 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
+3 -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()
+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;
+29 -5
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
remove_expectWarning() {
# Fix "Call to undefined method CurlTest\CurlTest::expectWarning()".
sed -i$(sed v < /dev/null 2> /dev/null || echo -n " ''") -e "/->expectWarning(/d" "./PHPCurlClass/PHP"*
@@ -21,14 +23,25 @@ replace_assertMatchesRegularExpression() {
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
}
@@ -67,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
@@ -85,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 ${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 ${extra_args}"
elif [[ "${phpunit_version}" == "8.5."* ]]; then
phpunit_v8_5_shim
phpunit_args=" --debug --verbose ${extra_args}"
elif [[ "${phpunit_version}" == "9."* ]]; then
phpunit_v9_shim
phpunit_args=" --debug --verbose ${extra_args}"
elif [[ "${phpunit_version}" == "10."* ]]; then
phpunit_v10_shim
phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings ${extra_args}"
fi
if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then
@@ -100,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>
+26 -6
View File
@@ -23,14 +23,25 @@ replace_assertMatchesRegularExpression() {
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
}
@@ -66,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
@@ -84,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 ${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 ${extra_args}"
elif [[ "${phpunit_version}" == "8.5."* ]]; then
phpunit_v8_5_shim
phpunit_args=" --debug --verbose ${extra_args}"
elif [[ "${phpunit_version}" == "9."* ]]; then
phpunit_v9_shim
phpunit_args=" --debug --verbose ${extra_args}"
elif [[ "${phpunit_version}" == "10."* ]]; then
phpunit_v10_shim
phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings ${extra_args}"
fi
if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then
@@ -97,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') {