WordPress.org

Make WordPress Core

Changeset 26871


Ignore:
Timestamp:
12/27/2013 03:07:07 PM (6 years ago)
Author:
nacin
Message:

Test runner: Extend WP_PHPUnit_Util_Getopt instead of PHPUnit_TextUI_Command to parse incoming options.

props wawco.
fixes #26725.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r25415 r26871  
    9696 * A child class of the PHP test runner.
    9797 *
    98  * Not actually used as a runner. Rather, used to access the protected
    99  * longOptions property, to parse the arguments passed to the script.
     98 * Used to access the protected longOptions property, to parse the arguments
     99 * passed to the script.
    100100 *
    101101 * If it is determined that phpunit was called with a --group that corresponds
     
    106106 * how you call phpunit has no effect.
    107107 */
    108 class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
     108class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
     109    protected $longOptions = array(
     110      'exclude-group=',
     111      'group=',
     112    );
    109113    function __construct( $argv ) {
    110         $options = PHPUnit_Util_Getopt::getopt(
    111             $argv,
    112             'd:c:hv',
    113             array_keys( $this->longOptions )
    114         );
     114        array_shift( $argv );
     115        $options = array();
     116        while ( list( $i, $arg ) = each( $argv ) ) {
     117            try {
     118                if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
     119                    PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );
     120                }
     121            }
     122            catch ( PHPUnit_Framework_Exception $e ) {
     123                // Enforcing recognized arguments or correctly formed arguments is
     124                // not really the concern here.
     125                continue;
     126            }
     127        }
     128
    115129        $ajax_message = true;
    116         foreach ( $options[0] as $option ) {
     130        foreach ( $options as $option ) {
    117131            switch ( $option[0] ) {
    118132                case '--exclude-group' :
     
    122136                    $groups = explode( ',', $option[1] );
    123137                    foreach ( $groups as $group ) {
    124                         if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) )
     138                        if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) {
    125139                            WP_UnitTestCase::forceTicket( $group );
     140                        }
    126141                    }
    127142                    $ajax_message = ! in_array( 'ajax', $groups );
     
    129144            }
    130145        }
    131         if ( $ajax_message )
     146        if ( $ajax_message ) {
    132147            echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
     148        }
    133149    }
    134150}
    135 new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] );
     151new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
Note: See TracChangeset for help on using the changeset viewer.