From 4ed7644250caa63a8df01e4e8cefea03b05937ef Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 16 Feb 2023 05:58:35 -0800 Subject: [PATCH] Update tests to work with PHPUnit 10 --- composer.json | 6 ++++ .../{PHPCurlClass => }/ContentRangeServer.php | 0 tests/{PHPCurlClass => }/Helper.php | 0 tests/PHPCurlClass/PHPCurlClassTest.php | 6 ++-- tests/PHPCurlClass/PHPMultiCurlClassTest.php | 2 +- tests/{PHPCurlClass => }/RangeHeader.php | 0 tests/{PHPCurlClass => }/User.php | 0 tests/ci.sh | 34 ++++++++++++++++--- tests/{PHPCurlClass => }/index.php | 0 tests/phpunit.xml | 2 +- tests/run.sh | 32 +++++++++++++---- tests/{PHPCurlClass => }/server.php | 6 ++-- 12 files changed, 68 insertions(+), 20 deletions(-) rename tests/{PHPCurlClass => }/ContentRangeServer.php (100%) rename tests/{PHPCurlClass => }/Helper.php (100%) rename tests/{PHPCurlClass => }/RangeHeader.php (100%) rename tests/{PHPCurlClass => }/User.php (100%) rename tests/{PHPCurlClass => }/index.php (100%) rename tests/{PHPCurlClass => }/server.php (99%) diff --git a/composer.json b/composer.json index 7e6f720..389876e 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,12 @@ "Curl\\": "src/Curl/" } }, + "autoload-dev": { + "files": [ + "./tests/Helper.php", + "./tests/User.php" + ] + }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true diff --git a/tests/PHPCurlClass/ContentRangeServer.php b/tests/ContentRangeServer.php similarity index 100% rename from tests/PHPCurlClass/ContentRangeServer.php rename to tests/ContentRangeServer.php diff --git a/tests/PHPCurlClass/Helper.php b/tests/Helper.php similarity index 100% rename from tests/PHPCurlClass/Helper.php rename to tests/Helper.php diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 087351a..5f36864 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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() diff --git a/tests/PHPCurlClass/PHPMultiCurlClassTest.php b/tests/PHPCurlClass/PHPMultiCurlClassTest.php index 0260e39..d4a008a 100644 --- a/tests/PHPCurlClass/PHPMultiCurlClassTest.php +++ b/tests/PHPCurlClass/PHPMultiCurlClassTest.php @@ -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; diff --git a/tests/PHPCurlClass/RangeHeader.php b/tests/RangeHeader.php similarity index 100% rename from tests/PHPCurlClass/RangeHeader.php rename to tests/RangeHeader.php diff --git a/tests/PHPCurlClass/User.php b/tests/User.php similarity index 100% rename from tests/PHPCurlClass/User.php rename to tests/User.php diff --git a/tests/ci.sh b/tests/ci.sh index ce36042..65e90c6 100755 --- a/tests/ci.sh +++ b/tests/ci.sh @@ -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") diff --git a/tests/PHPCurlClass/index.php b/tests/index.php similarity index 100% rename from tests/PHPCurlClass/index.php rename to tests/index.php diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 87b3ee1..ea668de 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,7 +1,7 @@ - ./PHPCurlClass/ + ../tests/ diff --git a/tests/run.sh b/tests/run.sh index 399cd6f..0fbd571 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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") diff --git a/tests/PHPCurlClass/server.php b/tests/server.php similarity index 99% rename from tests/PHPCurlClass/server.php rename to tests/server.php index 85bf66f..4f1443a 100644 --- a/tests/PHPCurlClass/server.php +++ b/tests/server.php @@ -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') {