diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 237af968d5..c0e9559d72 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; + /** * Executes tests. * @@ -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', @@ -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(); @@ -512,7 +519,7 @@ protected function runIncludedSuites($suites, $parent_dir) "\n\n[$namespace]: tests from $current_dir\n" ); - $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); } @@ -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)) { diff --git a/tests/cli/IncludedCest.php b/tests/cli/IncludedCest.php index e63371842e..d472f9e67f 100644 --- a/tests/cli/IncludedCest.php +++ b/tests/cli/IncludedCest.php @@ -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'); + + } + } diff --git a/tests/data/snapshots/tests/_data/Snapshot.NotAJsonSnapshot.xml b/tests/data/snapshots/tests/_data/Snapshot.NotAJsonSnapshot.xml index 3ff04027b5..2218714739 100644 --- a/tests/data/snapshots/tests/_data/Snapshot.NotAJsonSnapshot.xml +++ b/tests/data/snapshots/tests/_data/Snapshot.NotAJsonSnapshot.xml @@ -1,8 +1,8 @@ - Son - Vader - Disclaimer - I'm your father! + Tove + Jani + Reminder + Don't forget me this weekend! \ No newline at end of file