Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Flysystem/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function stream_close(): void
E_USER_WARNING
);
}

if (!is_resource($this->current->handle)) {
return;
}
}

fclose($this->current->handle);
Expand Down
31 changes: 31 additions & 0 deletions tests/Issues/AdapterClosesStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

namespace M2MTech\FlysystemStreamWrapper\Tests\Issues;

use League\Flysystem\FilesystemOperator;
use M2MTech\FlysystemStreamWrapper\Flysystem\FileData;
use M2MTech\FlysystemStreamWrapper\Flysystem\StreamWrapper;
use M2MTech\FlysystemStreamWrapper\FlysystemStreamWrapper;
use M2MTech\FlysystemStreamWrapper\Tests\Assert;
use M2MTech\FlysystemStreamWrapper\Tests\StreamCommand\AbstractStreamCommandTestCase;

Expand All @@ -34,4 +37,32 @@ public function testStreamClose(): void
$wrapper->stream_close();
$this->assertIsClosedResource($current->handle);
}

public function testStreamCloseWithLocalCopy(): void
{
$filesystem = $this->createMock(FilesystemOperator::class);
FlysystemStreamWrapper::register(self::TEST_PROTOCOL, $filesystem);

$current = new FileData();
$current->setPath(self::TEST_PATH);

$current->handle = fopen('php://temp', 'wb');
$current->workOnLocalCopy = true;

$wrapper = new StreamWrapper($current);

if (!is_resource($current->handle)) {
$this->fail();
}

$filesystem->expects($this->once())
->method('writeStream')
->willReturnCallback(static function (string $file, $handle) {
// adapter closes the stream itself after writing it to file
fclose($handle);
});

$wrapper->stream_close();
$this->assertIsClosedResource($current->handle);
}
}