Skip to content

Commit

Permalink
lmc-eu#12 possibility to run just some test cases filtered by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zverina committed Jun 3, 2015
1 parent 1f505c0 commit 7965ec6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 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 test cases 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
10 changes: 9 additions & 1 deletion src/Process/ProcessSetCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ 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) {
$this->output->writeln('Filtering testcases:');
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 test cases 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 7965ec6

Please sign in to comment.