diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 3fc3ef65b9..9e83f3bf0e 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\Lib\GroupManager; use Codeception\Util\PathResolver; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -493,9 +494,20 @@ protected function matchSingleTest($suite, $config) */ protected function runIncludedSuites($suites, $parent_dir) { + $defaultConfig = Configuration::config(); + $absolutePath = \Codeception\Configuration::projectDir(); + 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) { + return $absolutePath . $g; + }, $defaultConfig['groups']); + Configuration::append(['groups' => $groups]); + } + $suites = Configuration::suites(); $namespace = $this->currentNamespace(); diff --git a/src/Codeception/Configuration.php b/src/Codeception/Configuration.php index 687e150503..fc3fe2f2a6 100644 --- a/src/Codeception/Configuration.php +++ b/src/Codeception/Configuration.php @@ -32,6 +32,12 @@ class Configuration */ protected static $dir = null; + /** + * @var string Directory of a base configuration file for the project with includes. + * @see self::projectDir() + */ + protected static $baseDir = null; + /** * @var string Current project output directory. */ @@ -158,6 +164,11 @@ public static function config($configFile = null) $dir = realpath(dirname($configFile)); self::$dir = $dir; + // set the one default base directory for included setup + if (!self::$baseDir) { + self::$baseDir = $dir; + } + $configDistFile = $dir . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; if (!(file_exists($configDistFile) || file_exists($configFile))) { @@ -568,6 +579,17 @@ public static function projectDir() return self::$dir . DIRECTORY_SEPARATOR; } + /** + * Returns path to the base dir for config which consists with included setup + * Returns path to `codeception.yml` which was executed. + * If config doesn't have "include" section the result is the same as `projectDir()` + * @return string + */ + public static function baseDir() + { + return self::$baseDir . DIRECTORY_SEPARATOR; + } + /** * Returns path to tests directory diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index 3910544c97..f1ecdf7469 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -18,8 +18,12 @@ class GroupManager protected $configuredGroups; protected $testsInGroups = []; + protected $rootDir; + + public function __construct(array $groups) { + $this->rootDir = Configuration::baseDir(); $this->configuredGroups = $groups; $this->loadGroupsByPattern(); $this->loadConfiguredGroupSettings(); @@ -42,12 +46,19 @@ protected function loadGroupsByPattern() if (strpos($group, '*') === false) { continue; } + $path = dirname($pattern); + if (!\Codeception\Util\PathResolver::isPathAbsolute($pattern)) { + $path = $this->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(); @@ -66,8 +77,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 = $this->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 @@ -95,6 +113,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 : @@ -110,12 +130,12 @@ private function normalizeFilePath($file, $group) $this->checkIfFileExists($file, $group); return realpath($file); } elseif (strpos($file, ':') === false) { - $dirtyPath = Configuration::projectDir() . $file; + $dirtyPath = $this->rootDir . $file; $this->checkIfFileExists($dirtyPath, $group); return realpath($dirtyPath); } - $dirtyPath = Configuration::projectDir() . $pathParts[0]; + $dirtyPath = $this->rootDir . $pathParts[0]; $this->checkIfFileExists($dirtyPath, $group); return sprintf('%s:%s', realpath($dirtyPath), $pathParts[1]); } diff --git a/tests/cli/IncludedCest.php b/tests/cli/IncludedCest.php index d1e4c2d8e2..46c5480f03 100644 --- a/tests/cli/IncludedCest.php +++ b/tests/cli/IncludedCest.php @@ -182,4 +182,15 @@ public function cleanIncluded(\CliGuy $I) $I->seeInShellOutput('Done'); } + /** + * @before moveToIncluded + * @param CliGuy $I + */ + public function runIncludedGroup(\CliGuy $I) + { + $I->executeCommand("run -g group", false); + $I->dontSeeInShellOutput('No tests executed'); + $I->seeInShellOutput('2 tests'); + } + } diff --git a/tests/data/included/codeception.yml b/tests/data/included/codeception.yml index 0b03891c7d..4d0b51b47e 100644 --- a/tests/data/included/codeception.yml +++ b/tests/data/included/codeception.yml @@ -2,7 +2,11 @@ include: - jazz - jazz/pianist - shire + +groups: + group: group.txt + paths: log: "_log" settings: - colors: false \ No newline at end of file + colors: false diff --git a/tests/data/included/group.txt b/tests/data/included/group.txt new file mode 100644 index 0000000000..8f5e1f3484 --- /dev/null +++ b/tests/data/included/group.txt @@ -0,0 +1 @@ +jazz/tests/unit/SimpleTest.php diff --git a/tests/data/included/jazz/codeception.yml b/tests/data/included/jazz/codeception.yml index ad7fe84d94..f9a9df6b4a 100644 --- a/tests/data/included/jazz/codeception.yml +++ b/tests/data/included/jazz/codeception.yml @@ -4,8 +4,8 @@ paths: log: tests/_log data: tests/_data helpers: tests/_helpers +bootstrap: functional/_bootstrap.php settings: - bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite colors: true memory_limit: 1024M diff --git a/tests/data/included/jazz/pianist/codeception.yml b/tests/data/included/jazz/pianist/codeception.yml index c9709c78bd..7afb023f23 100644 --- a/tests/data/included/jazz/pianist/codeception.yml +++ b/tests/data/included/jazz/pianist/codeception.yml @@ -4,8 +4,8 @@ paths: log: tests/_log data: tests/_data helpers: tests/_helpers +bootstrap: functional/_bootstrap.php settings: - bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite colors: true memory_limit: 1024M diff --git a/tests/data/included/shire/codeception.yml b/tests/data/included/shire/codeception.yml index 85e61da6b4..6d7612eb04 100644 --- a/tests/data/included/shire/codeception.yml +++ b/tests/data/included/shire/codeception.yml @@ -4,8 +4,8 @@ paths: log: tests/_log data: tests/_data helpers: tests/_helpers +bootstrap: functional/_bootstrap.php settings: - bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite colors: true memory_limit: 1024M