Skip to content

Commit 4bd18db

Browse files
committed
Remove custom error handler in mbstring tests
To make it more obvious what is tested and what the error messages are.
1 parent 94d5093 commit 4bd18db

11 files changed

+105
-111
lines changed

ext/mbstring/tests/bug20087.phpt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ Bug #20087 (Assertion failure)
44
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
55
--FILE--
66
<?php
7-
ini_set('include_path', dirname(__FILE__));
8-
include_once('common.inc');
97
$testmoo = "blah blah";
108
var_dump(mb_parse_str("testmoo"));
119
var_dump($testmoo);
1210
var_dump(mb_parse_str("test=moo"));
1311
var_dump($test);
1412
?>
15-
--EXPECT--
16-
ERR: Deprecated
13+
--EXPECTF--
14+
Deprecated: mb_parse_str(): Calling mb_parse_str() without the result argument is deprecated in %s on line %d
1715
bool(true)
1816
string(0) ""
19-
ERR: Deprecated
17+
18+
Deprecated: mb_parse_str(): Calling mb_parse_str() without the result argument is deprecated in %s on line %d
2019
bool(true)
2120
string(3) "moo"

ext/mbstring/tests/common.inc

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,6 @@
33
* Common definition and Settings
44
*/
55

6-
// Custom Error Hanlder for testing
7-
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
8-
global $debug;
9-
10-
$err_type = array (
11-
1 => "Error", // E_ERROR
12-
2 => "Warning", // E_WARINING
13-
4 => "Parsing Error", // E_PARSE
14-
8 => "Notice", // E_NOTICE
15-
16 => "Core Error", // E_CORE_ERROR
16-
32 => "Core Warning", // E_CORE_WARNING
17-
64 => "Compile Error", // E_COMPILE_ERROR
18-
128 => "Compile Warning", // E_COMPILE_WARNING
19-
256 => "User Error", // E_USER_ERROR
20-
512 => "User Warning", // E_USER_WARMING
21-
1024=> "User Notice", // E_USER_NOTICE
22-
2048=> "Strict Notice", // E_STRICT
23-
4096=> "Recoverable fatal error", // E_RECOVERABLE_ERROR
24-
8192=> "Deprecated", // E_DEPRECATED
25-
);
26-
27-
if (!empty($debug)) {
28-
printf("%s: %s (%d)\n", $err_type[$err_no], $err_msg, $linenum);
29-
}
30-
else {
31-
printf("ERR: %s\n",$err_type[$err_no]);
32-
}
33-
}
34-
35-
set_error_handler('test_error_handler');
36-
37-
386
// Var def for testing
397
$t_ary = array(
408
's1' => '日本語EUC-JPの文字列',

ext/mbstring/tests/mb_convert_encoding.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ mbstring.language=Japanese
88
--FILE--
99
<?php
1010
// TODO: Add more tests
11-
//$debug = true; // Uncomment this line to view error/warning/notice message in *.out file
12-
ini_set('include_path', dirname(__FILE__));
13-
include_once('common.inc');
1411

1512
// SJIS string (BASE64 encoded)
1613
$sjis = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
@@ -108,7 +105,7 @@ print("MP: $s\n"); // Missing parameter
108105

109106

110107
?>
111-
--EXPECT--
108+
--EXPECTF--
112109
== BASIC TEST ==
113110
EUC-JP: 日本語テキストです。0123456789。
114111
EUC-JP: 日本語テキストです。0123456789。
@@ -129,7 +126,9 @@ JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
129126
== INVALID PARAMETER ==
130127
INT: 1234
131128
EUC-JP:
132-
ERR: Warning
129+
130+
Warning: mb_convert_encoding(): Unknown encoding "BAD" in %s on line %d
133131
BAD:
134-
ERR: Warning
132+
133+
Warning: mb_convert_encoding() expects at least 2 parameters, 1 given in %s on line %d
135134
MP:

ext/mbstring/tests/mb_detect_encoding.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ mbstring.language=Japanese
77
--FILE--
88
<?php
99
// TODO: Add more tests
10-
//$debug = true; // Uncomment this line to view error/warning/notice message in *.out file
11-
ini_set('include_path', dirname(__FILE__));
12-
include_once('common.inc');
1310

1411
// SJIS string (BASE64 encoded)
1512
$sjis = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
@@ -96,7 +93,7 @@ print("MP: $s\n"); // Missing parameter
9693

9794

9895
?>
99-
--EXPECT--
96+
--EXPECTF--
10097
== BASIC TEST ==
10198
SJIS: SJIS
10299
JIS: JIS
@@ -113,7 +110,9 @@ SJIS: SJIS
113110
== INVALID PARAMETER ==
114111
INT: EUC-JP
115112
EUC-JP: EUC-JP
116-
ERR: Warning
113+
114+
Warning: mb_detect_encoding(): Illegal argument in %s on line %d
117115
BAD: EUC-JP
118-
ERR: Warning
116+
117+
Warning: mb_detect_encoding() expects at least 1 parameter, 0 given in %s on line %d
119118
MP:

ext/mbstring/tests/mb_http_output.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mb_http_output()
55
--FILE--
66
<?php
77
//TODO: Add more encoding. Wrong parameter type test.
8-
//$debug = true;
98
ini_set('include_path', dirname(__FILE__));
109
include_once('common.inc');
1110

@@ -59,7 +58,7 @@ $enc = mb_http_output();
5958
print "$enc\n";
6059

6160
?>
62-
--EXPECT--
61+
--EXPECTF--
6362
OK_ASCII_SET
6463
ASCII
6564
OK_SJIS_SET
@@ -71,12 +70,15 @@ UTF-8
7170
OK_EUC-JP_SET
7271
EUC-JP
7372
== INVALID PARAMETER ==
74-
ERR: Warning
73+
74+
Warning: mb_http_output(): Unknown encoding "BAD_NAME" in %s on line %d
7575
OK_BAD_SET
7676
EUC-JP
77-
ERR: Warning
77+
78+
Warning: mb_http_output() expects parameter 1 to be string, array given in %s on line %d
7879
OK_BAD_ARY_SET
7980
EUC-JP
80-
ERR: Warning
81+
82+
Warning: mb_http_output() expects parameter 1 to be string, object given in %s on line %d
8183
OK_BAD_OBJ_SET
8284
EUC-JP

ext/mbstring/tests/mb_internal_encoding.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mb_internal_encoding()
55
--FILE--
66
<?php
77
// TODO:
8-
//$debug = true;
98
ini_set('include_path', dirname(__FILE__));
109
include_once('common.inc');
1110

@@ -47,20 +46,23 @@ $enc = mb_internal_encoding();
4746
print "$enc\n";
4847

4948
?>
50-
--EXPECT--
49+
--EXPECTF--
5150
OK_EUC-JP_SET
5251
EUC-JP
5352
OK_UTF-8_SET
5453
UTF-8
5554
OK_ASCII_SET
5655
ASCII
5756
== INVALID PARAMETER ==
58-
ERR: Warning
57+
58+
Warning: mb_internal_encoding(): Unknown encoding "BAD" in %s on line %d
5959
OK_BAD_SET
6060
ASCII
61-
ERR: Warning
61+
62+
Warning: mb_internal_encoding() expects parameter 1 to be string, array given in %s on line %d
6263
OK_BAD_ARY_SET
6364
ASCII
64-
ERR: Warning
65+
66+
Warning: mb_internal_encoding() expects parameter 1 to be string, object given in %s on line %d
6567
OK_BAD_OBJ_SET
6668
ASCII

ext/mbstring/tests/mb_strimwidth.phpt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ output_handler=
77
--FILE--
88
<?php
99
// TODO: Add more encoding
10-
//$debug = true;
11-
ini_set('include_path', dirname(__FILE__));
12-
include_once('common.inc');
1310

1411
// EUC-JP
1512
$euc_jp = '0123この文字列は日本語です。EUC-JPを使っています。日本語は面倒臭い。';
@@ -37,7 +34,7 @@ $str = mb_strimwidth($euc_jp, -10, -12,'...','EUC-JP');
3734
($str === FALSE) ? print "13 OK\n" : print "NG: $str\n";
3835

3936
?>
40-
--EXPECT--
37+
--EXPECTF--
4138
String width: 68
4239
1: 0123この文字...
4340
2: 0123この文字列は日本語です。EUC-JPを使っています。日本語は面倒臭い。
@@ -46,11 +43,15 @@ String width: 68
4643
5: 。
4744
6: 。
4845
7: 。
49-
ERR: Warning
46+
47+
Warning: mb_strimwidth(): Width is out of range in %s on line %d
5048
10 OK
51-
ERR: Warning
49+
50+
Warning: mb_strimwidth(): Start position is out of range in %s on line %d
5251
11 OK
53-
ERR: Warning
52+
53+
Warning: mb_strimwidth(): Start position is out of range in %s on line %d
5454
12 OK
55-
ERR: Warning
55+
56+
Warning: mb_strimwidth(): Width is out of range in %s on line %d
5657
13 OK

ext/mbstring/tests/mb_stripos.phpt

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mb_stripos()
66
<?php
77
// TODO: Add more encodings
88

9-
//$debug=true;
109
ini_set('include_path','.');
1110
include_once('common.inc');
1211

@@ -140,7 +139,7 @@ $r = mb_stripos($euc_jp, $t_obj, 'BAD_ENCODING');
140139
($r === NULL) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
141140
?>
142141
==DONE==
143-
--EXPECT--
142+
--EXPECTF--
144143
String len: 43
145144
== POSITIVE OFFSET ==
146145
10
@@ -158,25 +157,35 @@ String len: 43
158157
30
159158
0
160159
== INVALID OFFSET ==
161-
ERR: Warning
160+
161+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
162162
OK_INVALID_OFFSET
163-
ERR: Warning
163+
164+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
164165
OK_INVALID_OFFSET
165-
ERR: Warning
166+
167+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
166168
OK_INVALID_OFFSET
167-
ERR: Warning
169+
170+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
168171
OK_INVALID_OFFSET
169-
ERR: Warning
172+
173+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
170174
OK_INVALID_OFFSET
171-
ERR: Warning
175+
176+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
172177
OK_INVALID_OFFSET
173-
ERR: Warning
178+
179+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
174180
OK_INVALID_OFFSET
175-
ERR: Warning
181+
182+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
176183
OK_INVALID_OFFSET
177-
ERR: Warning
184+
185+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
178186
OK_INVALID_OFFSET
179-
ERR: Warning
187+
188+
Warning: mb_stripos(): Offset not contained in string in %s on line %d
180189
OK_INVALID_OFFSET
181190
== OUT OF RANGE ==
182191
OK_OUT_RANGE
@@ -205,12 +214,16 @@ OK_NEWLINE
205214
OK_STR
206215
OK_NEWLINE
207216
== INVALID PARAMETER TEST ==
208-
ERR: Warning
217+
218+
Warning: mb_stripos() expects parameter 3 to be int, string given in %s on line %d
209219
OK_NULL
210-
ERR: Warning
220+
221+
Warning: mb_stripos() expects parameter 2 to be string, array given in %s on line %d
211222
OK_ARRAY
212-
ERR: Warning
223+
224+
Warning: mb_stripos() expects parameter 2 to be string, object given in %s on line %d
213225
OK_OBJECT
214-
ERR: Warning
226+
227+
Warning: mb_stripos() expects parameter 2 to be string, object given in %s on line %d
215228
OK_BAD_ENCODING
216229
==DONE==

ext/mbstring/tests/mb_strlen.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mbstring.func_overload=0
88
<?php
99
// TODO: Add more encodings
1010

11-
//$debug=true;
1211
ini_set('include_path', dirname(__FILE__));
1312
include_once('common.inc');
1413

@@ -70,10 +69,8 @@ $r = mb_strlen($euc_jp, 'BAD_NAME');
7069
echo $r."\n";
7170

7271

73-
74-
7572
?>
76-
--EXPECT--
73+
--EXPECTF--
7774
== ASCII ==
7875
40
7976
40
@@ -90,8 +87,11 @@ echo $r."\n";
9087
43
9188
101
9289
== WRONG PARAMETERS ==
93-
ERR: Warning
9490

95-
ERR: Warning
91+
Warning: strlen() expects parameter 1 to be string, array given in %s on line %d
92+
93+
94+
Warning: strlen() expects parameter 1 to be string, object given in %s on line %d
95+
9696

97-
ERR: Warning
97+
Warning: mb_strlen(): Unknown encoding "BAD_NAME" in %s on line %d

0 commit comments

Comments
 (0)