From f1469e34aa8f29a8dbec8e1ae9260fb09777f82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 5 Jul 2018 18:08:56 +0200 Subject: [PATCH 1/2] Add fopen method to ISimpleFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Files/SimpleFS/SimpleFile.php | 11 +++++++++++ lib/public/Files/SimpleFS/ISimpleFile.php | 9 +++++++++ tests/lib/Files/SimpleFS/SimpleFileTest.php | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php index e9bf0213d0..52b7819694 100644 --- a/lib/private/Files/SimpleFS/SimpleFile.php +++ b/lib/private/Files/SimpleFS/SimpleFile.php @@ -146,4 +146,15 @@ class SimpleFile implements ISimpleFile { public function getMimeType() { return $this->file->getMimeType(); } + + /** + * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen + * + * @return resource + * @throws \OCP\Files\NotPermittedException + * @since 14.0.0 + */ + public function fopen(string $mode) { + return $this->file->fopen($mode); + } } diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php index cd092056cd..c417db6354 100644 --- a/lib/public/Files/SimpleFS/ISimpleFile.php +++ b/lib/public/Files/SimpleFS/ISimpleFile.php @@ -99,4 +99,13 @@ interface ISimpleFile { * @since 11.0.0 */ public function getMimeType(); + + /** + * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen + * + * @return resource + * @throws \OCP\Files\NotPermittedException + * @since 14.0.0 + */ + public function fopen(string $mode); } diff --git a/tests/lib/Files/SimpleFS/SimpleFileTest.php b/tests/lib/Files/SimpleFS/SimpleFileTest.php index ab4970804a..aec5052cb4 100644 --- a/tests/lib/Files/SimpleFS/SimpleFileTest.php +++ b/tests/lib/Files/SimpleFS/SimpleFileTest.php @@ -123,4 +123,12 @@ class SimpleFileTest extends \Test\TestCase { $this->simpleFile->getContent(); } + + public function testFopen() { + $this->file->expects($this->once()) + ->method('fopen') + ->with('r+'); + + $this->simpleFile->fopen('r+'); + } } From 6da2b7c4f6744baa5a14a2919790d034de4229bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 10 Jul 2018 14:27:47 +0200 Subject: [PATCH 2/2] Separate fopen into read and write methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Files/SimpleFS/SimpleFile.php | 18 +++++++++++++++--- lib/public/Files/SimpleFS/ISimpleFile.php | 13 +++++++++++-- tests/lib/Files/SimpleFS/SimpleFileTest.php | 14 +++++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php index 52b7819694..7b83e9372f 100644 --- a/lib/private/Files/SimpleFS/SimpleFile.php +++ b/lib/private/Files/SimpleFS/SimpleFile.php @@ -148,13 +148,25 @@ class SimpleFile implements ISimpleFile { } /** - * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen + * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * * @return resource * @throws \OCP\Files\NotPermittedException * @since 14.0.0 */ - public function fopen(string $mode) { - return $this->file->fopen($mode); + public function read() { + return $this->file->fopen('r'); } + + /** + * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen + * + * @return resource + * @throws \OCP\Files\NotPermittedException + * @since 14.0.0 + */ + public function write() { + return $this->file->fopen('w'); + } + } diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php index c417db6354..a3cd3245cc 100644 --- a/lib/public/Files/SimpleFS/ISimpleFile.php +++ b/lib/public/Files/SimpleFS/ISimpleFile.php @@ -101,11 +101,20 @@ interface ISimpleFile { public function getMimeType(); /** - * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen + * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * * @return resource * @throws \OCP\Files\NotPermittedException * @since 14.0.0 */ - public function fopen(string $mode); + public function read(); + + /** + * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen + * + * @return resource + * @throws \OCP\Files\NotPermittedException + * @since 14.0.0 + */ + public function write(); } diff --git a/tests/lib/Files/SimpleFS/SimpleFileTest.php b/tests/lib/Files/SimpleFS/SimpleFileTest.php index aec5052cb4..c1c53b15ec 100644 --- a/tests/lib/Files/SimpleFS/SimpleFileTest.php +++ b/tests/lib/Files/SimpleFS/SimpleFileTest.php @@ -124,11 +124,19 @@ class SimpleFileTest extends \Test\TestCase { $this->simpleFile->getContent(); } - public function testFopen() { + public function testRead() { $this->file->expects($this->once()) ->method('fopen') - ->with('r+'); + ->with('r'); - $this->simpleFile->fopen('r+'); + $this->simpleFile->read(); + } + + public function testWrite() { + $this->file->expects($this->once()) + ->method('fopen') + ->with('w'); + + $this->simpleFile->write(); } }