Skip to content

Commit

Permalink
Merge pull request #19 from Codeception/openFile-no-such-file-error
Browse files Browse the repository at this point in the history
openFile: Fail correctly if the file doesn't exist
  • Loading branch information
Naktibalda authored Mar 14, 2022
2 parents 2c8201d + 214fe0c commit 326ef1c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Codeception/Module/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 326ef1c

Please sign in to comment.