@@ -78,7 +78,18 @@ function (&$item) {
7878 'Clean language files from unused language strings. Detecting which strings are truly in use may ' .
7979 'not always correctly work. Use with caution. ' );
8080
81- $ options ->registerCommand ('test ' , 'Run the unit tests for this extension. ' );
81+ $ options ->registerCommand (
82+ 'test ' ,
83+ 'Run the unit tests for this extension. (calls phpunit using the proper config and group) '
84+ );
85+ $ options ->registerOption (
86+ 'filter ' ,
87+ 'Filter tests to run by a given string. (passed to phpunit) ' ,
88+ null ,
89+ true ,
90+ 'test '
91+ );
92+ $ options ->registerArgument ('files... ' , 'The test files to run. Defaults to all. ' , false , 'test ' );
8293
8394 $ options ->registerCommand ('check ' , 'Check for code style violations. ' );
8495 $ options ->registerArgument ('files... ' , 'The files to check. Defaults to the whole extension. ' , false , 'check ' );
@@ -121,7 +132,8 @@ protected function main(Options $options)
121132 case 'cleanLang ' :
122133 return $ this ->cmdCleanLang ();
123134 case 'test ' :
124- return $ this ->cmdTest ();
135+ $ filter = $ options ->getOpt ('filter ' );
136+ return $ this ->cmdTest ($ filter , $ args );
125137 case 'check ' :
126138 return $ this ->cmdCheck ($ args );
127139 case 'fix ' :
@@ -444,9 +456,13 @@ protected function cmdCleanLang()
444456 }
445457
446458 /**
459+ * Run the unit tests for this extension
460+ *
461+ * @param string $filter Optional filter string for phpunit
462+ * @param string[] $args Additional arguments to pass to phpunit (files)
447463 * @return int
448464 */
449- protected function cmdTest ()
465+ protected function cmdTest ($ filter = '' , $ args = [] )
450466 {
451467 $ dir = fullpath (getcwd ());
452468 [$ base , $ type ] = $ this ->getTypedNameFromDir ($ dir );
@@ -457,14 +473,26 @@ protected function cmdTest()
457473 $ colors = 'never ' ;
458474 }
459475
460- $ args = [
461- fullpath (__DIR__ . '/../../../_test/vendor/bin/phpunit ' ),
476+ $ bin = fullpath (__DIR__ . '/../../../_test/vendor/bin/phpunit ' );;
477+ if (!file_exists ($ bin )) {
478+ $ this ->error ('Testing framework not found. Please run "composer install" in the _test/ directory first. ' );
479+ return 1 ;
480+ }
481+
482+ $ runArgs = [
483+ $ bin ,
462484 '--verbose ' ,
463485 "--colors= $ colors " ,
464486 '--configuration ' , fullpath (__DIR__ . '/../../../_test/phpunit.xml ' ),
465487 '--group ' , $ type . '_ ' . $ base ,
466488 ];
467- $ cmd = join (' ' , array_map ('escapeshellarg ' , $ args ));
489+ if ($ filter ) {
490+ $ runArgs [] = '--filter ' ;
491+ $ runArgs [] = $ filter ;
492+ }
493+
494+ $ runArgs = array_merge ($ runArgs , $ args );
495+ $ cmd = join (' ' , array_map ('escapeshellarg ' , $ runArgs ));
468496 $ this ->info ("Running $ cmd " );
469497
470498 $ result = 0 ;
@@ -527,7 +555,7 @@ protected function cmdFix($files = [])
527555
528556 $ result = 0 ;
529557 passthru ($ cmd , $ result );
530- if ($ result !== 0 ) return $ result ;
558+ if ($ result !== 0 ) return $ result ;
531559
532560 // now run phpcbf to clean up code style
533561 $ args = [
0 commit comments