diff --git a/.travis.yml b/.travis.yml index f021cb017c..b629e306cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,7 +67,11 @@ before_script: # Install the specified version of PHPUnit depending on the PHP version: if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then case "$TRAVIS_PHP_VERSION" in - 7.1|7.0|hhvm|nightly) + 7.1|7.0|nightly) + echo "Using PHPUnit 6.1" + composer global require "phpunit/phpunit=6.1.*" + ;; + hhvm) echo "Using PHPUnit 5.7" composer global require "phpunit/phpunit=5.7.*" ;; diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index b462e7039b..1450736fd1 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -3,6 +3,12 @@ * Installs WordPress for running the tests and loads WordPress and the test libraries */ +/** + * Compatibility with PHPUnit 6+ + */ +if ( class_exists( 'PHPUnit\Runner\Version' ) ) { + require_once dirname( __FILE__ ) . '/phpunit6-compat.php'; +} $config_file_path = dirname( dirname( __FILE__ ) ); if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { diff --git a/tests/phpunit/includes/phpunit6-compat.php b/tests/phpunit/includes/phpunit6-compat.php new file mode 100644 index 0000000000..a5b0a9f5a8 --- /dev/null +++ b/tests/phpunit/includes/phpunit6-compat.php @@ -0,0 +1,37 @@ +=' ) ) { + + class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' ); + class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' ); + class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' ); + class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' ); + class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' ); + class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' ); + class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' ); + class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' ); + class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' ); + class_alias( 'PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState' ); + class_alias( 'PHPUnit\Util\Getopt', 'PHPUnit_Util_Getopt' ); + + class PHPUnit_Util_Test extends PHPUnit\Util\Test { + + public static function getTickets( $className, $methodName ) { + $annotations = self::parseTestMethodAnnotations( $className, $methodName ); + + $tickets = array(); + + if ( isset( $annotations['class']['ticket'] ) ) { + $tickets = $annotations['class']['ticket']; + } + + if ( isset( $annotations['method']['ticket'] ) ) { + $tickets = array_merge( $tickets, $annotations['method']['ticket'] ); + } + + return array_unique( $tickets ); + } + + } + +} diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 554de7e578..b559cf6f19 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -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 ( is_callable( 'parent::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;