Repository: Codeception/Codeception (PHP)

Issue:
Problem resolving paths with codeception.yml inside test root directory
## Summary

When codeception.yml is *inside* the test root directory, there is a problem with resolving paths to test files.

I have my folder structure set up like this:

```
/tests/codeception.yml
/tests/unit/ExampleTest.php
```

And in codeception.yml I have the path set up like this:
```yml
paths:
    tests: .
```

Next, I am trying to run the following command:

```bash
/tests$ codecept unit/ExampleTest.php
```

But this results in the following error:

```
 [RuntimeException]
  Suite 'unit/ExampleTest.php' could not be found
```

If I prepend `./` and run it like this, it works fine:

```bash
/tests$ codecept ./unit/ExampleTest.php
```

## Full Details

```bash
/tests$ codecept run unit/ExampleTest.php -vvv
Codeception PHP Testing Framework v2.3.4
Powered by PHPUnit 5.7.21 by Sebastian Bergmann and contributors.


  [RuntimeException]
  Suite 'unit/ExampleTest.php' could not be found


Exception trace:
 () at .....\vendor\codeception\codeception\src\Codeception\Command\Run.php:356
 Codeception\Command\Run->execute() at ....\vendor\symfony\console\Command\Command.php:266
 Symfony\Component\Console\Command\Command->run() at ....\vendor\symfony\console\Application.php:861
 Symfony\Component\Console\Application->doRunCommand() at ....\vendor\symfony\console\Application.php:208
 Symfony\Component\Console\Application->doRun() at ....\vendor\symfony\console\Application.php:127
 Symfony\Component\Console\Application->run() at ....\vendor\codeception\codeception\src\Codeception\Application.php:103
 Codeception\Application->run() at ....\vendor\codeception\codeception\codecept:36
```

* Codeception version: 2.3.4
* PHP Version: 5.6
* Operating System: Windows
* Installation type: Composer
* Suite configuration:

```yml
paths:
    tests: .
    output: _output
    data: _data
    support: _support
settings:
    bootstrap: _bootstrap.php
...
```

The problem should probably be fixed around here: https://github.com/Codeception/Codeception/blob/2.3/src/Codeception/Command/Run.php#L327



Discussion:

