Test runner: Extend WP_PHPUnit_Util_Getopt instead of PHPUnit_TextUI_Command to parse incoming options.
props wawco. fixes #26725. git-svn-id: https://develop.svn.wordpress.org/trunk@26871 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
329672c70d
commit
2105b8683d
@ -95,8 +95,8 @@ require dirname( __FILE__ ) . '/utils.php';
|
|||||||
/**
|
/**
|
||||||
* A child class of the PHP test runner.
|
* A child class of the PHP test runner.
|
||||||
*
|
*
|
||||||
* Not actually used as a runner. Rather, used to access the protected
|
* Used to access the protected longOptions property, to parse the arguments
|
||||||
* longOptions property, to parse the arguments passed to the script.
|
* passed to the script.
|
||||||
*
|
*
|
||||||
* If it is determined that phpunit was called with a --group that corresponds
|
* 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
|
* to an @ticket annotation (such as `phpunit --group 12345` for bugs marked
|
||||||
@ -105,15 +105,29 @@ require dirname( __FILE__ ) . '/utils.php';
|
|||||||
* If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
|
* If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
|
||||||
* how you call phpunit has no effect.
|
* how you call phpunit has no effect.
|
||||||
*/
|
*/
|
||||||
class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
|
class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt {
|
||||||
function __construct( $argv ) {
|
protected $longOptions = array(
|
||||||
$options = PHPUnit_Util_Getopt::getopt(
|
'exclude-group=',
|
||||||
$argv,
|
'group=',
|
||||||
'd:c:hv',
|
|
||||||
array_keys( $this->longOptions )
|
|
||||||
);
|
);
|
||||||
|
function __construct( $argv ) {
|
||||||
|
array_shift( $argv );
|
||||||
|
$options = array();
|
||||||
|
while ( list( $i, $arg ) = each( $argv ) ) {
|
||||||
|
try {
|
||||||
|
if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) {
|
||||||
|
PHPUnit_Util_Getopt::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$ajax_message = true;
|
$ajax_message = true;
|
||||||
foreach ( $options[0] as $option ) {
|
foreach ( $options as $option ) {
|
||||||
switch ( $option[0] ) {
|
switch ( $option[0] ) {
|
||||||
case '--exclude-group' :
|
case '--exclude-group' :
|
||||||
$ajax_message = false;
|
$ajax_message = false;
|
||||||
@ -121,15 +135,17 @@ class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command {
|
|||||||
case '--group' :
|
case '--group' :
|
||||||
$groups = explode( ',', $option[1] );
|
$groups = explode( ',', $option[1] );
|
||||||
foreach ( $groups as $group ) {
|
foreach ( $groups as $group ) {
|
||||||
if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) )
|
if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) {
|
||||||
WP_UnitTestCase::forceTicket( $group );
|
WP_UnitTestCase::forceTicket( $group );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$ajax_message = ! in_array( 'ajax', $groups );
|
$ajax_message = ! in_array( 'ajax', $groups );
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $ajax_message )
|
if ( $ajax_message ) {
|
||||||
echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
|
echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
new WP_PHPUnit_TextUI_Command( $_SERVER['argv'] );
|
new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] );
|
||||||
|
Loading…
Reference in New Issue
Block a user