Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test suite to avoid unhandled promise rejections #66

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/FunctionRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 14 additions & 2 deletions tests/FunctionTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down