Patch:
diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php
index 5abf08fcbe..dec08a8b79 100644
--- a/src/Codeception/Command/Run.php
+++ b/src/Codeception/Command/Run.php
@@ -323,6 +323,12 @@ public function execute(InputInterface $input, OutputInterface $output)
                     $config = Configuration::config($projectDir);
                 }
             } elseif (!empty($suite)) {
+                // Workaround when codeception.yml is inside tests directory and tests path is set to "."
+                // @see https://github.com/Codeception/Codeception/issues/4432
+                if ($config['paths']['tests'] === '.' && !preg_match('~^\.[/\\\]~', $suite)) {
+                    $suite = './' . $suite;
+                }
+                
                 // Run single test without included tests
                 if (! Configuration::isEmpty() && strpos($suite, $config['paths']['tests']) === 0) {
                     list(, $suite, $test) = $this->matchTestFromFilename($suite, $config['paths']['tests']);


Test patch:
diff --git a/tests/cli/CodeceptionYmlInTestsDirCest.php b/tests/cli/CodeceptionYmlInTestsDirCest.php
new file mode 100644
index 0000000000..6b0b665395
--- /dev/null
+++ b/tests/cli/CodeceptionYmlInTestsDirCest.php
@@ -0,0 +1,16 @@
+<?php
+class CodeceptionYmlInTestsDirCest
+{
+    /**
+     * @param CliGuy $I
+     */
+    public function runTestPath(\CliGuy $I)
+    {
+        $I->amInPath('tests/data/codeception_yml_in_tests_dir');
+        $I->executeCommand('run unit/ExampleCest.php');
+        
+        $I->seeResultCodeIs(0);
+        $I->dontSeeInShellOutput('RuntimeException');
+        $I->dontSeeInShellOutput('could not be found');
+    }
+}
diff --git a/tests/data/codeception_yml_in_tests_dir/_bootstrap.php b/tests/data/codeception_yml_in_tests_dir/_bootstrap.php
new file mode 100644
index 0000000000..243f9c85bc
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/_bootstrap.php
@@ -0,0 +1,2 @@
+<?php
+// This is global bootstrap for autoloading
diff --git a/tests/data/codeception_yml_in_tests_dir/_output/.gitignore b/tests/data/codeception_yml_in_tests_dir/_output/.gitignore
new file mode 100644
index 0000000000..c96a04f008
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/_output/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
\ No newline at end of file
diff --git a/tests/data/codeception_yml_in_tests_dir/_support/UnitTester.php b/tests/data/codeception_yml_in_tests_dir/_support/UnitTester.php
new file mode 100644
index 0000000000..28353572c1
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/_support/UnitTester.php
@@ -0,0 +1,26 @@
+<?php
+
+
+/**
+ * Inherited Methods
+ * @method void wantToTest($text)
+ * @method void wantTo($text)
+ * @method void execute($callable)
+ * @method void expectTo($prediction)
+ * @method void expect($prediction)
+ * @method void amGoingTo($argumentation)
+ * @method void am($role)
+ * @method void lookForwardTo($achieveValue)
+ * @method void comment($description)
+ * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
+ *
+ * @SuppressWarnings(PHPMD)
+*/
+class UnitTester extends \Codeception\Actor
+{
+    use _generated\UnitTesterActions;
+
+   /**
+    * Define custom actions here
+    */
+}
diff --git a/tests/data/codeception_yml_in_tests_dir/_support/_generated/.gitignore b/tests/data/codeception_yml_in_tests_dir/_support/_generated/.gitignore
new file mode 100644
index 0000000000..c96a04f008
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/_support/_generated/.gitignore
@@ -0,0 +1,2 @@
+*
+!.gitignore
\ No newline at end of file
diff --git a/tests/data/codeception_yml_in_tests_dir/codeception.yml b/tests/data/codeception_yml_in_tests_dir/codeception.yml
new file mode 100644
index 0000000000..a9024f26d3
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/codeception.yml
@@ -0,0 +1,8 @@
+actor: Tester
+paths:
+    tests: .
+    log: _output
+    data: _data
+    support: _support
+settings:
+    bootstrap: _bootstrap.php
\ No newline at end of file
diff --git a/tests/data/codeception_yml_in_tests_dir/unit.suite.yml b/tests/data/codeception_yml_in_tests_dir/unit.suite.yml
new file mode 100644
index 0000000000..07a7166d5b
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/unit.suite.yml
@@ -0,0 +1,8 @@
+# Codeception Test Suite Configuration
+#
+# Suite for unit (internal) tests.
+
+class_name: UnitTester
+modules:
+    enabled:
+        - Asserts
\ No newline at end of file
diff --git a/tests/data/codeception_yml_in_tests_dir/unit/ExampleCest.php b/tests/data/codeception_yml_in_tests_dir/unit/ExampleCest.php
new file mode 100644
index 0000000000..012fcca581
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/unit/ExampleCest.php
@@ -0,0 +1,9 @@
+<?php
+
+class ExampleCest
+{
+    public function successful(UnitTester $I)
+    {
+        $I->assertTrue(true);
+    }
+}
diff --git a/tests/data/codeception_yml_in_tests_dir/unit/_bootstrap.php b/tests/data/codeception_yml_in_tests_dir/unit/_bootstrap.php
new file mode 100644
index 0000000000..8a88555806
--- /dev/null
+++ b/tests/data/codeception_yml_in_tests_dir/unit/_bootstrap.php
@@ -0,0 +1,2 @@
+<?php
+// Here you can initialize variables that will be available to your tests