diff --git a/src/Console/Command/RunTestsCommand.php b/src/Console/Command/RunTestsCommand.php index 9c479d8e..fc0380ad 100644 --- a/src/Console/Command/RunTestsCommand.php +++ b/src/Console/Command/RunTestsCommand.php @@ -45,6 +45,7 @@ class RunTestsCommand extends Command const OPTION_LOGS_DIR = 'logs-dir'; const OPTION_PATTERN = 'pattern'; const OPTION_GROUP = 'group'; + const OPTION_FILTER = 'filter'; const OPTION_EXCLUDE_GROUP = 'exclude-group'; const OPTION_PUBLISH_RESULTS = 'publish-results'; @@ -121,6 +122,12 @@ protected function configure() InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Only run testcases with specified @group of this name' ) + ->addOption( + self::OPTION_FILTER, + null, + InputOption::VALUE_REQUIRED, + 'Run only tests whose name is matching this filter' + ) ->addOption( self::OPTION_EXCLUDE_GROUP, null, @@ -246,7 +253,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $processSet = $processSetCreator->createFromFiles( $files, $input->getOption(self::OPTION_GROUP), - $input->getOption(self::OPTION_EXCLUDE_GROUP) + $input->getOption(self::OPTION_EXCLUDE_GROUP), + $input->getOption(self::OPTION_FILTER) ); if (!count($processSet)) { diff --git a/src/Process/ProcessSetCreator.php b/src/Process/ProcessSetCreator.php index d0bd8a6d..cf3d2e8c 100644 --- a/src/Process/ProcessSetCreator.php +++ b/src/Process/ProcessSetCreator.php @@ -54,11 +54,12 @@ public function __construct( * @param Finder $files * @param array $groups Groups to be run * @param array $excludeGroups Groups to be excluded + * @param string $filter filter test cases by name * @return ProcessSet */ - public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null) + public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null, $filter = null) { - if ($groups || $excludeGroups) { + if ($groups || $excludeGroups || $filter) { $this->output->writeln('Filtering testcases:'); } if ($groups) { @@ -67,6 +68,9 @@ public function createFromFiles(Finder $files, array $groups = null, array $excl if ($excludeGroups) { $this->output->writeln(sprintf(' - excluding group(s): %s', implode(', ', $excludeGroups))); } + if ($filter) { + $this->output->writeln(sprintf(' - filtering tests by name: %s', $filter)); + } $processSet = $this->getProcessSet(); @@ -126,6 +130,10 @@ public function createFromFiles(Finder $files, array $groups = null, array $excl '--configuration=' . realpath(__DIR__ . '/../phpunit.xml'), ]; + if ($filter) { + $phpunitArgs[] = "--filter=" . $filter; + } + // If ANSI output is enabled, turn on colors in PHPUnit if ($this->output->isDecorated()) { $phpunitArgs[] = '--colors=always';