From 3579d06da59e00a5face70fd0140357370af618d Mon Sep 17 00:00:00 2001 From: Nicky De Maeyer Date: Sat, 23 Jan 2021 17:41:44 +0100 Subject: [PATCH] detect the suite from a test path relative to the current working dir (#6051) * detect the suite from a test path relative to the current working directory * when tests and suite paths are "." we can safely set the suite * test for codeception.yaml in random subdir * revert generic solution for #4432 --- src/Codeception/Command/Run.php | 27 +++++++++++++++---- tests/cli/CodeceptionYmlInRandomDirCest.php | 16 +++++++++++ .../random/subdir/codeception.yml | 8 ++++++ .../tests/_bootstrap.php | 2 ++ .../tests/_output/.gitignore | 2 ++ .../tests/_support/UnitTester.php | 26 ++++++++++++++++++ .../tests/_support/_generated/.gitignore | 2 ++ .../tests/unit.suite.yml | 8 ++++++ .../tests/unit/ExampleCest.php | 9 +++++++ .../tests/unit/_bootstrap.php | 2 ++ 10 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 tests/cli/CodeceptionYmlInRandomDirCest.php create mode 100644 tests/data/codeception_yml_in_random_dir/random/subdir/codeception.yml create mode 100644 tests/data/codeception_yml_in_random_dir/tests/_bootstrap.php create mode 100644 tests/data/codeception_yml_in_random_dir/tests/_output/.gitignore create mode 100644 tests/data/codeception_yml_in_random_dir/tests/_support/UnitTester.php create mode 100644 tests/data/codeception_yml_in_random_dir/tests/_support/_generated/.gitignore create mode 100644 tests/data/codeception_yml_in_random_dir/tests/unit.suite.yml create mode 100644 tests/data/codeception_yml_in_random_dir/tests/unit/ExampleCest.php create mode 100644 tests/data/codeception_yml_in_random_dir/tests/unit/_bootstrap.php diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index e537d2b543..4184f6f2cb 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -117,7 +117,6 @@ class Run extends Command */ protected $output; - /** * Sets Run arguments * @throws \Symfony\Component\Console\Exception\InvalidArgumentException @@ -456,9 +455,28 @@ protected function matchSingleTest($suite, $config) } } - // Run single test without included tests - if (! Configuration::isEmpty() && strpos($suite, $config['paths']['tests']) === 0) { - return $this->matchTestFromFilename($suite, $config['paths']['tests']); + if (! Configuration::isEmpty()) { + // Run single test without included tests + if (strpos($suite, $config['paths']['tests']) === 0) { + return $this->matchTestFromFilename($suite, $config['paths']['tests']); + } + + // Run single test from working directory + $realTestDir = realpath(Configuration::testsDir()); + $cwd = getcwd(); + if (strpos($realTestDir, $cwd) === 0) { + $file = $suite; + if (strpos($file, ':') !== false) { + list($file) = explode(':', $suite, -1); + } + $realPath = $cwd . DIRECTORY_SEPARATOR . $file; + if (file_exists($realPath) || is_dir($realPath)) { + return $this->matchTestFromFilename( + $cwd . DIRECTORY_SEPARATOR . $suite, + $realTestDir + ); + } + } } } @@ -487,7 +505,6 @@ protected function runIncludedSuites($suites, $parent_dir) } } - protected function currentNamespace() { $config = Configuration::config(); diff --git a/tests/cli/CodeceptionYmlInRandomDirCest.php b/tests/cli/CodeceptionYmlInRandomDirCest.php new file mode 100644 index 0000000000..d5d25efe19 --- /dev/null +++ b/tests/cli/CodeceptionYmlInRandomDirCest.php @@ -0,0 +1,16 @@ +amInPath('tests/data/codeception_yml_in_random_dir'); + $I->executeCommand('run -c random/subdir/codeception.yml tests/unit/ExampleCest.php'); + + $I->seeResultCodeIs(0); + $I->dontSeeInShellOutput('RuntimeException'); + $I->dontSeeInShellOutput('could not be found'); + } +} diff --git a/tests/data/codeception_yml_in_random_dir/random/subdir/codeception.yml b/tests/data/codeception_yml_in_random_dir/random/subdir/codeception.yml new file mode 100644 index 0000000000..07742f03e9 --- /dev/null +++ b/tests/data/codeception_yml_in_random_dir/random/subdir/codeception.yml @@ -0,0 +1,8 @@ +actor: Tester +paths: + tests: ../../tests + log: ../../tests/_output + data: ../../tests/_data + support: ../../tests/_support +settings: + bootstrap: ../../tests/_bootstrap.php diff --git a/tests/data/codeception_yml_in_random_dir/tests/_bootstrap.php b/tests/data/codeception_yml_in_random_dir/tests/_bootstrap.php new file mode 100644 index 0000000000..243f9c85bc --- /dev/null +++ b/tests/data/codeception_yml_in_random_dir/tests/_bootstrap.php @@ -0,0 +1,2 @@ +assertTrue(true); + } +} diff --git a/tests/data/codeception_yml_in_random_dir/tests/unit/_bootstrap.php b/tests/data/codeception_yml_in_random_dir/tests/unit/_bootstrap.php new file mode 100644 index 0000000000..8a88555806 --- /dev/null +++ b/tests/data/codeception_yml_in_random_dir/tests/unit/_bootstrap.php @@ -0,0 +1,2 @@ +