Skip to content

Commit

Permalink
Test if file exists before calling getContents #11
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Aug 1, 2016
1 parent f2c1f41 commit 194f259
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public function constructLink($path)
*/
public function getContents($filename)
{
return $this->file($filename)->getContents();
$file = $this->file($filename);
return $file->exists()->then(function () use ($file) {
return $file->getContents();
});
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use React\Filesystem\Filesystem;
use React\Filesystem\InstantInvoker;
use React\Promise\FulfilledPromise;
use React\Promise\RejectedPromise;

class FilesystemTest extends TestCase
Expand Down Expand Up @@ -67,6 +68,11 @@ public function testDir()
public function testGetContents()
{
$adapter = $this->mockAdapter();
$adapter
->expects($this->any())
->method('stat')
->will($this->returnValue(new FulfilledPromise([])))
;
$adapter
->expects($this->any())
->method('open')
Expand Down

0 comments on commit 194f259

Please sign in to comment.