Skip to content

Commit

Permalink
ensure that directly running root level suites
Browse files Browse the repository at this point in the history
does not run included app suites.
  • Loading branch information
calvinalkan committed May 5, 2022
1 parent 30b102e commit dfdb820
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/Codeception/Command/Run.php
Expand Up @@ -9,6 +9,8 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function array_merge;

/**
* Executes tests.
*
Expand Down Expand Up @@ -408,10 +410,13 @@ public function execute(InputInterface $input, OutputInterface $output)

// Run all tests of given suite or all suites
if (!$test) {
$rawSuites = $suite ? explode(',', $suite) : Configuration::suites();

/** @var string[] $mainAppSuite */
$mainAppSuite = [];
$didPassCliSuite = !empty($suite);

$rawSuites = $didPassCliSuite ? explode(',', $suite) : Configuration::suites();

/** @var string[] $mainAppSuites */
$mainAppSuites = [];

/** @var array<string,string> $appSpecificSuites */
$appSpecificSuites = [];
Expand All @@ -429,19 +434,22 @@ public function execute(InputInterface $input, OutputInterface $output)
$appSpecificSuites[$appAndSuite[0]][] = $appAndSuite[1];
continue;
}
$mainAppSuite[] = $rawSuite;
$mainAppSuites[] = $rawSuite;
}

if([] !== $mainAppSuite) {
$this->executed = $this->runSuites($mainAppSuite, $this->options['skip']);
if([] !== $mainAppSuites) {
$this->executed = $this->runSuites($mainAppSuites, $this->options['skip']);
}

if(!empty($wildcardSuites) && ! empty($appSpecificSuites)) {
$this->output->writeLn('<error>Wildcard options can not be combined with specific suites of included apps.</error>');
return 2;
}

if(!empty($config['include'])) {
if(
!empty($config['include'])
&& (!$didPassCliSuite || !empty($wildcardSuites) || !empty($appSpecificSuites))
) {

$currentDir = Configuration::projectDir();
$includedApps = $config['include'];
Expand Down Expand Up @@ -737,4 +745,13 @@ private function isSuiteInMultiApplication($suite_name)
return false !== strpos($suite_name, '::');
}

/**
* @param string $suite_name
*
* @return bool
*/
private function isRootLevelSuite($suite_name) {
return !$this->isSuiteInMultiApplication($suite_name) && ! $this->isWildcardSuiteName($suite_name);
}

}
67 changes: 67 additions & 0 deletions tests/cli/IncludedCest.php
Expand Up @@ -279,4 +279,71 @@ public function wildCardSuitesAndAppSpecificSuitesCantBeCombined(CliGuy $I)
$I->seeInShellOutput('Wildcard options can not be combined with specific suites of included apps.');
}

/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runningASuiteInTheRootApplicationDoesNotRunTheIncludedAppSuites(CliGuy $I)
{
$I->executeCommand('run unit');

$I->seeInShellOutput('Unit Tests (1)');
$I->seeInShellOutput('RootApplicationUnitTest:');

$I->dontSeeInShellOutput('Functional Tests (1)');
$I->dontSeeInShellOutput('RootApplicationFunctionalTest:');
$I->dontSeeInShellOutput('Jazz.functional Tests');
$I->dontSeeInShellOutput('Jazz.unit Tests');

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

$I->seeInShellOutput('Functional Tests (1)');
$I->seeInShellOutput('RootApplicationFunctionalTest:');

$I->dontSeeInShellOutput('Unit Tests (1)');
$I->dontSeeInShellOutput('RootApplicationUnitTest:');
$I->dontSeeInShellOutput('Jazz.functional Tests');
$I->dontSeeInShellOutput('Jazz.unit Tests');
}

/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function rootSuitesCanBeRunInCombinationWithIncludedSuites(CliGuy $I)
{
$I->executeCommand('run unit,*::unit');

// root level
$I->seeInShellOutput('Unit Tests (1)');
$I->seeInShellOutput('RootApplicationUnitTest:');
$I->dontSeeInShellOutput('Functional Tests (1)');
$I->dontSeeInShellOutput('RootApplicationFunctionalTest:');

// included
$I->seeInShellOutput('Jazz.unit Tests');
$I->dontSeeInShellOutput('Jazz.functional Tests');
$I->dontSeeInShellOutput('Jazz\Pianist.functional');
$I->dontSeeInShellOutput('Shire.functional Tests');

// Ensure that root level suites are not run twice.
$I->seeInShellOutput('OK (3 tests, 3 assertions)');


$I->executeCommand('run unit,jazz::functional');

// root level
$I->seeInShellOutput('Unit Tests (1)');
$I->seeInShellOutput('RootApplicationUnitTest:');
$I->dontSeeInShellOutput('Functional Tests (1)');
$I->dontSeeInShellOutput('RootApplicationFunctionalTest:');

// included apps
$I->seeInShellOutput('Jazz.functional Tests');
$I->dontSeeInShellOutput('Jazz.unit Tests');
$I->dontSeeInShellOutput('Jazz\Pianist.functional');
$I->dontSeeInShellOutput('Shire.functional Tests');

}

}
5 changes: 5 additions & 0 deletions tests/data/included/codeception.yml
Expand Up @@ -3,10 +3,15 @@ include:
- jazz/pianist
- shire



groups:
group: group.txt

paths:
tests: tests
data: tests/_data
support: tests/_support
log: "_log"
settings:
colors: false
1 change: 1 addition & 0 deletions tests/data/included/tests/functional.suite.yml
@@ -0,0 +1 @@
##
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace data\included\tests\functional;

use Codeception\Test\Unit;

/**
* This is not a Cept test case because it does not matter for what we are testing.
*/
class RootApplicationFunctionalTest extends Unit
{

public function testBarEqualsBar()
{
$this->assertSame('bar', 'bar');
}
}
1 change: 1 addition & 0 deletions tests/data/included/tests/unit.suite.yml
@@ -0,0 +1 @@
##
15 changes: 15 additions & 0 deletions tests/data/included/tests/unit/RootApplicationUnitTest.php
@@ -0,0 +1,15 @@
<?php

namespace data\included\tests\unit;

use Codeception\Test\Unit;

class RootApplicationUnitTest extends Unit
{

public function testFooEqualsFoo()
{
$this->assertSame('foo', 'foo');
}

}

0 comments on commit dfdb820

Please sign in to comment.