Skip to content

Commit

Permalink
possibility to run just some test cases filtered by name (fixes #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zverina authored and OndraM committed Jun 4, 2015
1 parent 1f505c0 commit 2e1d7e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/Console/Command/RunTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
12 changes: 10 additions & 2 deletions src/Process/ProcessSetCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 2e1d7e0

Please sign in to comment.