Skip to content

Commit 326ef1c

Browse files
authored
Merge pull request #19 from Codeception/openFile-no-such-file-error
openFile: Fail correctly if the file doesn't exist
2 parents 2c8201d + 214fe0c commit 326ef1c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Codeception/Module/Filesystem.php

Lines changed: 13 additions & 4 deletions
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,7 +79,11 @@ protected function absolutizePath(string $path): string
7579
*/
7680
public function openFile(string $filename): void
7781
{
78-
$this->file = file_get_contents($this->absolutizePath($filename));
82+
$absolutePath = $this->absolutizePath($filename);
83+
if (!file_exists($absolutePath)) {
84+
TestCase::fail('file not found');
85+
}
86+
$this->file = file_get_contents($absolutePath);
7987
$this->filePath = $filename;
8088
}
8189

@@ -89,11 +97,12 @@ public function openFile(string $filename): void
8997
*/
9098
public function deleteFile(string $filename): void
9199
{
92-
if (!file_exists($this->absolutizePath($filename))) {
100+
$absolutePath = $this->absolutizePath($filename);
101+
if (!file_exists($absolutePath)) {
93102
TestCase::fail('file not found');
94103
}
95104

96-
unlink($this->absolutizePath($filename));
105+
unlink($absolutePath);
97106
}
98107

99108
/**

0 commit comments

Comments
 (0)