Skip to content

ext/intl: Split error tests out and stop relying on ut_common() testing #19266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions ext/intl/tests/bug67397.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ intl
--FILE--
<?php

function ut_main()
{
$ret = var_export(ut_loc_get_display_name(str_repeat('*', 256), 'en_us'), true);
$ret .= "\n";
$ret .= var_export(intl_get_error_message(), true);
return $ret;
}
$locale = str_repeat('*', 256);
$dispLocale= 'en_us';

var_dump(Locale::getDisplayName($locale, $dispLocale));
var_dump(intl_get_error_message());
var_dump(locale_get_display_name($locale, $dispLocale));
var_dump(intl_get_error_message());

include_once( 'ut_common.inc' );
ut_run();
?>
--EXPECT--
false
'locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR'
bool(false)
string(65) "locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(65) "locale_get_display_name : name too long: U_ILLEGAL_ARGUMENT_ERROR"
46 changes: 25 additions & 21 deletions ext/intl/tests/bug72533.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ intl
--FILE--
<?php

function ut_main()
{
$ret = var_export(ut_loc_accept_http(str_repeat('x', 256)), true);
$ret .= "\n";
if(intl_is_failure(intl_get_error_code())) {
$ret .= var_export(intl_get_error_message(), true);
}
$ret .= "\n";
$ret .= var_export(ut_loc_accept_http(str_repeat('en,', 256)), true);
$ret .= "\n";
if(intl_is_failure(intl_get_error_code())) {
$ret .= var_export(intl_get_error_message(), true);
}
return $ret;
}

include_once( 'ut_common.inc' );
ut_run();
$http = str_repeat('x', 256);

var_dump(Locale::acceptFromHttp($http));
var_dump(intl_get_error_message());

var_dump(locale_accept_from_http($http));
var_dump(intl_get_error_message());


$http = str_repeat('en', 256);

var_dump(Locale::acceptFromHttp($http));
var_dump(intl_get_error_message());

var_dump(locale_accept_from_http($http));
var_dump(intl_get_error_message());

?>
--EXPECT--
false
'locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR'
'en'
bool(false)
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(73) "locale_accept_from_http: locale string too long: U_ILLEGAL_ARGUMENT_ERROR"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
create() icu >= 53.1
Collator creation tests
--EXTENSIONS--
intl
--FILE--
Expand All @@ -17,11 +17,9 @@ function ut_main()
$locales = array(
'EN-US-ODESSA',
'UK_UA_ODESSA',
'uk-ua_CALIFORNIA@currency=;currency=GRN',
'',
'root',
'uk@currency=EURO',
'12345678911131517192123252729313335373941434547495153575961636567697173757779818385878991939597991234567891113151719212325272931333537394143454749515357596163656769717375777981838587899193959799'
);

foreach( $locales as $locale )
Expand Down Expand Up @@ -62,7 +60,6 @@ Locale: 'UK_UA_ODESSA'
ULOC_REQUESTED_LOCALE = 'UK_UA_ODESSA'
ULOC_VALID_LOCALE = 'uk'
ULOC_ACTUAL_LOCALE = 'uk'
Error creating collator with 'uk-ua_CALIFORNIA@currency=;currency=GRN' locale: collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR
Locale: ''
ULOC_REQUESTED_LOCALE = ''
ULOC_VALID_LOCALE = '%s'
Expand All @@ -75,4 +72,3 @@ Locale: 'uk@currency=EURO'
ULOC_REQUESTED_LOCALE = 'uk@currency=EURO'
ULOC_VALID_LOCALE = 'uk'
ULOC_ACTUAL_LOCALE = 'uk'
Error creating collator with '12345678911131517192123252729313335373941434547495153575961636567697173757779818385878991939597991234567891113151719212325272931333537394143454749515357596163656769717375777981838587899193959799' locale: Locale string too long, should be no longer than %d characters: U_ILLEGAL_ARGUMENT_ERROR
40 changes: 40 additions & 0 deletions ext/intl/tests/collator_create_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
Collator creation errors
--EXTENSIONS--
intl
--FILE--
<?php

