diff --git a/src/StreamWrapper.php b/src/StreamWrapper.php index aa19e8a..377d29c 100644 --- a/src/StreamWrapper.php +++ b/src/StreamWrapper.php @@ -259,6 +259,8 @@ public function stream_open( if (strpbrk($mode, 'waxc') !== false) { $this->stream_write(''); $this->stream_flush(); + } elseif (strpbrk($mode, 'r') !== false) { + $this->openRead(); } return true; } diff --git a/tests/StreamWrapperTest.php b/tests/StreamWrapperTest.php index d9657f7..72791ff 100644 --- a/tests/StreamWrapperTest.php +++ b/tests/StreamWrapperTest.php @@ -10,6 +10,13 @@ use Monolog\Logger; use Psr\Log\LoggerInterface; +function createFile(string $uri): void +{ + $result = touch($uri); + expect($result)->toBeTrue(); + expect(file_exists($uri))->toBeTrue(); +} + beforeEach(function () { $serviceLocator = new ServiceLocator(); ServiceLocator::setInstance($serviceLocator); @@ -45,8 +52,7 @@ }); it('can copy an empty file', function () { - $success = touch('fly://src'); - expect($success)->toBe(true); + createFile('fly://src'); $success = copy('fly://src', 'fly://dst'); expect($success)->toBe(true); @@ -98,9 +104,7 @@ }); it('can rename an existing file', function () { - $result = touch('fly://foo'); - expect($result)->toBeTrue(); - expect(file_exists('fly://foo'))->toBeTrue(); + createFile('fly://foo'); $result = rename('fly://foo', 'fly://bar'); expect($result)->toBeTrue(); clearstatcache(); @@ -123,6 +127,8 @@ }); it('can acquire multiple shared locks', function () { + createFile('fly://foo'); + $stream1 = fopen('fly://foo', 'r'); $result = flock($stream1, LOCK_SH); expect($result)->toBeTrue(); @@ -152,6 +158,8 @@ }); it('cannot acquire an exclusive lock with existing locks', function () { + createFile('fly://foo'); + $stream1 = fopen('fly://foo', 'r'); $result = flock($stream1, LOCK_SH); expect($result)->toBeTrue(); @@ -166,9 +174,7 @@ }); it('does not support operations to change owner, group, or access', function () { - $result = touch('fly://foo'); - expect($result)->toBeTrue(); - expect(file_exists('fly://foo'))->toBeTrue(); + createFile('fly://foo'); $result = chmod('fly://foo', 0755); expect($result)->toBeFalse(); @@ -281,3 +287,14 @@ expect($actual)->toBe($expected); }); + +it('can stat a file', function () { + $result = file_put_contents('fly://foo', 'foobar'); + expect(file_exists('fly://foo'))->toBeTrue(); + + $stream = fopen('fly://foo', 'r'); + $metadata = \stream_get_meta_data($stream); + expect($metadata['uri'])->toEqual('fly://foo'); + fclose($stream); + ; +});