Skip to content

Commit 2e04bc5

Browse files
committed
ext/intl: Split error tests out and stop relying on ut_common() testing
1 parent f4ad6ea commit 2e04bc5

36 files changed

+610
-437
lines changed

ext/intl/tests/bug67397.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ intl
55
--FILE--
66
<?php
77

8-
function ut_main()
9-
{
10-
$ret = var_export(ut_loc_get_display_name(str_repeat('*', 256), 'en_us'), true);
11-
$ret .= "\n";
12-
$ret .= var_export(intl_get_error_message(), true);
13-
return $ret;
14-
}
8+
$locale = str_repeat('*', 256);
9+
$dispLocale= 'en_us';
10+
11+
var_dump(Locale::getDisplayName($locale, $dispLocale));
12+
var_dump(intl_get_error_message());
13+
var_dump(locale_get_display_name($locale, $dispLocale));
14+
var_dump(intl_get_error_message());
1515

16-
include_once( 'ut_common.inc' );
17-
ut_run();
1816
?>
1917
--EXPECT--
20-
false
21-
'locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR'
18+
bool(false)
19+
string(65) "locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR"
20+
bool(false)
21+
string(65) "locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/bug72533.phpt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@ intl
55
--FILE--
66
<?php
77

8-
function ut_main()
9-
{
10-
$ret = var_export(ut_loc_accept_http(str_repeat('x', 256)), true);
11-
$ret .= "\n";
12-
if(intl_is_failure(intl_get_error_code())) {
13-
$ret .= var_export(intl_get_error_message(), true);
14-
}
15-
$ret .= "\n";
16-
$ret .= var_export(ut_loc_accept_http(str_repeat('en,', 256)), true);
17-
$ret .= "\n";
18-
if(intl_is_failure(intl_get_error_code())) {
19-
$ret .= var_export(intl_get_error_message(), true);
20-
}
21-
return $ret;
22-
}
23-
24-
include_once( 'ut_common.inc' );
25-
ut_run();
8+
$http = str_repeat('x', 256);
9+
10+
var_dump(Locale::acceptFromHttp($http));
11+
var_dump(intl_get_error_message());
12+
13+
var_dump(locale_accept_from_http($http));
14+
var_dump(intl_get_error_message());
15+
16+
17+
$http = str_repeat('en', 256);
18+
19+
var_dump(Locale::acceptFromHttp($http));
20+
var_dump(intl_get_error_message());
21+
22+
var_dump(locale_accept_from_http($http));
23+
var_dump(intl_get_error_message());
24+
2625
?>
2726
--EXPECT--
28-
false
29-
'locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR'
30-
'en'
27+
bool(false)
28+
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
29+
bool(false)
30+
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
31+
bool(false)
32+
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
33+
bool(false)
34+
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/collator_create4.phpt renamed to ext/intl/tests/collator_create.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
create() icu >= 53.1
2+
Collator creation tests
33
--EXTENSIONS--
44
intl
55
--FILE--
@@ -17,11 +17,9 @@ function ut_main()
1717
$locales = array(
1818
'EN-US-ODESSA',
1919
'UK_UA_ODESSA',
20-
'uk-ua_CALIFORNIA@currency=;currency=GRN',
2120
'',
2221
'root',
2322
'uk@currency=EURO',
24-
'12345678911131517192123252729313335373941434547495153575961636567697173757779818385878991939597991234567891113151719212325272931333537394143454749515357596163656769717375777981838587899193959799'
2523
);
2624

