From 94c3bb631cce3a46178c19c6f42844255a982714 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 7 Jan 2019 11:32:42 -0600 Subject: [PATCH] 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(). --- lib/EioHandle.php | 4 ++++ lib/UvHandle.php | 4 ++++ test/HandleTest.php | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/EioHandle.php b/lib/EioHandle.php index a4e848a..14adb2f 100644 --- a/lib/EioHandle.php +++ b/lib/EioHandle.php @@ -132,6 +132,10 @@ class EioHandle implements Handle { $length = \strlen($data); + if ($length === 0) { + return new Success(0); + } + $deferred = new Deferred; $this->poll->listen($deferred->promise()); diff --git a/lib/UvHandle.php b/lib/UvHandle.php index b12b23e..d693a76 100644 --- a/lib/UvHandle.php +++ b/lib/UvHandle.php @@ -150,6 +150,10 @@ class UvHandle implements Handle { $length = \strlen($data); + if ($length === 0) { + return new Success(0); + } + $deferred = new Deferred; $this->poll->listen($deferred->promise()); diff --git a/test/HandleTest.php b/test/HandleTest.php index 6f2f4e7..8b5dd14 100644 --- a/test/HandleTest.php +++ b/test/HandleTest.php @@ -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() { $this->execute(function () {