Skip to content

Commit

Permalink
Propagate --ext and --override parameters to included test suites (#6536
Browse files Browse the repository at this point in the history
)

* 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 1458dda
  • Loading branch information
calvinalkan committed Aug 13, 2022
1 parent 83f6f7b commit c53401d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
42 changes: 21 additions & 21 deletions src/Codeception/Command/Run.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

}
52 changes: 50 additions & 2 deletions tests/cli/ExtensionsCest.php
Expand Up @@ -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:');
}

}

0 comments on commit c53401d

Please sign in to comment.