mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-30 18:24:31 +00:00
Build/Test Tools: Add support for PHPUnit 7.x.
* Create an abstract `WP_UnitTestCase_Base` class to share between PHPUnit 7.x and older versions. * Add a speed-trap loader to determine which `SpeedTrapListener` class needs to be loaded for the current PHPUnit version. * Remove unnecessary `PHPUnit\Util\Test` and `PHPUnit_Util_Getopt` inheritances. * Update Travis CI config to use PHPUnit 7.x for PHP 7.1, 7.2, and nightly PHP versions. Props jipmoors, netweb, desrosj, ayeshrajans, soulseekah, SergeyBiryukov. See #43218. git-svn-id: https://develop.svn.wordpress.org/trunk@44701 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Compatibility with PHPUnit 6+
|
||||
*/
|
||||
if ( class_exists( 'PHPUnit\Runner\Version' ) ) {
|
||||
require_once dirname( __FILE__ ) . '/phpunit6-compat.php';
|
||||
require_once dirname( __FILE__ ) . '/phpunit6/compat.php';
|
||||
}
|
||||
|
||||
if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) ) {
|
||||
@@ -118,7 +118,12 @@ require_once ABSPATH . '/wp-settings.php';
|
||||
// Delete any default posts & related data
|
||||
_delete_all_posts();
|
||||
|
||||
require dirname( __FILE__ ) . '/testcase.php';
|
||||
if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
|
||||
require dirname( __FILE__ ) . '/phpunit7/testcase.php';
|
||||
} else {
|
||||
require dirname( __FILE__ ) . '/testcase.php';
|
||||
}
|
||||
|
||||
require dirname( __FILE__ ) . '/testcase-rest-api.php';
|
||||
require dirname( __FILE__ ) . '/testcase-rest-controller.php';
|
||||
require dirname( __FILE__ ) . '/testcase-rest-post-type-controller.php';
|
||||
@@ -144,10 +149,11 @@ require dirname( __FILE__ ) . '/class-wp-fake-block-type.php';
|
||||
* If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
|
||||
* how you call phpunit has no effect.
|
||||
*/
|
||||
class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
|
||||
class WP_PHPUnit_Util_Getopt {
|
||||
protected $longOptions = array(
|
||||
'exclude-group=',
|
||||
'group=',
|
||||
'verbose=',
|
||||
);
|
||||
function __construct( $argv ) {
|
||||
array_shift( $argv );
|
||||
@@ -157,7 +163,7 @@ class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
|
||||
next( $argv );
|
||||
try {
|
||||
if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
|
||||
PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
|
||||
self::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
|
||||
}
|
||||
} catch ( PHPUnit_Framework_Exception $e ) {
|
||||
// Enforcing recognized arguments or correctly formed arguments is
|
||||
@@ -208,5 +214,68 @@ class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from https://raw.githubusercontent.com/sebastianbergmann/phpunit/6.5.7/src/Util/Getopt.php
|
||||
*
|
||||
* @param $arg
|
||||
* @param $long_options
|
||||
* @param $opts
|
||||
* @param $args
|
||||
*/
|
||||
protected static function parseLongOption( $arg, $long_options, &$opts, &$args ) {
|
||||
$count = count( $long_options );
|
||||
$list = explode( '=', $arg );
|
||||
$opt = $list[0];
|
||||
$opt_arg = null;
|
||||
|
||||
if ( count( $list ) > 1 ) {
|
||||
$opt_arg = $list[1];
|
||||
}
|
||||
|
||||
$opt_len = strlen( $opt );
|
||||
|
||||
for ( $i = 0; $i < $count; $i++ ) {
|
||||
$long_opt = $long_options[ $i ];
|
||||
$opt_start = substr( $long_opt, 0, $opt_len );
|
||||
|
||||
if ( $opt_start != $opt ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$opt_rest = substr( $long_opt, $opt_len );
|
||||
|
||||
if ( $opt_rest != '' && $opt[0] != '=' && $i + 1 < $count &&
|
||||
$opt == substr( $long_options[ $i + 1 ], 0, $opt_len ) ) {
|
||||
throw new Exception(
|
||||
"option --$opt is ambiguous"
|
||||
);
|
||||
}
|
||||
|
||||
if ( substr( $long_opt, -1 ) == '=' ) {
|
||||
if ( substr( $long_opt, -2 ) != '==' ) {
|
||||
if ( ! strlen( $opt_arg ) ) {
|
||||
if ( false === $opt_arg = current( $args ) ) {
|
||||
throw new Exception(
|
||||
"option --$opt requires an argument"
|
||||
);
|
||||
}
|
||||
next( $args );
|
||||
}
|
||||
}
|
||||
} elseif ( $opt_arg ) {
|
||||
throw new Exception(
|
||||
"option --$opt doesn't allow an argument"
|
||||
);
|
||||
}
|
||||
|
||||
$full_option = '--' . preg_replace( '/={1,2}$/', '', $long_opt );
|
||||
$opts[] = array( $full_option, $opt_arg );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception( "unrecognized option --$opt" );
|
||||
}
|
||||
}
|
||||
new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
|
||||
|
||||
Reference in New Issue
Block a user