diff --git a/src/Node/File.php b/src/Node/File.php index 55278c1b..55a684c4 100644 --- a/src/Node/File.php +++ b/src/Node/File.php @@ -145,9 +145,7 @@ public function close() */ public function getContents() { - return $this->open('r')->then(function ($stream) { - return Stream\buffer($stream); - }); + return $this->adapter->getContents($this->path); } /** @@ -155,10 +153,7 @@ public function getContents() */ public function putContents($contents) { - return $this->open('cw')->then(function (WritableStreamInterface $stream) use ($contents) { - $stream->write($contents); - return $this->close(); - }); + return $this->adapter->putContents($this->path, $contents); } /** diff --git a/tests/Node/FileTest.php b/tests/Node/FileTest.php index 16115583..1d0fedbf 100644 --- a/tests/Node/FileTest.php +++ b/tests/Node/FileTest.php @@ -280,36 +280,13 @@ public function testGetContents() $filesystem = $this->mockAdapter(); - $filesystem - ->expects($this->any()) - ->method('stat') - ->with($path) - ->will($this->returnValue(new FulfilledPromise([ - 'size' => 1, - ]))) - ; - - $filesystem - ->expects($this->once()) - ->method('open') - ->with($path, 'r') - ->will($this->returnValue(new FulfilledPromise($fd))) - ; - $filesystem ->expects($this->once()) - ->method('read') - ->with($fd, 1, 0) + ->method('getContents') + ->with($path) ->will($this->returnValue(new FulfilledPromise('a'))) ; - $filesystem - ->expects($this->once()) - ->method('close') - ->with($fd) - ->will($this->returnValue(new FulfilledPromise())) - ; - $getContentsPromise = (new File($path, Filesystem::createFromAdapter($filesystem)))->getContents(); $this->assertInstanceOf('React\Promise\PromiseInterface', $getContentsPromise); }