From dd5b821b0d765082efb25d94bafca75ec88c3143 Mon Sep 17 00:00:00 2001 From: p8nut Date: Tue, 6 Aug 2024 10:52:22 +0200 Subject: [PATCH 1/3] add missing stream wrapper functions --- src/S3/StreamWrapper.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/S3/StreamWrapper.php b/src/S3/StreamWrapper.php index a70e5cd52d..9089851754 100644 --- a/src/S3/StreamWrapper.php +++ b/src/S3/StreamWrapper.php @@ -581,6 +581,28 @@ public function stream_cast($cast_as) return false; } + public function stream_set_option($option, $arg1, $arg2) + { + return false; + } + + public function stream_metadata($path, $option, $value) + { + return false; + } + + public function stream_lock($operation) + { + trigger_error('stream_lock() is not supported by the Amazon S3 stream wrapper', E_USER_WARNING); + return false; + } + + public function stream_truncate($new_size) + { + trigger_error('stream_truncate() is not supported by the Amazon S3 stream wrapper', E_USER_WARNING); + return false; + } + /** * Validates the provided stream arguments for fopen and returns an array * of errors. From 37376966e653bef55ced993d20be811b212cc6ac Mon Sep 17 00:00:00 2001 From: p8nut Date: Mon, 9 Sep 2024 20:44:59 +0200 Subject: [PATCH 2/3] add tests --- tests/S3/StreamWrapperTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/S3/StreamWrapperTest.php b/tests/S3/StreamWrapperTest.php index 2a774aa508..e3f8df75f2 100644 --- a/tests/S3/StreamWrapperTest.php +++ b/tests/S3/StreamWrapperTest.php @@ -1035,4 +1035,30 @@ public function testTriggersErrorOnNoFlushOrClose($content) $stream = fopen('s3://bucket/key', 'a'); fwrite($stream, $content); } + + public function testStreamSetOption() + { + $stream = fopen('s3://bucket/key', 'r'); + $this->assertFalse(stream_set_option($stream, STREAM_OPTION_READ_TIMEOUT, 1)); + } + + public function testStreamMetadata() + { + $stream = fopen('s3://bucket/key', 'r'); + $this->assertFalse(stream_metadata($stream, STREAM_META_TOUCH, 1)); + } + + public function testStreamLock() + { + $stream = fopen('s3://bucket/key', 'r'); + $this->assertFalse(flock($stream, LOCK_EX)); + $this->assertFalse(flock($stream, LOCK_UN)); + $this->assertFalse(flock($stream, LOCK_SH)); + } + + public function testStreamTruncate() + { + $stream = fopen('s3://bucket/key', 'r'); + $this->assertFalse(ftruncate($stream, 1)); + } } From cd9335080f1e1d370da9328b164bbdeea522e854 Mon Sep 17 00:00:00 2001 From: p8nut Date: Wed, 25 Sep 2024 02:30:28 +0200 Subject: [PATCH 3/3] update tests name; add mockResults --- tests/S3/StreamWrapperTest.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/S3/StreamWrapperTest.php b/tests/S3/StreamWrapperTest.php index e3f8df75f2..d924fb2e6f 100644 --- a/tests/S3/StreamWrapperTest.php +++ b/tests/S3/StreamWrapperTest.php @@ -1036,28 +1036,52 @@ public function testTriggersErrorOnNoFlushOrClose($content) fwrite($stream, $content); } - public function testStreamSetOption() + public function testStreamSetOptionReturnsFalse() { + $this->addMockResults( + $this->client, + [ + new Result(), + ] + ); $stream = fopen('s3://bucket/key', 'r'); $this->assertFalse(stream_set_option($stream, STREAM_OPTION_READ_TIMEOUT, 1)); } - public function testStreamMetadata() + public function testStreamMetadataReturnsFalse() { + $this->addMockResults( + $this->client, + [ + new Result(), + ] + ); $stream = fopen('s3://bucket/key', 'r'); $this->assertFalse(stream_metadata($stream, STREAM_META_TOUCH, 1)); } - public function testStreamLock() + public function testStreamLockReturnsFalse() { + $this->addMockResults( + $this->client, + [ + new Result(), + ] + ); $stream = fopen('s3://bucket/key', 'r'); $this->assertFalse(flock($stream, LOCK_EX)); $this->assertFalse(flock($stream, LOCK_UN)); $this->assertFalse(flock($stream, LOCK_SH)); } - public function testStreamTruncate() + public function testStreamTruncateReturnsFalse() { + $this->addMockResults( + $this->client, + [ + new Result(), + ] + ); $stream = fopen('s3://bucket/key', 'r'); $this->assertFalse(ftruncate($stream, 1)); }