support cross version phpunit (#92)

This commit is contained in:
Dengke Tang
2023-03-09 16:44:10 -08:00
committed by GitHub
parent 5334110e8b
commit 46e0ca0c81
9 changed files with 22 additions and 22 deletions
@@ -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());
}
}
}
+1 -1
View File
@@ -86,5 +86,5 @@ final class CrcTest extends CrtTestCase {
$expected = 0x14298C12;
$this->assertEquals($output, $expected);
}
}
+2 -1
View File
@@ -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());
+8 -12
View File
@@ -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();
}
}