Build/Test Tools: Fix PHP 5.2 compatibility for grandchild methods which expect exceptions to be raised.

This is due to `is_callable( 'parent::setExpectedException' )` not being supported on PHP 5.2 when the method being checked only exists on the grandparent class.

See #39822

Merges [40872] and [40873] to the 4.7 branch.


git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40876 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-06-05 10:41:02 +00:00
parent 98e9eaa3e1
commit f58726da4b
2 changed files with 21 additions and 21 deletions

View File

@ -200,25 +200,4 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
if ( !empty( $buffer ) )
$this->_last_response = $buffer;
}
/**
* PHPUnit 6+ compatibility shim.
*
* @param mixed $exception
* @param string $message
* @param int|string $code
*/
public function setExpectedException( $exception, $message = '', $code = null ) {
if ( is_callable( 'parent::setExpectedException' ) ) {
parent::setExpectedException( $exception, $message, $code );
} else {
$this->expectException( $exception );
if ( '' !== $message ) {
$this->expectExceptionMessage( $message );
}
if ( null !== $code ) {
$this->expectExceptionCode( $code );
}
}
}
}

View File

@ -415,6 +415,27 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
array_push( $this->expected_doing_it_wrong, $doing_it_wrong );
}
/**
* PHPUnit 6+ compatibility shim.
*
* @param mixed $exception
* @param string $message
* @param int|string $code
*/
public function setExpectedException( $exception, $message = '', $code = null ) {
if ( method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' ) ) {
parent::setExpectedException( $exception, $message, $code );
} else {
$this->expectException( $exception );
if ( '' !== $message ) {
$this->expectExceptionMessage( $message );
}
if ( null !== $code ) {
$this->expectExceptionCode( $code );
}
}
}
function deprecated_function_run( $function ) {
if ( ! in_array( $function, $this->caught_deprecated ) )
$this->caught_deprecated[] = $function;