1
0
mirror of https://github.com/danog/file.git synced 2024-11-29 20:09:10 +01:00

Avoid warning when writing an empty string with eio

No warning emitted from uv, but there's also no reason to call uv_fs_write().
This commit is contained in:
Aaron Piotrowski 2019-01-07 11:32:42 -06:00
parent 8cfe851cd2
commit 94c3bb631c
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 23 additions and 0 deletions

View File

@ -132,6 +132,10 @@ class EioHandle implements Handle
{ {
$length = \strlen($data); $length = \strlen($data);
if ($length === 0) {
return new Success(0);
}
$deferred = new Deferred; $deferred = new Deferred;
$this->poll->listen($deferred->promise()); $this->poll->listen($deferred->promise());

View File

@ -150,6 +150,10 @@ class UvHandle implements Handle
{ {
$length = \strlen($data); $length = \strlen($data);
if ($length === 0) {
return new Success(0);
}
$deferred = new Deferred; $deferred = new Deferred;
$this->poll->listen($deferred->promise()); $this->poll->listen($deferred->promise());

View File

@ -41,6 +41,21 @@ abstract class HandleTest extends TestCase
}); });
} }
public function testEmptyWrite()
{
$this->execute(function () {
$path = Fixture::path() . "/write";
$handle = yield File\open($path, "c+");
$this->assertSame(0, $handle->tell());
yield $handle->write("");
$this->assertSame(0, $handle->tell());
yield $handle->close();
});
}
public function testWriteAfterClose() public function testWriteAfterClose()
{ {
$this->execute(function () { $this->execute(function () {