diff --git a/src/Io/Factory.php b/src/Io/Factory.php index a760832..c8b2b97 100644 --- a/src/Io/Factory.php +++ b/src/Io/Factory.php @@ -91,6 +91,8 @@ public function createClient(string $uri): PromiseInterface // either close successful connection or cancel pending connection attempt $connecting->then(function (ConnectionInterface $connection) { $connection->close(); + }, function () { + // ignore to avoid reporting unhandled rejection }); assert(\method_exists($connecting, 'cancel')); $connecting->cancel(); diff --git a/src/RedisClient.php b/src/RedisClient.php index 8230294..9ad7027 100644 --- a/src/RedisClient.php +++ b/src/RedisClient.php @@ -220,6 +220,8 @@ public function close(): void if ($this->promise !== null) { $this->promise->then(function (StreamingClient $redis) { $redis->close(); + }, function () { + // ignore to avoid reporting unhandled rejection }); if ($this->promise !== null) { assert(\method_exists($this->promise, 'cancel')); diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index b55309b..be36eda 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -161,15 +161,4 @@ public function testClose(): void $redis->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); } - - public function testCloseLazy(): void - { - $redis = new RedisClient($this->uri, null, $this->loop); - - $redis->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce()); - - $redis->close(); - - $redis->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); - } } diff --git a/tests/Io/FactoryStreamingClientTest.php b/tests/Io/FactoryStreamingClientTest.php index da83302..4df8589 100644 --- a/tests/Io/FactoryStreamingClientTest.php +++ b/tests/Io/FactoryStreamingClientTest.php @@ -57,13 +57,17 @@ public function testCtor(): void public function testWillConnectWithDefaultPort(): void { $this->connector->expects($this->once())->method('connect')->with('redis.example.com:6379')->willReturn(reject(new \RuntimeException())); - $this->factory->createClient('redis.example.com'); + $promise = $this->factory->createClient('redis.example.com'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testWillConnectToLocalhost(): void { $this->connector->expects($this->once())->method('connect')->with('localhost:1337')->willReturn(reject(new \RuntimeException())); - $this->factory->createClient('localhost:1337'); + $promise = $this->factory->createClient('localhost:1337'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testWillResolveIfConnectorResolves(): void diff --git a/tests/RedisClientTest.php b/tests/RedisClientTest.php index 323b3f8..8fc8bab 100644 --- a/tests/RedisClientTest.php +++ b/tests/RedisClientTest.php @@ -161,7 +161,10 @@ public function testPingAfterPreviousFactoryRejectsUnderlyingClientWillCreateNew new Promise(function () { }) ); - $this->redis->ping(); + $promise = $this->redis->ping(); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $deferred->reject($error); $this->redis->ping(); @@ -308,7 +311,10 @@ public function testCloseAfterPingWillEmitCloseWithoutErrorWhenUnderlyingClientC $this->redis->on('error', $this->expectCallableNever()); $this->redis->on('close', $this->expectCallableOnce()); - $this->redis->ping(); + $promise = $this->redis->ping(); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $this->redis->close(); }