From c53401dd68e871ce02e01cb3035348e8de26e221 Mon Sep 17 00:00:00 2001 From: Calvin Alkan Date: Sat, 13 Aug 2022 14:57:04 +0200 Subject: [PATCH] Propagate --ext and --override parameters to included test suites (#6536) * fix: fix wrong behaviour for runtime options like --ext and --override when included suites are present in config. * fix: remove dead method isRootLevelSuite in Run.php This method was never needed and should not have been introduced in 1458ddaadf14fcde38950d3014d0e2c8378d376a --- src/Codeception/Command/Run.php | 42 +++++++++++++------------- tests/cli/ExtensionsCest.php | 52 +++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 5ffaa2f9bd..d23b110983 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -3,6 +3,7 @@ use Codeception\Codecept; use Codeception\Configuration; +use Codeception\Exception\ParseException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -249,18 +250,10 @@ public function execute(InputInterface $input, OutputInterface $output) if ($this->options['bootstrap']) { Configuration::loadBootstrap($this->options['bootstrap'], getcwd()); } - - // load config + $config = $this->getGlobalConfig(); - - // update config from options - if (count($this->options['override'])) { - $config = $this->overrideConfig($this->options['override']); - } - if ($this->options['ext']) { - $config = $this->enableExtensions($this->options['ext']); - } - + $config = $this->addRuntimeOptionsToCurrentConfig($config); + if (!$this->options['colors']) { $this->options['colors'] = $config['settings']['colors']; } @@ -348,10 +341,7 @@ public function execute(InputInterface $input, OutputInterface $output) if (strpos($suite, $include) === 0) { // Use include config $config = Configuration::config($projectDir.$include); - - if (!empty($this->options['override'])) { - $config = $this->overrideConfig($this->options['override']); - } + $config = $this->addRuntimeOptionsToCurrentConfig($config); if (!isset($config['paths']['tests'])) { throw new \RuntimeException( @@ -378,7 +368,9 @@ public function execute(InputInterface $input, OutputInterface $output) // Restore main config if (!$isIncludeTest) { - $config = Configuration::config($projectDir); + $config = $this->addRuntimeOptionsToCurrentConfig( + Configuration::config($projectDir) + ); } } elseif (!empty($suite)) { $result = $this->matchSingleTest($suite, $config); @@ -747,12 +739,20 @@ private function isSuiteInMultiApplication($suite_name) } /** - * @param string $suite_name - * - * @return bool + * @return array */ - private function isRootLevelSuite($suite_name) { - return !$this->isSuiteInMultiApplication($suite_name) && ! $this->isWildcardSuiteName($suite_name); + private function addRuntimeOptionsToCurrentConfig(array $config) + { + // update config from options + if (count($this->options['override'])) { + $config = $this->overrideConfig($this->options['override']); + } + // enable extensions + if ($this->options['ext']) { + $config = $this->enableExtensions($this->options['ext']); + } + + return $config; } } diff --git a/tests/cli/ExtensionsCest.php b/tests/cli/ExtensionsCest.php index 471067c9e8..336cad0089 100644 --- a/tests/cli/ExtensionsCest.php +++ b/tests/cli/ExtensionsCest.php @@ -87,6 +87,54 @@ public function runPerSuiteExtensionsInEnvironment(CliGuy $I) $I->seeInShellOutput('Config1: black_value'); $I->seeInShellOutput('Config2: value2'); } - - + + /** + * @param CliGuy $I + */ + public function runtimeExtensionsWorkWithIncludedSuitesPresentInTheConfigAndRunningARootSuite(CliGuy $I) + { + $I->amInPath('tests/data/included'); + // unit is a root suite. + $I->executeCommand('run unit --ext DotReporter'); + $I->seeInShellOutput('.'); + $I->dontSeeInShellOutput('RootApplicationUnitTest:'); + } + + /** + * @param CliGuy $I + */ + public function runtimeExtensionsWorkWhenRunningWildCardSuites(CliGuy $I) + { + $I->amInPath('tests/data/included'); + $I->executeCommand('run *::unit --ext DotReporter'); + $I->seeInShellOutput('..'); + $I->dontSeeInShellOutput('SimpleTest: Simple:'); + } + + /** + * @param CliGuy $I + */ + public function runtimeExtensionsWorkWhenRunningWildCardSuitesAndRoot(CliGuy $I) + { + $I->amInPath('tests/data/included'); + $I->executeCommand('run unit,*::unit --ext DotReporter'); + $I->seeInShellOutput('..'); + $I->dontSeeInShellOutput('SimpleTest: Simple:'); + $I->dontSeeInShellOutput('RootApplicationUnitTest:'); + } + + + /** + * @param CliGuy $I + */ + public function runtimeExtensionsWorkWhenRunningTestsFromAnIncludedConfig(CliGuy $I) + { + $I->amInPath('tests/data/included'); + + $ds = DIRECTORY_SEPARATOR; + $I->executeCommand("run jazz{$ds}tests{$ds}functional{$ds}DemoCept.php --ext DotReporter", false); + $I->seeInShellOutput('.'); + $I->dontSeeInShellOutput('DemoCept:'); + } + }