Skip to content

Commit

Permalink
Allow including suites by name (opposite of --skip)
Browse files Browse the repository at this point in the history
Fix: #6434
  • Loading branch information
calvinalkan committed Apr 18, 2022
1 parent 2585340 commit 488137f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/Codeception/Command/Run.php
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


/**
* Executes tests.
*
Expand Down Expand Up @@ -202,6 +203,12 @@ protected function configure()
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Skip selected suites'
),
new InputOption(
'include-suite',
'i',
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Include only the given suites by name. Useful for multi-application setups'
),
new InputOption(
'skip-group',
'x',
Expand Down Expand Up @@ -406,7 +413,7 @@ public function execute(InputInterface $input, OutputInterface $output)
// Run all tests of given suite or all suites
if (!$test) {
$suites = $suite ? explode(',', $suite) : Configuration::suites();
$this->executed = $this->runSuites($suites, $this->options['skip']);
$this->executed = $this->runSuites($suites, $this->options['skip'], $this->options['include-suite']);

if (!empty($config['include']) and !$suite) {
$current_dir = Configuration::projectDir();
Expand Down Expand Up @@ -512,7 +519,7 @@ protected function runIncludedSuites($suites, $parent_dir)
"\n<fg=white;bg=magenta>\n[$namespace]: tests from $current_dir\n</fg=white;bg=magenta>"
);

$this->executed += $this->runSuites($suites, $this->options['skip']);
$this->executed += $this->runSuites($suites, $this->options['skip'], $this->options['include-suite']);
if (!empty($config['include'])) {
$this->runIncludedSuites($config['include'], $current_dir);
}
Expand All @@ -532,8 +539,13 @@ protected function currentNamespace()
return $config['namespace'];
}

protected function runSuites($suites, $skippedSuites = [])
protected function runSuites($suites, $skippedSuites = [], $include_only = [])
{

if([] != $include_only) {
$suites = array_intersect($suites, $include_only);
}

$executed = 0;
foreach ($suites as $suite) {
if (in_array($suite, $skippedSuites)) {
Expand Down
41 changes: 41 additions & 0 deletions tests/cli/IncludedCest.php
Expand Up @@ -205,4 +205,45 @@ public function includedSuitesAreNotRunTwice (CliGuy $I) {
$I->seeInShellOutput('2 tests');
$I->dontSeeInShellOutput('4 tests');
}

/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function suitesForMultipleIncludedPackagesCanBeFilteredByName(\CliGuy $I)
{
$I->executeCommand('run --include-suite functional');

// only functional tests are run
$I->seeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('Jazz\Pianist.functional');
$I->seeInShellOutput('Shire.functional Tests');

// unit suites are not run
$I->dontSeeInShellOutput('Jazz.unit Tests');


$I->executeCommand('run -i functional');

// only functional tests are run
$I->seeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('Jazz\Pianist.functional');
$I->seeInShellOutput('Shire.functional Tests');

// unit suites are not run
$I->dontSeeInShellOutput('Jazz.unit Tests');


$I->executeCommand('run -i functional -i unit');

// only functional tests are run
$I->seeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('Jazz\Pianist.functional');
$I->seeInShellOutput('Shire.functional Tests');

// unit suites are run now
$I->seeInShellOutput('Jazz.unit Tests');

}

}
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema>
<note>
<to>Son</to>
<from>Vader</from>
<heading>Disclaimer</heading>
<body>I'm your father!</body>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

0 comments on commit 488137f

Please sign in to comment.