Skip to content

Commit 52b1841

Browse files
committed
Catch some exceptions in tests
To avoid printing arguments in exception backtrace. This reduces false positives for GH-5366.
1 parent e631ea4 commit 52b1841

File tree

3 files changed

+22
-50
lines changed

3 files changed

+22
-50
lines changed

ext/intl/tests/calendar_isWeekend_error.phpt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ date.timezone=Atlantic/Azores
66
<?php
77
if (!extension_loaded('intl'))
88
die('skip intl extension not enabled');
9+
?>
910
--FILE--
1011
<?php
1112
ini_set("intl.error_level", E_WARNING);
1213

13-
var_dump(intlcal_is_weekend(1));
14-
--EXPECTF--
15-
Fatal error: Uncaught TypeError: intlcal_is_weekend(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d
16-
Stack trace:
17-
#0 %s(%d): intlcal_is_weekend(1)
18-
#1 {main}
19-
thrown in %s on line %d
14+
try {
15+
var_dump(intlcal_is_weekend(1));
16+
} catch (TypeError $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
?>
20+
--EXPECT--
21+
intlcal_is_weekend(): Argument #1 ($calendar) must be of type IntlCalendar, int given

ext/json/tests/json_encode_exceptions.phpt

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Test json_encode() function : JSON_THROW_ON_ERROR flag
88
try {
99
var_dump(json_encode("\x80", JSON_THROW_ON_ERROR));
1010
} catch (JsonException $e) {
11-
var_dump($e);
11+
echo "[{$e->getCode()}] {$e->getMessage()}\n";
1212
}
1313

1414
// JSON_PARTIAL_OUTPUT_ON_ERROR is incompatible with exceptions
@@ -19,40 +19,8 @@ var_dump(json_last_error());
1919
var_dump(json_last_error_msg());
2020

2121
?>
22-
--EXPECTF--
23-
object(JsonException)#1 (7) {
24-
["message":protected]=>
25-
string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
26-
["string":"Exception":private]=>
27-
string(0) ""
28-
["code":protected]=>
29-
int(5)
30-
["file":protected]=>
31-
string(%d) "%s"
32-
["line":protected]=>
33-
int(%d)
34-
["trace":"Exception":private]=>
35-
array(1) {
36-
[0]=>
37-
array(4) {
38-
["file"]=>
39-
string(%d) "%s"
40-
["line"]=>
41-
int(%d)
42-
["function"]=>
43-
string(11) "json_encode"
44-
["args"]=>
45-
array(2) {
46-
[0]=>
47-
string(1) "%s"
48-
[1]=>
49-
int(4194304)
50-
}
51-
}
52-
}
53-
["previous":"Exception":private]=>
54-
NULL
55-
}
22+
--EXPECT--
23+
[5] Malformed UTF-8 characters, possibly incorrectly encoded
5624
string(4) "null"
5725
int(5)
5826
string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"

ext/session/tests/session_module_name_variation3.phpt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function gc($maxlifetime) { return true; }
3131
var_dump(session_module_name("files"));
3232
session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
3333
var_dump(session_module_name());
34-
var_dump(session_start());
34+
try {
35+
var_dump(session_start());
36+
} catch (Exception $e) {
37+
echo $e->getMessage(), "\n";
38+
}
3539
var_dump(session_module_name());
3640
var_dump(session_destroy());
3741

@@ -42,11 +46,9 @@ ob_end_flush();
4246
string(5) "files"
4347
string(4) "user"
4448

45-
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line 25
49+
Warning: session_start(): Failed to initialize storage module: user (path: ) in %s on line %d
50+
Stop...!
51+
string(4) "user"
4652

47-
Fatal error: Uncaught Exception: Stop...! in %s:13
48-
Stack trace:
49-
#0 [internal function]: open('', 'PHPSESSID')
50-
#1 %s(25): session_start()
51-
#2 {main}
52-
thrown in %s on line 13
53+
Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d
54+
bool(false)

0 commit comments

Comments
 (0)