diff --git a/composer.json b/composer.json index 181f2d88..638ac426 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "react/promise": "^3.0 || ^2.7 || ^1.2.1" }, "require-dev": { - "phpunit/phpunit": "^9.5 || ^4.8.35", + "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35", "react/async": "^4 || ^3 || ^2", "react/promise-timer": "^1.9" }, diff --git a/tests/FunctionalResolverTest.php b/tests/FunctionalResolverTest.php index 989bf347..fab08332 100644 --- a/tests/FunctionalResolverTest.php +++ b/tests/FunctionalResolverTest.php @@ -187,6 +187,9 @@ public function testResolveShouldNotCauseGarbageReferencesWhenUsingInvalidNamese gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->resolver->resolve('google.com'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + unset($promise); $this->assertEquals(0, gc_collect_cycles()); @@ -205,6 +208,9 @@ public function testResolveCachedShouldNotCauseGarbageReferencesWhenUsingInvalid gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->resolver->resolve('google.com'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + unset($promise); $this->assertEquals(0, gc_collect_cycles()); diff --git a/tests/Query/CoopExecutorTest.php b/tests/Query/CoopExecutorTest.php index 44ea9676..c43c273d 100644 --- a/tests/Query/CoopExecutorTest.php +++ b/tests/Query/CoopExecutorTest.php @@ -107,7 +107,9 @@ public function testQueryTwiceWillPassExactQueryToBaseExecutorTwiceWhenFirstQuer $connector = new CoopExecutor($base); - $connector->query($query); + $promise = $connector->query($query); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $deferred->reject(new RuntimeException()); diff --git a/tests/Query/RetryExecutorTest.php b/tests/Query/RetryExecutorTest.php index 37ea0b6c..9de9c04b 100644 --- a/tests/Query/RetryExecutorTest.php +++ b/tests/Query/RetryExecutorTest.php @@ -258,7 +258,9 @@ public function queryShouldNotCauseGarbageReferencesOnTimeoutErrors() gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); - $retryExecutor->query($query); + $promise = $retryExecutor->query($query); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->assertEquals(0, gc_collect_cycles()); } @@ -322,7 +324,9 @@ public function queryShouldNotCauseGarbageReferencesOnNonTimeoutErrors() gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); - $retryExecutor->query($query); + $promise = $retryExecutor->query($query); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->assertEquals(0, gc_collect_cycles()); } diff --git a/tests/Query/SelectiveTransportExecutorTest.php b/tests/Query/SelectiveTransportExecutorTest.php index 9e0e0c84..6b1cc35b 100644 --- a/tests/Query/SelectiveTransportExecutorTest.php +++ b/tests/Query/SelectiveTransportExecutorTest.php @@ -226,6 +226,9 @@ public function testRejectedPromiseAfterTruncatedResponseShouldNotCreateAnyGarba gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->executor->query($query); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + unset($promise); $this->assertEquals(0, gc_collect_cycles()); diff --git a/tests/Query/TcpTransportExecutorTest.php b/tests/Query/TcpTransportExecutorTest.php index 202fdbce..33dddacd 100644 --- a/tests/Query/TcpTransportExecutorTest.php +++ b/tests/Query/TcpTransportExecutorTest.php @@ -370,8 +370,12 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith $query = new Query('google' . str_repeat('.com', 100), Message::TYPE_A, Message::CLASS_IN); // send a bunch of queries and keep reference to last promise + $exception = null; for ($i = 0; $i < 2000; ++$i) { $promise = $executor->query($query); + $promise->then(null, function (\Exception $reason) use (&$exception) { + $exception = $reason; + }); } $client = stream_socket_accept($server); @@ -399,11 +403,6 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith restore_error_handler(); $this->assertNull($error); - $exception = null; - $promise->then(null, function ($reason) use (&$exception) { - $exception = $reason; - }); - // expect EPIPE (Broken pipe), except for macOS kernel race condition or legacy HHVM $this->setExpectedException( 'RuntimeException', @@ -472,7 +471,6 @@ public function testQueryKeepsPendingIfServerSendsIncompleteMessageLength() null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -509,7 +507,6 @@ public function testQueryKeepsPendingIfServerSendsIncompleteMessageBody() null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); diff --git a/tests/Query/UdpTransportExecutorTest.php b/tests/Query/UdpTransportExecutorTest.php index 81cf9497..3f04d9ad 100644 --- a/tests/Query/UdpTransportExecutorTest.php +++ b/tests/Query/UdpTransportExecutorTest.php @@ -269,7 +269,6 @@ public function testQueryKeepsPendingIfServerSendsInvalidMessage() null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -307,7 +306,6 @@ public function testQueryKeepsPendingIfServerSendsInvalidId() null, function ($e) use (&$wait) { $wait = false; - throw $e; } );