Skip to content

Commit 7918d5b

Browse files
committed
Update test suite to avoid unhandled promise rejections
1 parent 252f37e commit 7918d5b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

tests/FunctionRejectTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function testWaitingForPromiseToRejectDoesNotLeaveGarbageCycles()
5858
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
5959

6060
$promise = Timer\reject(0.01);
61+
62+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
63+
64+
Loop::run();
65+
6166
unset($promise);
6267

6368
$this->assertEquals(0, gc_collect_cycles());

tests/FunctionTimeoutTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function testRejectedWillNotStartTimer()
5252
{
5353
$promise = Promise\reject(new \Exception('reject'));
5454

55-
Timer\timeout($promise, 3);
55+
$promise = Timer\timeout($promise, 3);
56+
57+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
5658

5759
$time = microtime(true);
5860
Loop::run();
@@ -83,7 +85,9 @@ public function testPendingCancellableWillBeCancelledThroughFollowerOnTimeout()
8385
$promise = $this->getMockBuilder($cancellableInterface)->getMock();
8486
$promise->expects($this->once())->method('then')->willReturn($cancellable);
8587

86-
Timer\timeout($promise, 0.01);
88+
$promise = Timer\timeout($promise, 0.01);
89+
90+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
8791

8892
Loop::run();
8993
}
@@ -210,6 +214,8 @@ public function testWaitingForPromiseToRejectBeforeTimeoutDoesNotLeaveGarbageCyc
210214

211215
$promise = Timer\timeout($promise, 1.0);
212216

217+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
218+
213219
Loop::run();
214220
unset($promise);
215221

@@ -230,6 +236,8 @@ public function testWaitingForPromiseToTimeoutDoesNotLeaveGarbageCycles()
230236

231237
$promise = Timer\timeout($promise, 0.01);
232238

239+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
240+
233241
Loop::run();
234242
unset($promise);
235243

@@ -248,6 +256,8 @@ public function testWaitingForPromiseToTimeoutWithoutCancellerDoesNotLeaveGarbag
248256

249257
$promise = Timer\timeout($promise, 0.01);
250258

259+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
260+
251261
Loop::run();
252262
unset($promise);
253263

@@ -268,6 +278,8 @@ public function testWaitingForPromiseToTimeoutWithNoOpCancellerDoesNotLeaveGarba
268278

269279
$promise = Timer\timeout($promise, 0.01);
270280

281+
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
282+
271283
Loop::run();
272284
unset($promise);
273285

0 commit comments

Comments
 (0)