Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to run just some tests in a test case #19

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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