Skip to content

Commit

Permalink
CakeTestCase の phpunit 9 対応
Browse files Browse the repository at this point in the history
  • Loading branch information
okinaka committed Nov 16, 2022
1 parent 4935f6e commit b72e660
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions app/TestSuite/CakeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @package Cake.TestSuite
*/
abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
abstract class CakeTestCase extends PHPUnit\Framework\TestCase {

/**
* The class responsible for managing the creation, loading and removing of fixtures
Expand Down Expand Up @@ -71,11 +71,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* If no TestResult object is passed a new one will be created.
* This method is run for each test method in this class
*
* @param PHPUnit_Framework_TestResult $result The test result object
* @return PHPUnit_Framework_TestResult
* @param PHPUnit/Framework/TestResult $result The test result object
* @return PHPUnit/Framework/TestResult
* @throws InvalidArgumentException
*/
public function run(PHPUnit_Framework_TestResult $result = null) {
public function run(?PHPUnit\Framework\TestResult $result = null): PHPUnit\Framework\TestResult {
$level = ob_get_level();

if (!empty($this->fixtureManager)) {
Expand Down Expand Up @@ -133,7 +133,7 @@ public function skipIf($shouldSkip, $message = '') {
*
* @return void
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

if (empty($this->_configure)) {
Expand All @@ -152,7 +152,7 @@ public function setUp() {
*
* @return void
*/
public function tearDown() {
public function tearDown(): void {
parent::tearDown();
App::build($this->_pathRestore, App::RESET);
if (class_exists('ClassRegistry', false)) {
Expand Down Expand Up @@ -185,7 +185,7 @@ public static function date($format = 'Y-m-d H:i:s') {
*
* @return void
*/
protected function assertPreConditions() {
protected function assertPreConditions(): void {
parent::assertPreConditions();
$this->startTest($this->getName());
}
Expand All @@ -195,7 +195,7 @@ protected function assertPreConditions() {
*
* @return void
*/
protected function assertPostConditions() {
protected function assertPostConditions(): void {
parent::assertPostConditions();
$this->endTest($this->getName());
}
Expand Down Expand Up @@ -324,7 +324,7 @@ public function assertTextEndsNotWith($suffix, $string, $message = '') {
public function assertTextContains($needle, $haystack, $message = '', $ignoreCase = false) {
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
$haystack = str_replace(array("\r\n", "\r"), "\n", $haystack);
return $this->assertContains($needle, $haystack, $message, $ignoreCase);
return $this->assertStringContainsString($needle, $haystack, $message, $ignoreCase);
}

/**
Expand All @@ -340,7 +340,7 @@ public function assertTextContains($needle, $haystack, $message = '', $ignoreCas
public function assertTextNotContains($needle, $haystack, $message = '', $ignoreCase = false) {
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
$haystack = str_replace(array("\r\n", "\r"), "\n", $haystack);
return $this->assertNotContains($needle, $haystack, $message, $ignoreCase);
return $this->assertStringNotContainsString($needle, $haystack, $message, $ignoreCase);
}

/**
Expand Down Expand Up @@ -557,7 +557,7 @@ protected function _assertAttributes($assertions, $string) {
* @return void
*/
protected static function assertEqual($result, $expected, $message = '') {
return static::assertEquals($expected, $result, $message);
static::assertEquals($expected, $result, $message);
}

/**
Expand All @@ -570,7 +570,7 @@ protected static function assertEqual($result, $expected, $message = '') {
* @return void
*/
protected static function assertNotEqual($result, $expected, $message = '') {
return static::assertNotEquals($expected, $result, $message);
static::assertNotEquals($expected, $result, $message);
}

/**
Expand All @@ -583,7 +583,7 @@ protected static function assertNotEqual($result, $expected, $message = '') {
* @return void
*/
protected static function assertPattern($pattern, $string, $message = '') {
return static::assertRegExp($pattern, $string, $message);
static::assertRegExp($pattern, $string, $message);
}

/**
Expand All @@ -596,7 +596,7 @@ protected static function assertPattern($pattern, $string, $message = '') {
* @return void
*/
protected static function assertIdentical($actual, $expected, $message = '') {
return static::assertSame($expected, $actual, $message);
static::assertSame($expected, $actual, $message);
}

/**
Expand All @@ -609,7 +609,7 @@ protected static function assertIdentical($actual, $expected, $message = '') {
* @return void
*/
protected static function assertNotIdentical($actual, $expected, $message = '') {
return static::assertNotSame($expected, $actual, $message);
static::assertNotSame($expected, $actual, $message);
}

/**
Expand All @@ -622,7 +622,7 @@ protected static function assertNotIdentical($actual, $expected, $message = '')
* @return void
*/
protected static function assertNoPattern($pattern, $string, $message = '') {
return static::assertNotRegExp($pattern, $string, $message);
static::assertNotRegExp($pattern, $string, $message);
}

/**
Expand All @@ -642,7 +642,7 @@ protected function assertNoErrors() {
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
* @return void
*/
protected function expectError($expected = false, $message = '') {
public function expectError($expected = false, $message = ''): void {
if (!$expected) {
$expected = 'Exception';
}
Expand All @@ -657,8 +657,8 @@ protected function expectError($expected = false, $message = '') {
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0.
* @return void
*/
public function expectException($name = 'Exception', $message = '') {
$this->setExpectedException($name, $message);
public function expectException($name = 'Exception', $message = ''): void {
parent::expectException($name);
}

/**
Expand All @@ -670,8 +670,8 @@ public function expectException($name = 'Exception', $message = '') {
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
* @return void
*/
protected static function assertReference(&$first, &$second, $message = '') {
return static::assertSame($first, $second, $message);
protected static function assertReference(&$first, &$second, $message = ''): void {
static::assertSame($first, $second, $message);
}

/**
Expand All @@ -683,8 +683,8 @@ protected static function assertReference(&$first, &$second, $message = '') {
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
* @return void
*/
protected static function assertIsA($object, $type, $message = '') {
return static::assertInstanceOf($type, $object, $message);
protected static function assertIsA($object, $type, $message = ''): void {
static::assertInstanceOf($type, $object, $message);
}

/**
Expand All @@ -696,10 +696,10 @@ protected static function assertIsA($object, $type, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
protected static function assertWithinMargin($result, $expected, $margin, $message = '') {
protected static function assertWithinMargin($result, $expected, $margin, $message = ''): void {
$upper = $result + $margin;
$lower = $result - $margin;
return static::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
static::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
}

/**
Expand Down Expand Up @@ -816,12 +816,6 @@ public function getMock(
$callOriginalMethods = false,
$proxyTarget = null
) {
$phpUnitVersion = PHPUnit_Runner_Version::id();
if (version_compare($phpUnitVersion, '5.7.0', '<')) {
return parent::getMock($originalClassName, $methods, $arguments,
$mockClassName, $callOriginalConstructor, $callOriginalClone,
$callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
}
if ($cloneArguments) {
throw new InvalidArgumentException('$cloneArguments parameter is not supported');
}
Expand Down

0 comments on commit b72e660

Please sign in to comment.