-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test suite to improve PHP 8.4+ support
- Loading branch information
1 parent
9dcf6c6
commit 6b19f37
Showing
10 changed files
with
157 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
tests/FunctionAnyTestRejectedShouldReportUnhandledOnPhp84.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,30 @@ | ||
--TEST-- | ||
Calling any() with rejected promises should report unhandled rejection | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?> | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\any; | ||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
any([ | ||
reject(new RuntimeException('foo')), | ||
reject(new RuntimeException('bar')) | ||
]); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with React\Promise\Exception\CompositeException: All promises rejected. in %s:%d | ||
Stack trace: | ||
#0 %s/src/Promise.php(%d): {closure:%s:%d}(%S) | ||
#1 %s/src/Promise.php(%d): React\Promise\Promise->call(%S) | ||
#2 %s/src/functions.php(%d): React\Promise\Promise->__construct(%S) | ||
#3 %s(%d): React\Promise\any(%S) | ||
#4 %A | ||
#5 {main} |
2 changes: 2 additions & 0 deletions
2
...ctionRejectTestFinallyThatThrowsNewExceptionShouldReportUnhandledForNewExceptionOnly.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
28 changes: 28 additions & 0 deletions
28
...jectTestFinallyThatThrowsNewExceptionShouldReportUnhandledForNewExceptionOnlyOnPhp84.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,28 @@ | ||
--TEST-- | ||
Calling reject() and then finally() should call handler and report unhandled rejection for new exception from handler | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?> | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
reject(new RuntimeException('foo'))->finally(function (): void { | ||
throw new \RuntimeException('Finally!'); | ||
}); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with RuntimeException: Finally! in %s:%d | ||
Stack trace: | ||
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S) | ||
#1 %s/src/Internal/RejectedPromise.php(%d): React\Promise\Internal\RejectedPromise->{closure:%s:%d}(%S) | ||
#2 %s/src/Internal/RejectedPromise.php(%d): React\Promise\Internal\RejectedPromise->then(%S) | ||
#3 %s(%d): React\Promise\Internal\RejectedPromise->finally(%S) | ||
#4 %A | ||
#5 {main} |
2 changes: 2 additions & 0 deletions
2
...tThenMatchingThatThrowsNewExceptionShouldReportUnhandledRejectionForNewExceptionOnly.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
26 changes: 26 additions & 0 deletions
26
...tchingThatThrowsNewExceptionShouldReportUnhandledRejectionForNewExceptionOnlyOnPhp84.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,26 @@ | ||
--TEST-- | ||
Calling reject() and then then() should report unhandled rejection for new exception from handler | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?> | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
reject(new RuntimeException('foo'))->then(null, function () { | ||
throw new \RuntimeException('bar'); | ||
}); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with RuntimeException: bar in %s:%d | ||
Stack trace: | ||
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S) | ||
#1 %s(%d): React\Promise\Internal\RejectedPromise->then(%S) | ||
#2 %A | ||
#3 {main} |
2 changes: 1 addition & 1 deletion
2
...nRejectTestThenMismatchThrowsTypeErrorAndShouldReportUnhandledForTypeErrorOnlyOnPhp8.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
26 changes: 26 additions & 0 deletions
26
...RejectTestThenMismatchThrowsTypeErrorAndShouldReportUnhandledForTypeErrorOnlyOnPhp84.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,26 @@ | ||
--TEST-- | ||
Calling reject() and then then() with invalid type should report unhandled rejection for TypeError | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?> | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\reject; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
reject(new RuntimeException('foo'))->then(null, function (UnexpectedValueException $unexpected): void { // @phpstan-ignore-line | ||
echo 'This will never be shown because the types do not match' . PHP_EOL; | ||
}); | ||
|
||
?> | ||
--EXPECTF-- | ||
Unhandled promise rejection with TypeError: {closure:%s:%d}(): Argument #1 ($unexpected) must be of type UnexpectedValueException, RuntimeException given, called in %s/src/Internal/RejectedPromise.php on line %d in %s:%d | ||
Stack trace: | ||
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S) | ||
#1 %s(%d): React\Promise\Internal\RejectedPromise->then(%S) | ||
#2 %A | ||
#3 {main} |
2 changes: 2 additions & 0 deletions
2
...RejectionHandlerThatTriggersErrorHandlerThatThrowsShouldTerminateProgramForUnhandled.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
38 changes: 38 additions & 0 deletions
38
...onHandlerThatTriggersErrorHandlerThatThrowsShouldTerminateProgramForUnhandledOnPhp84.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,38 @@ | ||
--TEST-- | ||
The callback given to set_rejection_handler() may trigger a fatal error which in turn throws an exception which will terminate the program for unhandled rejection | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?> | ||
--INI-- | ||
# suppress legacy PHPUnit 7 warning for Xdebug 3 | ||
xdebug.default_enable= | ||
--FILE-- | ||
<?php | ||
|
||
use function React\Promise\reject; | ||
use function React\Promise\set_rejection_handler; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
set_error_handler(function (int $_, string $errstr): void { | ||
throw new \OverflowException('This function should never throw'); | ||
}); | ||
|
||
set_rejection_handler(function (Throwable $e): void { | ||
trigger_error($e->getMessage(), E_USER_ERROR); | ||
}); | ||
|
||
reject(new RuntimeException('foo')); | ||
|
||
echo 'NEVER'; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught OverflowException from unhandled promise rejection handler: This function should never throw in %s:%d | ||
Stack trace: | ||
#0 [internal function]: {closure:%s:%d}(%S) | ||
#1 %s(%d): trigger_error(%S) | ||
#2 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S) | ||
#3 %s/src/functions.php(%d): React\Promise\Internal\RejectedPromise->__destruct() | ||
#4 %s(%d): React\Promise\reject(%S) | ||
#5 %A | ||
#6 {main} |