Skip to content

Commit

Permalink
Fix nonexistent files not being created until written to
Browse files Browse the repository at this point in the history
  • Loading branch information
elazar committed Nov 12, 2023
1 parent ac45926 commit 66f6eae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public function stream_open(
$this->log('info', __METHOD__, func_get_args());
$this->path = $path;
$this->mode = $mode;
if (strpbrk($mode, 'waxc') !== false) {
$this->stream_write('');
$this->stream_flush();
}
return true;
}

Expand Down
14 changes: 13 additions & 1 deletion tests/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
ServiceLocator::setInstance($serviceLocator);

$this->logger = new Logger(__FILE__);
$this->logger->pushHandler(new TestHandler);
$this->loggerHandler = new TestHandler;
$this->logger->pushHandler($this->loggerHandler);
ServiceLocator::set(LoggerInterface::class, $this->logger);

$this->registry = ServiceLocator::get(FilesystemRegistry::class);
Expand All @@ -34,6 +35,17 @@
rmdir('fly://foo');
});

it('can copy an empty file', function () {
$success = touch('fly://src');
expect($success)->toBe(true);

$success = copy('fly://src', 'fly://dst');
expect($success)->toBe(true);

$success = file_exists('fly://dst');
expect($success)->toBe(true);
});

it('handles opening a nonexistent directory', function () {
$dir = opendir('fly://foo');
expect($dir)->toBeResource();
Expand Down

0 comments on commit 66f6eae

Please sign in to comment.