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

Fixes include group #6292

Merged
merged 5 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions src/Codeception/Command/Run.php
Expand Up @@ -3,6 +3,7 @@

use Codeception\Codecept;
use Codeception\Configuration;
use Codeception\Lib\GroupManager;
use Codeception\Util\PathResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -489,9 +490,23 @@ protected function matchSingleTest($suite, $config)
*/
protected function runIncludedSuites($suites, $parent_dir)
{
$defaultConfig = Configuration::config();
$absolutePath = \Codeception\Configuration::projectDir();
if (!empty($defaultConfig['groups'])) {
GroupManager::setRootDir($absolutePath);
}

foreach ($suites as $relativePath) {
$current_dir = rtrim($parent_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $relativePath;
$config = Configuration::config($current_dir);

if (!empty($defaultConfig['groups'])) {
$groups = array_map(function($g) use ($absolutePath) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

return $absolutePath . $g;
}, $defaultConfig['groups']);
Configuration::append(['groups' => $groups]);
}

$suites = Configuration::suites();

$namespace = $this->currentNamespace();
Expand Down
36 changes: 31 additions & 5 deletions src/Codeception/Lib/GroupManager.php
Expand Up @@ -18,8 +18,18 @@ class GroupManager
protected $configuredGroups;
protected $testsInGroups = [];

protected static $rootDir;

public static function setRootDir($dir)
{
self::$rootDir = $dir;
}

public function __construct(array $groups)
{
if (!self::$rootDir) {
self::$rootDir = codecept_root_dir();
}
$this->configuredGroups = $groups;
$this->loadGroupsByPattern();
$this->loadConfiguredGroupSettings();
Expand All @@ -42,12 +52,19 @@ protected function loadGroupsByPattern()
if (strpos($group, '*') === false) {
continue;
}
$path = dirname($pattern);
if (!\Codeception\Util\PathResolver::isPathAbsolute($pattern)) {
$path = self::$rootDir . $path;
}

$files = Finder::create()->files()
->name(basename($pattern))
->sortByName()
->in(Configuration::projectDir().dirname($pattern));
->in($path);

$i = 1;


foreach ($files as $file) {
/** @var SplFileInfo $file * */
$this->configuredGroups[str_replace('*', $i, $group)] = dirname($pattern).DIRECTORY_SEPARATOR.$file->getRelativePathname();
Expand All @@ -66,8 +83,15 @@ protected function loadConfiguredGroupSettings()
$file = str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $test);
$this->testsInGroups[$group][] = $this->normalizeFilePath($file, $group);
}
} elseif (is_file(Configuration::projectDir() . $tests)) {
$handle = @fopen(Configuration::projectDir() . $tests, "r");
continue;
}

$path = $tests;
if (!codecept_is_path_absolute($tests)) {
$path = self::$rootDir . $tests;
}
if (is_file($path)) {
$handle = @fopen($path, "r");
if ($handle) {
while (($test = fgets($handle, 4096)) !== false) {
// if the current line is blank then we need to move to the next line
Expand Down Expand Up @@ -95,6 +119,8 @@ protected function loadConfiguredGroupSettings()
private function normalizeFilePath($file, $group)
{
$pathParts = explode(':', $file);


if (codecept_is_path_absolute($file)) {
if ($file[0] === '/' && count($pathParts) > 1) {
//take segment before first :
Expand All @@ -110,12 +136,12 @@ private function normalizeFilePath($file, $group)
$this->checkIfFileExists($file, $group);
return realpath($file);
} elseif (strpos($file, ':') === false) {
$dirtyPath = Configuration::projectDir() . $file;
$dirtyPath = self::$rootDir . $file;
$this->checkIfFileExists($dirtyPath, $group);
return realpath($dirtyPath);
}

$dirtyPath = Configuration::projectDir() . $pathParts[0];
$dirtyPath = self::$rootDir . $pathParts[0];
$this->checkIfFileExists($dirtyPath, $group);
return sprintf('%s:%s', realpath($dirtyPath), $pathParts[1]);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/cli/IncludedCest.php
Expand Up @@ -182,4 +182,11 @@ public function cleanIncluded(\CliGuy $I)
$I->seeInShellOutput('Done');
}

public function runIncludedGroup(\CliGuy $I)
{
$I->executeCommand("run -g group", false);
$I->dontSeeInShellOutput('No tests executed');
$I->seeInShellOutput('2 tests');
}

}
6 changes: 5 additions & 1 deletion tests/data/included/codeception.yml
Expand Up @@ -2,7 +2,11 @@ include:
- jazz
- jazz/pianist
- shire

groups:
group: group.txt

paths:
log: "_log"
settings:
colors: false
colors: false
1 change: 1 addition & 0 deletions tests/data/included/group.txt
@@ -0,0 +1 @@
jazz/tests/unit/SimpleTest.php
1 change: 0 additions & 1 deletion tests/data/included/jazz/codeception.yml
Expand Up @@ -5,7 +5,6 @@ paths:
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
Expand Down
1 change: 0 additions & 1 deletion tests/data/included/jazz/pianist/codeception.yml
Expand Up @@ -5,7 +5,6 @@ paths:
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
Expand Down
1 change: 0 additions & 1 deletion tests/data/included/shire/codeception.yml
Expand Up @@ -5,7 +5,6 @@ paths:
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
Expand Down