Skip to content

Commit 191290e

Browse files
authored
ext/intl: Split error tests out and stop relying on ut_common() testing (#19266)
1 parent 4a0ad9b commit 191290e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+658
-478
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_calendars_variant3.phpt renamed to ext/intl/tests/dateformat_calendars_variant.phpt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ intl
88
<?php if (version_compare(INTL_ICU_VERSION, '72.1') >= 0) die('skip for ICU < 72.1'); ?>
99
--FILE--
1010
<?php
11-
ini_set("intl.error_level", E_WARNING);
1211

1312
$fmt1 = new IntlDateFormatter('en_US',
1413
IntlDateFormatter::FULL,
@@ -29,20 +28,8 @@ var_dump($fmt1->format(strtotime('2012-01-01 00:00:00 +0000')));
2928
var_dump($fmt2->format(strtotime('2012-01-01 00:00:00 +0000')));
3029
var_dump($fmt3->format(strtotime('2012-01-01 00:00:00 +0000')));
3130

32-
new IntlDateFormatter('en_US@calendar=hebrew',
33-
IntlDateFormatter::FULL,
34-
IntlDateFormatter::FULL,
35-
'GMT+05:12',
36-
-1);
3731
?>
38-
==DONE==
39-
--EXPECTF--
32+
--EXPECT--
4033
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
4134
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
4235
string(44) "Sunday, 6 Tevet 5772 at 5:12:00 AM GMT+05:12"
43-
44-
Fatal error: Uncaught IntlException: IntlDateFormatter::__construct(): datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant3.php:%d
45-
Stack trace:
46-
#0 %sdateformat_calendars_variant3.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
47-
#1 {main}
48-
thrown %sdateformat_calendars_variant3.php on line %d

ext/intl/tests/dateformat_calendars_variant_icu72-1.phpt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ intl
88
<?php if (version_compare(INTL_ICU_VERSION, '72.1') < 0) die('skip for ICU >= 72.1'); ?>
99
--FILE--
1010
<?php
11-
ini_set("intl.error_level", E_WARNING);
1211

1312
$fmt1 = new IntlDateFormatter('en_US',
1413
IntlDateFormatter::FULL,
@@ -29,20 +28,8 @@ var_dump($fmt1->format(strtotime('2012-01-01 00:00:00 +0000')));
2928
var_dump($fmt2->format(strtotime('2012-01-01 00:00:00 +0000')));
3029
var_dump($fmt3->format(strtotime('2012-01-01 00:00:00 +0000')));
3130

32-
new IntlDateFormatter('en_US@calendar=hebrew',
33-
IntlDateFormatter::FULL,
34-
IntlDateFormatter::FULL,
35-
'GMT+05:12',
36-
-1);
3731
?>
38-
==DONE==
39-
--EXPECTF--
32+
--EXPECT--
4033
string(49) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
4134
string(49) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
4235
string(46) "Sunday, 6 Tevet 5772 at 5:12:00 AM GMT+05:12"
43-
44-
Fatal error: Uncaught IntlException: IntlDateFormatter::__construct(): datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s:%d
45-
Stack trace:
46-
#0 %s(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
47-
#1 {main}
48-
thrown in %s on line %d

ext/intl/tests/dateformat_errors.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
IntlDateFormatter with invalid locale
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$locale = 'en_US';
9+
$timezone = 'GMT+05:12';
10+
$type = IntlDateFormatter::FULL;
11+
$invalidCalendar = -1;
12+
13+
try {
14+
$df = new IntlDateFormatter($locale, $type, $type, $timezone, $invalidCalendar);
15+
} catch (Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
17+
}
18+
19+
$df = IntlDateFormatter::create($locale, $type, $type, $timezone, $invalidCalendar);
20+
var_dump($df);
21+
var_dump(intl_get_error_message());
22+
23+
$df = datefmt_create($locale, $type, $type, $timezone, $invalidCalendar);
24+
var_dump($df);
25+
var_dump(intl_get_error_message());
26+
27+
?>
28+
--EXPECT--
29+
IntlException: datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object: U_ILLEGAL_ARGUMENT_ERROR
30+
NULL
31+
string(232) "datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object: U_ILLEGAL_ARGUMENT_ERROR"
32+
NULL
33+
string(232) "datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object: U_ILLEGAL_ARGUMENT_ERROR"

0 commit comments

Comments
 (0)