-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from clue-labs/report-unhandled
Report any unhandled promise rejections
- Loading branch information
Showing
36 changed files
with
658 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ parameters: | |
paths: | ||
- src/ | ||
- tests/ | ||
|
||
fileExtensions: | ||
- php | ||
- phpt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/DeferredTestCancelNoopThenRejectShouldNotReportUnhandled.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Calling cancel() and then reject() should not report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use React\Promise\Deferred; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$deferred = new Deferred(); | ||
$deferred->promise()->cancel(); | ||
$deferred->reject(new RuntimeException('foo')); | ||
|
||
echo 'void' . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
void |
20 changes: 20 additions & 0 deletions
20
tests/DeferredTestCancelThatRejectsShouldNotReportUnhandled.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Calling cancel() that rejects should not report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use React\Promise\Deferred; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$deferred = new Deferred(function () { throw new \RuntimeException('Cancelled'); }); | ||
$deferred->promise()->cancel(); | ||
|
||
echo 'void' . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Calling reject() without any handlers should report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use React\Promise\Deferred; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$deferred = new Deferred(); | ||
$deferred->reject(new RuntimeException('foo')); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with RuntimeException: foo in %s:%d | ||
Stack trace: | ||
#0 %A{main} |
21 changes: 21 additions & 0 deletions
21
tests/DeferredTestRejectThenCancelShouldNotReportUnhandled.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Calling reject() and then cancel() should not report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use React\Promise\Deferred; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$deferred = new Deferred(); | ||
$deferred->reject(new RuntimeException('foo')); | ||
$deferred->promise()->cancel(); | ||
|
||
echo 'void' . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
Calling all() with rejected promises should report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\all; | ||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
all([ | ||
reject(new RuntimeException('foo')), | ||
reject(new RuntimeException('bar')) | ||
]); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with RuntimeException: foo in %s:%d | ||
Stack trace: | ||
#0 %A{main} |
23 changes: 23 additions & 0 deletions
23
tests/FunctionAllTestRejectedThenMatchingThatReturnsShouldNotReportUnhandled.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
Calling all() and then then() should not report unhandled rejection | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\all; | ||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
all([ | ||
reject(new RuntimeException('foo')), | ||
reject(new RuntimeException('bar')) | ||
])->then(null, function (\Throwable $e) { | ||
echo 'Handled ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL; | ||
}); | ||
|
||
?> | ||
--EXPECT-- | ||
Handled RuntimeException: foo |
Oops, something went wrong.