2725
foreach( $locales as $locale )
@@ -62,7 +60,6 @@ Locale: 'UK_UA_ODESSA'
6260
ULOC_REQUESTED_LOCALE = 'UK_UA_ODESSA'
6361
ULOC_VALID_LOCALE = 'uk'
6462
ULOC_ACTUAL_LOCALE = 'uk'
65-
Error creating collator with 'uk-ua_CALIFORNIA@currency=;currency=GRN' locale: collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR
6663
Locale: ''
6764
ULOC_REQUESTED_LOCALE = ''
6865
ULOC_VALID_LOCALE = '%s'
@@ -75,4 +72,3 @@ Locale: 'uk@currency=EURO'
7572
ULOC_REQUESTED_LOCALE = 'uk@currency=EURO'
7673
ULOC_VALID_LOCALE = 'uk'
7774
ULOC_ACTUAL_LOCALE = 'uk'
78-
Error creating collator with '12345678911131517192123252729313335373941434547495153575961636567697173757779818385878991939597991234567891113151719212325272931333537394143454749515357596163656769717375777981838587899193959799' locale: Locale string too long, should be no longer than %d characters: U_ILLEGAL_ARGUMENT_ERROR
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Collator creation errors
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$locales = [
9+
'uk-ua_CALIFORNIA@currency=;currency=GRN',
10+
str_repeat('a', 160),
11+
];
12+
13+
foreach ($locales as $locale) {
14+
try {
15+
$c = new Collator($locale);
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
20+
$c = Collator::create($locale);
21+
var_dump($c);
22+
var_dump(intl_get_error_message());
23+
24+
$c = collator_create($locale);
25+
var_dump($c);
26+
var_dump(intl_get_error_message());
27+
}
28+
29+
?>
30+
--EXPECT--
31+
IntlException: Constructor failed
32+
NULL
33+
string(70) "collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR"
34+
NULL
35+
string(70) "collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR"
36+
IntlException: Constructor failed
37+
NULL
38+
string(89) "Locale string too long, should be no longer than 156 characters: U_ILLEGAL_ARGUMENT_ERROR"
39+
NULL
40+
string(89) "Locale string too long, should be no longer than 156 characters: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/collation_customization.phpt renamed to ext/intl/tests/collator_customization.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ intl
66
<?php
77

88
/*
9-
* Check effects of changing misc collattion options.
9+
* Check effects of changing misc collation options.
1010
*/
1111

12-
13-
function cmp_array( &$coll, $a )
12+
function cmp_array(Collator $coll, $a)
1413
{
1514
$res = '';
1615
$prev = null;
@@ -32,7 +31,7 @@ function cmp_array( &$coll, $a )
3231
return $res;
3332
}
3433

35-
function check_alternate_handling( &$coll )
34+
function check_alternate_handling(Collator $coll)
3635
{
3736
$res = '';
3837

ext/intl/tests/collator_get_error_message.phpt

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Collator get invalid attribute
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$attr = 12345;
9+
10+
$coll = Collator::create('ru_RU');
11+
12+
var_dump($coll->getAttribute($attr));
13+
var_dump($coll->getErrorMessage());
14+
15+
var_dump(collator_get_attribute($coll, $attr));
16+
var_dump(collator_get_error_message($coll));
17+
18+
?>
19+
--EXPECT--
20+
bool(false)
21+
string(55) "Error getting attribute value: U_ILLEGAL_ARGUMENT_ERROR"
22+
bool(false)
23+
string(55) "Error getting attribute value: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/dateformat_formatObject_error.phpt

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,59 @@
22
IntlDateFormatter::formatObject(): error conditions
33
--EXTENSIONS--
44
intl
5+
--INI--
6+
intl.default_locale=pt_PT
7+
date.timezone=Europe/Lisbon
58
--FILE--
69
<?php
7-
ini_set("intl.error_level", E_WARNING);
8-
ini_set("intl.default_locale", "pt_PT");
9-
ini_set("date.timezone", "Europe/Lisbon");
10-
11-
var_dump(IntlDateFormatter::formatObject(new stdclass));
1210

1311
class A extends IntlCalendar {function __construct(){}}
14-
var_dump(IntlDateFormatter::formatObject(new A));
12+
1513
class B extends DateTime {function __construct(){}}
14+
15+
$cal = IntlCalendar::createInstance();
16+
1617
try {
1718
var_dump(IntlDateFormatter::formatObject(new B));
18-
} catch (Error $e) {
19-
echo $e->getMessage(), "\n";
19+
var_dump(intl_get_error_message());
20+
} catch (Throwable $e) {
21+
echo $e::class, ': ', $e->getMessage(), "\n";
2022
}
2123

22-
$cal = IntlCalendar::createInstance();
24+
var_dump(IntlDateFormatter::formatObject(new stdclass));
25+
var_dump(intl_get_error_message());
26+
var_dump(IntlDateFormatter::formatObject(new A));
27+
var_dump(intl_get_error_message());
28+
2329
var_dump(IntlDateFormatter::formatObject($cal, -2));
30+
var_dump(intl_get_error_message());
2431
var_dump(IntlDateFormatter::formatObject($cal, array()));
32+
var_dump(intl_get_error_message());
2533
var_dump(IntlDateFormatter::formatObject($cal, array(1,2,3)));
34+
var_dump(intl_get_error_message());
2635
var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
36+
var_dump(intl_get_error_message());
2737
var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
38+
var_dump(intl_get_error_message());
2839
var_dump(IntlDateFormatter::formatObject($cal, ""));
40+
var_dump(intl_get_error_message());
2941

3042
?>
31-
--EXPECTF--
32-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the passed object must be an instance of either IntlCalendar or DateTimeInterface in %s on line %d
43+
--EXPECT--
44+
DateObjectError: Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
3345
bool(false)
34-
35-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad IntlCalendar instance: not initialized properly in %s on line %d
46+
string(118) "datefmt_format_object: the passed object must be an instance of either IntlCalendar or DateTimeInterface: U_ZERO_ERROR"
3647
bool(false)
37-
Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
38-
39-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the date/time format type is invalid in %s on line %d
48+
string(100) "datefmt_format_object: bad IntlCalendar instance: not initialized properly: U_ILLEGAL_ARGUMENT_ERROR"
4049
bool(false)
41-
42-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; if array, it must have two elements in %s on line %d
50+
string(85) "datefmt_format_object: the date/time format type is invalid: U_ILLEGAL_ARGUMENT_ERROR"
4351
bool(false)
44-
45-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; if array, it must have two elements in %s on line %d
52+
string(96) "datefmt_format_object: bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
4653
bool(false)
47-
48-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; the date format (first element of the array) is not valid in %s on line %d
54+
string(96) "datefmt_format_object: bad format; if array, it must have two elements: U_ILLEGAL_ARGUMENT_ERROR"
4955
bool(false)
50-
51-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad format; the time format (second element of the array) is not valid in %s on line %d
56+
string(118) "datefmt_format_object: bad format; the date format (first element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
5257
bool(false)
53-
54-
Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the format is empty in %s on line %d
58+
string(119) "datefmt_format_object: bad format; the time format (second element of the array) is not valid: U_ILLEGAL_ARGUMENT_ERROR"
5559
bool(false)
60+
string(68) "datefmt_format_object: the format is empty: U_ILLEGAL_ARGUMENT_ERROR"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
IntlDateFormatter->format() errors
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$locale = 'en_US';
9+
$timezone = 'GMT-10:00';
10+
$type = IntlDateFormatter::FULL;
11+
$object = new stdClass();
12+
13+
$f = new IntlDateFormatter($locale, $type, $type, $timezone, IntlDateFormatter::GREGORIAN);
14+
15+
$v = $f->format($object);
16+
var_dump($v);
17+
var_dump(intl_get_error_message());
18+
19+
$v = datefmt_format($f, $object);
20+
var_dump($v);
21+
var_dump(intl_get_error_message());
22+
23+
?>
24+
--EXPECT--
25+
bool(false)
26+
string(127) "datefmt_format: invalid object type for date/time (only IntlCalendar and DateTimeInterface permitted): U_ILLEGAL_ARGUMENT_ERROR"
27+
bool(false)
28+
string(127) "datefmt_format: invalid object type for date/time (only IntlCalendar and DateTimeInterface permitted): U_ILLEGAL_ARGUMENT_ERROR"

0 commit comments

Comments
 (0)