summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/includes/bootstrap.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/bootstrap.php')
-rw-r--r--tests/phpunit/includes/bootstrap.php77
1 files changed, 73 insertions, 4 deletions
diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php
index 35ab16ca04..427e5d8289 100644
--- a/tests/phpunit/includes/bootstrap.php
+++ b/tests/phpunit/includes/bootstrap.php
@@ -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'] );