Skip to content

Commit 486663a

Browse files
authored
openFile: Fail correctly if the file doesn't exist
1 parent 2c8201d commit 486663a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Codeception/Module/Filesystem.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public function _before(TestInterface $test): void
4343
*/
4444
public function amInPath(string $path): void
4545
{
46-
chdir($this->path = $this->absolutizePath($path) . DIRECTORY_SEPARATOR);
46+
$this->path = $this->absolutizePath($path) . DIRECTORY_SEPARATOR;
47+
if (!file_exists($this->path)) {
48+
TestCase::fail('directory not found');
49+
}
50+
chdir($this->path);
4751
$this->debug('Moved to ' . getcwd());
4852
}
4953

@@ -75,6 +79,9 @@ protected function absolutizePath(string $path): string
7579
*/
7680
public function openFile(string $filename): void
7781
{
82+
if (!file_exists($this->absolutizePath($filename))) {
83+
TestCase::fail('file not found');
84+
}
7885
$this->file = file_get_contents($this->absolutizePath($filename));
7986
$this->filePath = $filename;
8087
}

0 commit comments

Comments
 (0)