diff --git a/src/Codeception/Module/Filesystem.php b/src/Codeception/Module/Filesystem.php index dce7949..e3a181e 100644 --- a/src/Codeception/Module/Filesystem.php +++ b/src/Codeception/Module/Filesystem.php @@ -43,7 +43,11 @@ public function _before(TestInterface $test): void */ public function amInPath(string $path): void { - chdir($this->path = $this->absolutizePath($path) . DIRECTORY_SEPARATOR); + $this->path = $this->absolutizePath($path) . DIRECTORY_SEPARATOR; + if (!file_exists($this->path)) { + TestCase::fail('directory not found'); + } + chdir($this->path); $this->debug('Moved to ' . getcwd()); } @@ -75,7 +79,11 @@ protected function absolutizePath(string $path): string */ public function openFile(string $filename): void { - $this->file = file_get_contents($this->absolutizePath($filename)); + $absolutePath = $this->absolutizePath($filename); + if (!file_exists($absolutePath)) { + TestCase::fail('file not found'); + } + $this->file = file_get_contents($absolutePath); $this->filePath = $filename; } @@ -89,11 +97,12 @@ public function openFile(string $filename): void */ public function deleteFile(string $filename): void { - if (!file_exists($this->absolutizePath($filename))) { + $absolutePath = $this->absolutizePath($filename); + if (!file_exists($absolutePath)) { TestCase::fail('file not found'); } - unlink($this->absolutizePath($filename)); + unlink($absolutePath); } /**