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

[Multi Apps 4.2] Fix wrong behaviour for runtime options like --ext and --override #6536

Merged
merged 2 commits into from Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:');
}

}