From 46e0ca0c8147d744bb9b79bb4d778640d2e0ddca Mon Sep 17 00:00:00 2001 From: Dengke Tang <815825145@qq.com> Date: Thu, 9 Mar 2023 16:44:10 -0800 Subject: [PATCH] support cross version phpunit (#92) --- .github/workflows/ci.yml | 2 ++ .gitignore | 1 + composer.json | 6 ++---- dev-scripts/cleanup_build.py | 1 + ext/signing.c | 4 ++-- tests/{000_CoreTest.php => CoreTest.php} | 5 +++-- tests/CrcTest.php | 2 +- tests/ErrorTest.php | 3 ++- tests/common.inc | 20 ++++++++------------ 9 files changed, 22 insertions(+), 22 deletions(-) rename tests/{000_CoreTest.php => CoreTest.php} (87%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4586e22..3d0cba6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,8 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" + - "8.2" steps: - name: Setup PHP with Xdebug uses: shivammathur/setup-php@v2 diff --git a/.gitignore b/.gitignore index f7413f5..1eefe24 100644 --- a/.gitignore +++ b/.gitignore @@ -207,6 +207,7 @@ src/*.so src/*.dylib src/*.dll /x64/ +awscrt.dep # ignoring output of package.xml as it needs to be generated from ./prepare_release.sh in each publishing package.xml diff --git a/composer.json b/composer.json index 37f8193..387721e 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,13 @@ "email": "aws-sdk-common-runtime@amazon.com" } ], - "config": { - "platform": {"php": "7.4"} - }, "minimum-stability": "alpha", "require": { "php": ">=5.5" }, "require-dev": { - "phpunit/phpunit":"^4.8.35|^5.6.3" + "phpunit/phpunit":"^4.8.35||^5.6.3||^9.5", + "yoast/phpunit-polyfills": "^1.0" }, "autoload": { "classmap": [ diff --git a/dev-scripts/cleanup_build.py b/dev-scripts/cleanup_build.py index 6df535c..cc10372 100644 --- a/dev-scripts/cleanup_build.py +++ b/dev-scripts/cleanup_build.py @@ -38,6 +38,7 @@ FILES_TO_REMOVE = [ 'mkinstalldirs', 'run-tests.php', 'awscrt.la', + 'awscrt.dep', 'composer.lock', 'ext/awscrt.stub.php', 'acinclude.m4', diff --git a/ext/signing.c b/ext/signing.c index 69da25a..4e629d4 100644 --- a/ext/signing.c +++ b/ext/signing.c @@ -311,9 +311,9 @@ PHP_FUNCTION(aws_crt_sign_request_aws) { zend_ulong php_signable = 0; zend_ulong php_signing_config = 0; zval *php_on_complete = 0; - zend_ulong php_user_data = 0; + zval *php_user_data = 0; - aws_php_parse_parameters("llzl", &php_signable, &php_signing_config, &php_on_complete, &php_user_data); + aws_php_parse_parameters("llzz", &php_signable, &php_signing_config, &php_on_complete, &php_user_data); aws_crt_signable *signable = (void *)php_signable; aws_crt_signing_config_aws *signing_config = (void *)php_signing_config; diff --git a/tests/000_CoreTest.php b/tests/CoreTest.php similarity index 87% rename from tests/000_CoreTest.php rename to tests/CoreTest.php index e9e068a..24586c1 100644 --- a/tests/000_CoreTest.php +++ b/tests/CoreTest.php @@ -4,11 +4,12 @@ * SPDX-License-Identifier: Apache-2.0. */ use AWS\CRT\CRT; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; require_once('common.inc'); // This intentionally does not inherit from CrtTestCase because it needs a clean-room environment -final class CoreTest extends PHPUnit_Framework_TestCase { +final class CoreTest extends TestCase { // The CRT should always be available in this test suite public function testIsAvailable() { @@ -19,4 +20,4 @@ final class CoreTest extends PHPUnit_Framework_TestCase { public function testIsLoaded() { $this->assertTrue(!CRT::isLoaded()); } -} \ No newline at end of file +} diff --git a/tests/CrcTest.php b/tests/CrcTest.php index 56c5038..5c4b5af 100644 --- a/tests/CrcTest.php +++ b/tests/CrcTest.php @@ -86,5 +86,5 @@ final class CrcTest extends CrtTestCase { $expected = 0x14298C12; $this->assertEquals($output, $expected); } - + } diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index e84d1ed..9f1d820 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0. */ use AWS\CRT\CRT; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; -final class ErrorTest extends PHPUnit_Framework_TestCase { +final class ErrorTest extends TestCase { public function testNoInitialError() { $this->assertEquals(0, CRT::last_error()); diff --git a/tests/common.inc b/tests/common.inc index 1a7e8f8..40df82f 100644 --- a/tests/common.inc +++ b/tests/common.inc @@ -4,31 +4,27 @@ * SPDX-License-Identifier: Apache-2.0. */ use AWS\CRT\CRT as CRT; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; ini_set("memory_limit", "512M"); -abstract class CrtTestCase extends PHPUnit_Framework_TestCase { +abstract class CrtTestCase extends TestCase { private static $crt = null; - public static function setUpBeforeClass() { + public static function set_up_before_class() { + parent::set_up_before_class(); self::$crt = new CRT(); } - public static function tearDownAfterClass() { + public static function tear_down_after_class() { self::$crt = null; + parent::tear_down_after_class(); } // Ensure that after every test there are no errors in the CRT itself - protected function assertPostConditions() { + protected function assert_post_conditions() { if (CRT::last_error()) { $this->fail("Test left an error on the stack: " . CRT::error_name(CRT::last_error())); } - } - - // Shim missing calls in older versions of PHPUnit - public function __call($name, $arguments) { - // shim expectException -> setExpectedException for PHPUnit 4.8.x - if ($name == 'expectException') { - $this->setExpectedException($arguments[0]); - } + parent::assert_post_conditions(); } }