Skip to content

Commit cef218e

Browse files
committed
Improved RunTestInput class
1 parent cf04fb8 commit cef218e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Arachne/Codeception/Console/Input/RunTestInput.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,30 @@ public function __construct(InputDefinition $definition = NULL)
2020
$parameters = array($_SERVER['argv'][0], 'run');
2121

2222
if (isset($_SERVER['argv'][1])) {
23-
$filename = str_replace('\\', '/', $_SERVER['argv'][1]);
24-
$cwd = str_replace('\\', '/', getcwd()) . '/';
25-
if (strpos($filename, $cwd) === 0) {
26-
$parameters[] = substr($filename, strlen($cwd));
23+
$filename = $this->normalizePath($_SERVER['argv'][1]);
24+
$cwd = $this->normalizePath(getcwd()) . '/';
25+
26+
// IDE always provides absolute path but Codeception only accepts relative path without leading "./".
27+
// If path is not absolute, make it that way and call realpath to remove "./".
28+
if (strpos($filename, $cwd) !== 0 && file_exists($cwd . $filename)) {
29+
$filename = $this->normalizePath(realpath($cwd . $filename));
2730
}
31+
32+
if (!file_exists($filename)) {
33+
echo 'File "' . $filename . '" could not be found.';
34+
exit;
35+
}
36+
37+
// Cut of the absolute part for Codeception.
38+
$parameters[] = substr($filename, strlen($cwd));
2839
}
2940

3041
parent::__construct($parameters, $definition);
3142
}
3243

44+
private function normalizePath($path)
45+
{
46+
return str_replace('\\', '/', $path);
47+
}
48+
3349
}

0 commit comments

Comments
 (0)