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..5014b42 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() @@ -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(); 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 9a2d4f3..bb6f0cf 100755 --- a/tests/ci.sh +++ b/tests/ci.sh @@ -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") 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 d1e3b8d..d3745cd 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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") 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') {