From 784c55a32d7b7c19b9bfa7a6caacd115b7b12374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 29 Jun 2023 00:20:35 +0200 Subject: [PATCH] Update test suite to avoid unhandled promise rejections --- tests/FunctionRejectTest.php | 5 +++++ tests/FunctionTimeoutTest.php | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/FunctionRejectTest.php b/tests/FunctionRejectTest.php index f5ddcbf..676c0b1 100644 --- a/tests/FunctionRejectTest.php +++ b/tests/FunctionRejectTest.php @@ -58,6 +58,11 @@ public function testWaitingForPromiseToRejectDoesNotLeaveGarbageCycles() gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = Timer\reject(0.01); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + + Loop::run(); + unset($promise); $this->assertEquals(0, gc_collect_cycles()); diff --git a/tests/FunctionTimeoutTest.php b/tests/FunctionTimeoutTest.php index dfe6eb8..af73a42 100644 --- a/tests/FunctionTimeoutTest.php +++ b/tests/FunctionTimeoutTest.php @@ -52,7 +52,9 @@ public function testRejectedWillNotStartTimer() { $promise = Promise\reject(new \Exception('reject')); - Timer\timeout($promise, 3); + $promise = Timer\timeout($promise, 3); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $time = microtime(true); Loop::run(); @@ -83,7 +85,9 @@ public function testPendingCancellableWillBeCancelledThroughFollowerOnTimeout() $promise = $this->getMockBuilder($cancellableInterface)->getMock(); $promise->expects($this->once())->method('then')->willReturn($cancellable); - Timer\timeout($promise, 0.01); + $promise = Timer\timeout($promise, 0.01); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection Loop::run(); } @@ -210,6 +214,8 @@ public function testWaitingForPromiseToRejectBeforeTimeoutDoesNotLeaveGarbageCyc $promise = Timer\timeout($promise, 1.0); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + Loop::run(); unset($promise); @@ -230,6 +236,8 @@ public function testWaitingForPromiseToTimeoutDoesNotLeaveGarbageCycles() $promise = Timer\timeout($promise, 0.01); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + Loop::run(); unset($promise); @@ -248,6 +256,8 @@ public function testWaitingForPromiseToTimeoutWithoutCancellerDoesNotLeaveGarbag $promise = Timer\timeout($promise, 0.01); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + Loop::run(); unset($promise); @@ -268,6 +278,8 @@ public function testWaitingForPromiseToTimeoutWithNoOpCancellerDoesNotLeaveGarba $promise = Timer\timeout($promise, 0.01); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + Loop::run(); unset($promise);