$locales = [
'uk-ua_CALIFORNIA@currency=;currency=GRN',
str_repeat('a', 160),
];

foreach ($locales as $locale) {
try {
$c = new Collator($locale);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

$c = Collator::create($locale);
var_dump($c);
var_dump(intl_get_error_message());

$c = collator_create($locale);
var_dump($c);
var_dump(intl_get_error_message());
}

?>
--EXPECT--
IntlException: Constructor failed
NULL
string(70) "collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR"
NULL
string(70) "collator_create: unable to open ICU collator: U_ILLEGAL_ARGUMENT_ERROR"
IntlException: Constructor failed
NULL
string(89) "Locale string too long, should be no longer than 156 characters: U_ILLEGAL_ARGUMENT_ERROR"
NULL
string(89) "Locale string too long, should be no longer than 156 characters: U_ILLEGAL_ARGUMENT_ERROR"
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ intl
<?php

/*
* Check effects of changing misc collattion options.
* Check effects of changing misc collation options.
*/


function cmp_array( &$coll, $a )
function cmp_array(Collator $coll, $a)
{
$res = '';
$prev = null;
Expand All @@ -32,7 +31,7 @@ function cmp_array( &$coll, $a )
return $res;
}

function check_alternate_handling( &$coll )
function check_alternate_handling(Collator $coll)
{
$res = '';

Expand Down
36 changes: 0 additions & 36 deletions ext/intl/tests/collator_get_error_message.phpt

This file was deleted.

23 changes: 23 additions & 0 deletions ext/intl/tests/collator_get_invalid_attribute.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Collator get invalid attribute
--EXTENSIONS--
intl
--FILE--
<?php

$attr = 12345;

$coll = Collator::create('ru_RU');

var_dump($coll->getAttribute($attr));
var_dump($coll->getErrorMessage());

var_dump(collator_get_attribute($coll, $attr));
var_dump(collator_get_error_message($coll));

?>
--EXPECT--
bool(false)
string(55) "Error getting attribute value: U_ILLEGAL_ARGUMENT_ERROR"
bool(false)
string(55) "Error getting attribute value: U_ILLEGAL_ARGUMENT_ERROR"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ intl
<?php if (version_compare(INTL_ICU_VERSION, '72.1') >= 0) die('skip for ICU < 72.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

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

new IntlDateFormatter('en_US@calendar=hebrew',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'GMT+05:12',
-1);
?>
==DONE==
--EXPECTF--
--EXPECT--
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(44) "Sunday, 6 Tevet 5772 at 5:12:00 AM GMT+05:12"

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
Stack trace:
#0 %sdateformat_calendars_variant3.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
#1 {main}
thrown %sdateformat_calendars_variant3.php on line %d
15 changes: 1 addition & 14 deletions ext/intl/tests/dateformat_calendars_variant_icu72-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ intl
<?php if (version_compare(INTL_ICU_VERSION, '72.1') < 0) die('skip for ICU >= 72.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

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

new IntlDateFormatter('en_US@calendar=hebrew',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'GMT+05:12',
-1);
?>
==DONE==
--EXPECTF--
--EXPECT--
string(49) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(49) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(46) "Sunday, 6 Tevet 5772 at 5:12:00 AM GMT+05:12"

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
Stack trace:
#0 %s(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
#1 {main}
thrown in %s on line %d
33 changes: 33 additions & 0 deletions ext/intl/tests/dateformat_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
IntlDateFormatter with invalid locale
--EXTENSIONS--
intl
--FILE--
<?php

$locale = 'en_US';
$timezone = 'GMT+05:12';
$type = IntlDateFormatter::FULL;
$invalidCalendar = -1;

try {
$df = new IntlDateFormatter($locale, $type, $type, $timezone, $invalidCalendar);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

$df = IntlDateFormatter::create($locale, $type, $type, $timezone, $invalidCalendar);
var_dump($df);
var_dump(intl_get_error_message());

$df = datefmt_create($locale, $type, $type, $timezone, $invalidCalendar);
var_dump($df);
var_dump(intl_get_error_message());

?>
--EXPECT--
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
NULL
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"
NULL
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"
Loading