=' ) ) { 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'; require dirname( __FILE__ ) . '/testcase-xmlrpc.php'; require dirname( __FILE__ ) . '/testcase-ajax.php'; require dirname( __FILE__ ) . '/testcase-canonical.php'; require dirname( __FILE__ ) . '/exceptions.php'; require dirname( __FILE__ ) . '/utils.php'; require dirname( __FILE__ ) . '/spy-rest-server.php'; require dirname( __FILE__ ) . '/class-wp-rest-test-search-handler.php'; require dirname( __FILE__ ) . '/class-wp-fake-block-type.php'; /** * A child class of the PHP test runner. * * Used to access the protected longOptions property, to parse the arguments * passed to the script. * * If it is determined that phpunit was called with a --group that corresponds * to an @ticket annotation (such as `phpunit --group 12345` for bugs marked * as #WP12345), then it is assumed that known bugs should not be skipped. * * 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 { protected $longOptions = array( 'exclude-group=', 'group=', 'verbose=', ); function __construct( $argv ) { array_shift( $argv ); $options = array(); while ( current( $argv ) ) { $arg = current( $argv ); next( $argv ); try { if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) { self::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv ); } } catch ( PHPUnit_Framework_Exception $e ) { // Enforcing recognized arguments or correctly formed arguments is // not really the concern here. continue; } } $skipped_groups = array( 'ajax' => true, 'ms-files' => true, 'external-http' => true, ); foreach ( $options as $option ) { switch ( $option[0] ) { case '--exclude-group': foreach ( $skipped_groups as $group_name => $skipped ) { $skipped_groups[ $group_name ] = false; } continue 2; case '--group': $groups = explode( ',', $option[1] ); foreach ( $groups as $group ) { if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) { WP_UnitTestCase::forceTicket( $group ); } } foreach ( $skipped_groups as $group_name => $skipped ) { if ( in_array( $group_name, $groups ) ) { $skipped_groups[ $group_name ] = false; } } continue 2; } } $skipped_groups = array_filter( $skipped_groups ); foreach ( $skipped_groups as $group_name => $skipped ) { echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL; } if ( ! isset( $skipped_groups['external-http'] ) ) { echo PHP_EOL; echo 'External HTTP skipped tests can be caused by timeouts.' . PHP_EOL; echo 'If this changeset includes changes to HTTP, make sure there are no timeouts.' . PHP_EOL; 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'] );