Skip to content

Commit 6b19f37

Browse files
committed
Update test suite to improve PHP 8.4+ support
1 parent 9dcf6c6 commit 6b19f37

10 files changed

+157
-1
lines changed

tests/FunctionAnyTestRejectedShouldReportUnhandled.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Calling any() with rejected promises should report unhandled rejection
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID > 80300) die("Skipped: PHP < 8.4 only."); ?>
35
--INI--
46
# suppress legacy PHPUnit 7 warning for Xdebug 3
57
xdebug.default_enable=
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Calling any() with rejected promises should report unhandled rejection
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?>
5+
--INI--
6+
# suppress legacy PHPUnit 7 warning for Xdebug 3
7+
xdebug.default_enable=
8+
--FILE--
9+
<?php
10+
11+
use function React\Promise\any;
12+
use function React\Promise\reject;
13+
14+
require __DIR__ . '/../vendor/autoload.php';
15+
16+
any([
17+
reject(new RuntimeException('foo')),
18+
reject(new RuntimeException('bar'))
19+
]);
20+
21+
?>
22+
--EXPECTF--
23+
Unhandled promise rejection with React\Promise\Exception\CompositeException: All promises rejected. in %s:%d
24+
Stack trace:
25+
#0 %s/src/Promise.php(%d): {closure:%s:%d}(%S)
26+
#1 %s/src/Promise.php(%d): React\Promise\Promise->call(%S)
27+
#2 %s/src/functions.php(%d): React\Promise\Promise->__construct(%S)
28+
#3 %s(%d): React\Promise\any(%S)
29+
#4 %A
30+
#5 {main}

tests/FunctionRejectTestFinallyThatThrowsNewExceptionShouldReportUnhandledForNewExceptionOnly.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Calling reject() and then finally() should call handler and report unhandled rejection for new exception from handler
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID > 80300) die("Skipped: PHP < 8.4 only."); ?>
35
--INI--
46
# suppress legacy PHPUnit 7 warning for Xdebug 3
57
xdebug.default_enable=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Calling reject() and then finally() should call handler and report unhandled rejection for new exception from handler
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?>
5+
--INI--
6+
# suppress legacy PHPUnit 7 warning for Xdebug 3
7+
xdebug.default_enable=
8+
--FILE--
9+
<?php
10+
11+
use function React\Promise\reject;
12+
13+
require __DIR__ . '/../vendor/autoload.php';
14+
15+
reject(new RuntimeException('foo'))->finally(function (): void {
16+
throw new \RuntimeException('Finally!');
17+
});
18+
19+
?>
20+
--EXPECTF--
21+
Unhandled promise rejection with RuntimeException: Finally! in %s:%d
22+
Stack trace:
23+
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S)
24+
#1 %s/src/Internal/RejectedPromise.php(%d): React\Promise\Internal\RejectedPromise->{closure:%s:%d}(%S)
25+
#2 %s/src/Internal/RejectedPromise.php(%d): React\Promise\Internal\RejectedPromise->then(%S)
26+
#3 %s(%d): React\Promise\Internal\RejectedPromise->finally(%S)
27+
#4 %A
28+
#5 {main}

tests/FunctionRejectTestThenMatchingThatThrowsNewExceptionShouldReportUnhandledRejectionForNewExceptionOnly.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Calling reject() and then then() should report unhandled rejection for new exception from handler
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID > 80300) die("Skipped: PHP < 8.4 only."); ?>
35
--INI--
46
# suppress legacy PHPUnit 7 warning for Xdebug 3
57
xdebug.default_enable=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Calling reject() and then then() should report unhandled rejection for new exception from handler
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?>
5+
--INI--
6+
# suppress legacy PHPUnit 7 warning for Xdebug 3
7+
xdebug.default_enable=
8+
--FILE--
9+
<?php
10+
11+
use function React\Promise\reject;
12+
13+
require __DIR__ . '/../vendor/autoload.php';
14+
15+
reject(new RuntimeException('foo'))->then(null, function () {
16+
throw new \RuntimeException('bar');
17+
});
18+
19+
?>
20+
--EXPECTF--
21+
Unhandled promise rejection with RuntimeException: bar in %s:%d
22+
Stack trace:
23+
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S)
24+
#1 %s(%d): React\Promise\Internal\RejectedPromise->then(%S)
25+
#2 %A
26+
#3 {main}

tests/FunctionRejectTestThenMismatchThrowsTypeErrorAndShouldReportUnhandledForTypeErrorOnlyOnPhp8.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Calling reject() and then then() with invalid type should report unhandled rejection for TypeError
33
--SKIPIF--
4-
<?php if (PHP_VERSION_ID < 80000) die("Skipped: PHP 8+ only."); ?>
4+
<?php if (PHP_VERSION_ID < 80000 || PHP_VERSION_ID > 80300) die("Skipped: PHP 8.0 - PHP 8.3 only."); ?>
55
--INI--
66
# suppress legacy PHPUnit 7 warning for Xdebug 3
77
xdebug.default_enable=
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Calling reject() and then then() with invalid type should report unhandled rejection for TypeError
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?>
5+
--INI--
6+
# suppress legacy PHPUnit 7 warning for Xdebug 3
7+
xdebug.default_enable=
8+
--FILE--
9+
<?php
10+
11+
use function React\Promise\reject;
12+
13+
require __DIR__ . '/../vendor/autoload.php';
14+
15+
reject(new RuntimeException('foo'))->then(null, function (UnexpectedValueException $unexpected): void { // @phpstan-ignore-line
16+
echo 'This will never be shown because the types do not match' . PHP_EOL;
17+
});
18+
19+
?>
20+
--EXPECTF--
21+
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
22+
Stack trace:
23+
#0 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S)
24+
#1 %s(%d): React\Promise\Internal\RejectedPromise->then(%S)
25+
#2 %A
26+
#3 {main}

tests/FunctionSetRejectionHandlerThatTriggersErrorHandlerThatThrowsShouldTerminateProgramForUnhandled.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
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
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID > 80300) die("Skipped: PHP < 8.4 only."); ?>
35
--INI--
46
# suppress legacy PHPUnit 7 warning for Xdebug 3
57
xdebug.default_enable=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
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
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80400) die("Skipped: PHP 8.4+ only."); ?>
5+
--INI--
6+
# suppress legacy PHPUnit 7 warning for Xdebug 3
7+
xdebug.default_enable=
8+
--FILE--
9+
<?php
10+
11+
use function React\Promise\reject;
12+
use function React\Promise\set_rejection_handler;
13+
14+
require __DIR__ . '/../vendor/autoload.php';
15+
16+
set_error_handler(function (int $_, string $errstr): void {
17+
throw new \OverflowException('This function should never throw');
18+
});
19+
20+
set_rejection_handler(function (Throwable $e): void {
21+
trigger_error($e->getMessage(), E_USER_ERROR);
22+
});
23+
24+
reject(new RuntimeException('foo'));
25+
26+
echo 'NEVER';
27+
28+
?>
29+
--EXPECTF--
30+
Fatal error: Uncaught OverflowException from unhandled promise rejection handler: This function should never throw in %s:%d
31+
Stack trace:
32+
#0 [internal function]: {closure:%s:%d}(%S)
33+
#1 %s(%d): trigger_error(%S)
34+
#2 %s/src/Internal/RejectedPromise.php(%d): {closure:%s:%d}(%S)
35+
#3 %s/src/functions.php(%d): React\Promise\Internal\RejectedPromise->__destruct()
36+
#4 %s(%d): React\Promise\reject(%S)
37+
#5 %A
38+
#6 {main}

0 commit comments

Comments
 (0)