Changeset 44715
- Timestamp:
- 01/30/2019 12:53:52 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/bootstrap.php
r44707 r44715 138 138 139 139 /** 140 * A child class of the PHP test runner. 141 * 142 * Used to access the protected longOptions property, to parse the arguments 143 * passed to the script. 140 * A class to handle additional command line arguments passed to the script. 144 141 * 145 142 * If it is determined that phpunit was called with a --group that corresponds … … 151 148 */ 152 149 class WP_PHPUnit_Util_Getopt { 153 protected $longOptions = array( 154 'exclude-group=', 155 'group=', 156 ); 150 157 151 function __construct( $argv ) { 158 array_shift( $argv );159 $options = array();160 while ( current( $argv ) ) {161 $arg = current( $argv );162 next( $argv );163 try {164 if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {165 self::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv );166 }167 } catch ( PHPUnit_Framework_Exception $e ) {168 // Enforcing recognized arguments or correctly formed arguments is169 // not really the concern here.170 continue;171 }172 }173 174 152 $skipped_groups = array( 175 153 'ajax' => true, … … 178 156 ); 179 157 180 foreach ( $options as $option ) { 181 switch ( $option[0] ) { 158 while ( current( $argv ) ) { 159 $option = current( $argv ); 160 $value = next( $argv ); 161 162 switch ( $option ) { 182 163 case '--exclude-group': 183 164 foreach ( $skipped_groups as $group_name => $skipped ) { … … 186 167 continue 2; 187 168 case '--group': 188 $groups = explode( ',', $ option[1]);169 $groups = explode( ',', $value ); 189 170 foreach ( $groups as $group ) { 190 171 if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) { … … 215 196 } 216 197 217 /**218 * Copied from https://raw.githubusercontent.com/sebastianbergmann/phpunit/6.5.7/src/Util/Getopt.php219 *220 * @param $arg221 * @param $long_options222 * @param $opts223 * @param $args224 */225 protected static function parseLongOption( $arg, $long_options, &$opts, &$args ) {226 $count = count( $long_options );227 $list = explode( '=', $arg );228 $opt = $list[0];229 $opt_arg = null;230 231 if ( count( $list ) > 1 ) {232 $opt_arg = $list[1];233 }234 235 $opt_len = strlen( $opt );236 237 for ( $i = 0; $i < $count; $i++ ) {238 $long_opt = $long_options[ $i ];239 $opt_start = substr( $long_opt, 0, $opt_len );240 241 if ( $opt_start != $opt ) {242 continue;243 }244 245 $opt_rest = substr( $long_opt, $opt_len );246 247 if ( $opt_rest != '' && $opt[0] != '=' && $i + 1 < $count &&248 $opt == substr( $long_options[ $i + 1 ], 0, $opt_len ) ) {249 throw new Exception(250 "option --$opt is ambiguous"251 );252 }253 254 if ( substr( $long_opt, -1 ) == '=' ) {255 if ( substr( $long_opt, -2 ) != '==' ) {256 if ( ! strlen( $opt_arg ) ) {257 if ( false === $opt_arg = current( $args ) ) {258 throw new Exception(259 "option --$opt requires an argument"260 );261 }262 next( $args );263 }264 }265 } elseif ( $opt_arg ) {266 throw new Exception(267 "option --$opt doesn't allow an argument"268 );269 }270 271 $full_option = '--' . preg_replace( '/={1,2}$/', '', $long_opt );272 $opts[] = array( $full_option, $opt_arg );273 274 return;275 }276 }277 198 } 278 199 new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
Note: See TracChangeset
for help on using the changeset viewer.