Skip to content

Commit 2f7dbe5

Browse files
committed
More tests
1 parent 60aeb23 commit 2f7dbe5

17 files changed

+103
-130
lines changed
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
11
--TEST--
22
IntlCalendar::fieldDifference(): bad arguments
3-
--INI--
4-
date.timezone=Atlantic/Azores
53
--EXTENSIONS--
64
intl
75
--FILE--
86
<?php
9-
ini_set("intl.error_level", E_WARNING);
107

118
$c = new IntlGregorianCalendar(NULL, 'pt_PT');
129

13-
try {
14-
var_dump($c->fieldDifference($c, 2, 3));
15-
} catch (TypeError $e) {
16-
echo $e->getMessage(), "\n";
17-
}
1810
var_dump($c->fieldDifference(INF, 2));
11+
var_dump($c->getErrorMessage());
1912

20-
try {
21-
var_dump(intlcal_field_difference($c, 0, 1, 2));
22-
} catch (TypeError $e) {
23-
echo $e->getMessage(), "\n";
24-
}
25-
var_dump(intlcal_field_difference(1, 0, 1));
2613
?>
27-
--EXPECTF--
28-
IntlCalendar::fieldDifference() expects exactly 2 arguments, 3 given
29-
30-
Warning: IntlCalendar::fieldDifference(): Call to ICU method has failed in %s on line %d
14+
--EXPECT--
3115
bool(false)
32-
intlcal_field_difference() expects exactly 3 arguments, 4 given
33-
34-
Fatal error: Uncaught TypeError: intlcal_field_difference(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d
35-
Stack trace:
36-
#0 %s(%d): intlcal_field_difference(1, 0, 1)
37-
#1 {main}
38-
thrown in %s on line %d
16+
string(88) "IntlCalendar::fieldDifference(): Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/calendar_fromDateTime_error.phpt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,34 @@ intl.default_locale=nl
77
date.timezone=Europe/Lisbon
88
--FILE--
99
<?php
10-
ini_set("intl.error_level", E_WARNING);
1110

1211
try {
1312
IntlCalendar::fromDateTime("foobar");
14-
} catch (Exception $e) {
15-
echo "threw exception, OK";
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1615
}
16+
1717
class A extends DateTime {
18-
function __construct() {}
18+
function __construct() {}
1919
}
2020

2121
var_dump(IntlCalendar::fromDateTime(new A));
22+
var_dump(intl_get_error_message());
2223

2324
$date = new DateTime('2012-01-01 00:00:00 +24:00');
2425
var_dump(IntlCalendar::fromDateTime($date));
26+
var_dump(intl_get_error_message());
2527

2628
$date = new DateTime('2012-01-01 00:00:00 WEST');
2729
var_dump(IntlCalendar::fromDateTime($date));
30+
var_dump(intl_get_error_message());
31+
2832
?>
29-
--EXPECTF--
30-
threw exception, OK
31-
Warning: IntlCalendar::fromDateTime(): DateTime object is unconstructed in %s on line %d
33+
--EXPECT--
34+
DateMalformedStringException: Failed to parse time string (foobar) at position 0 (f): The timezone could not be found in the database
3235
NULL
33-
34-
Warning: IntlCalendar::fromDateTime(): object has an time zone offset that's too large in %s on line %d
36+
string(88) "IntlCalendar::fromDateTime(): DateTime object is unconstructed: U_ILLEGAL_ARGUMENT_ERROR"
3537
NULL
36-
37-
Warning: IntlCalendar::fromDateTime(): time zone id 'WEST' extracted from ext/date DateTimeZone not recognized in %s on line %d
38+
string(103) "IntlCalendar::fromDateTime(): object has an time zone offset that's too large: U_ILLEGAL_ARGUMENT_ERROR"
3839
NULL
40+
string(127) "IntlCalendar::fromDateTime(): time zone id 'WEST' extracted from ext/date DateTimeZone not recognized: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/calendar_getErrorCode_getErrorMessage_basic.phpt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,34 @@
22
IntlCalendar::getErrorCode(), ::getErrorMessage() basic test
33
--INI--
44
date.timezone=Atlantic/Azores
5+
intl.default_locale=nl
56
--EXTENSIONS--
67
intl
78
--FILE--
89
<?php
9-
ini_set("intl.error_level", E_WARNING);
10-
ini_set("intl.default_locale", "nl");
1110

1211
$intlcal = IntlGregorianCalendar::createFromDate(2012, 1, 29);
1312
var_dump(
14-
$intlcal->getErrorCode(),
15-
intlcal_get_error_code($intlcal),
16-
$intlcal->getErrorMessage(),
17-
intlcal_get_error_message($intlcal)
13+
$intlcal->getErrorCode(),
14+
intlcal_get_error_code($intlcal),
15+
$intlcal->getErrorMessage(),
16+
intlcal_get_error_message($intlcal)
1817
);
1918
$intlcal->add(IntlCalendar::FIELD_SECOND, 2147483647);
2019
$intlcal->fieldDifference(-PHP_INT_MAX, IntlCalendar::FIELD_SECOND);
2120

2221
var_dump(
23-
$intlcal->getErrorCode(),
24-
intlcal_get_error_code($intlcal),
25-
$intlcal->getErrorMessage(),
26-
intlcal_get_error_message($intlcal)
22+
$intlcal->getErrorCode(),
23+
intlcal_get_error_code($intlcal),
24+
$intlcal->getErrorMessage(),
25+
intlcal_get_error_message($intlcal)
2726
);
2827
?>
29-
--EXPECTF--
28+
--EXPECT--
3029
int(0)
3130
int(0)
3231
string(12) "U_ZERO_ERROR"
3332
string(12) "U_ZERO_ERROR"
34-
35-
Warning: IntlCalendar::fieldDifference(): Call to ICU method has failed in %s on line %d
3633
int(1)
3734
int(1)
3835
string(88) "IntlCalendar::fieldDifference(): Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR"

ext/intl/tests/calendar_setTimeZone_error2.phpt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ date.timezone=Europe/Amsterdam
77
intl.default_locale=nl
88
--FILE--
99
<?php
10-
ini_set("intl.error_level", E_WARNING);
1110

1211
$intlcal = new IntlGregorianCalendar();
1312

1413
$pstdate = new DateTime('2012-01-01 00:00:00 WEST');
15-
$intlcal->setTimeZone($pstdate->getTimeZone());
14+
var_dump($intlcal->setTimeZone($pstdate->getTimeZone()));
15+
var_dump($intlcal->getErrorMessage());
1616
var_dump($intlcal->getTimeZone()->getID());
1717

1818
$pstdate = new DateTime('2012-01-01 00:00:00 +24:00');
19-
$intlcal->setTimeZone($pstdate->getTimeZone());
19+
var_dump($intlcal->setTimeZone($pstdate->getTimeZone()));
20+
var_dump($intlcal->getErrorMessage());
2021
var_dump($intlcal->getTimeZone()->getID());
2122
?>
22-
--EXPECTF--
23-
Warning: IntlCalendar::setTimeZone(): time zone id 'WEST' extracted from ext/date DateTimeZone not recognized in %s on line %d
23+
--EXPECT--
24+
bool(false)
25+
string(126) "IntlCalendar::setTimeZone(): time zone id 'WEST' extracted from ext/date DateTimeZone not recognized: U_ILLEGAL_ARGUMENT_ERROR"
2426
string(16) "Europe/Amsterdam"
25-
26-
Warning: IntlCalendar::setTimeZone(): object has an time zone offset that's too large in %s on line %d
27+
bool(false)
28+
string(102) "IntlCalendar::setTimeZone(): object has an time zone offset that's too large: U_ILLEGAL_ARGUMENT_ERROR"
2729
string(16) "Europe/Amsterdam"

ext/intl/tests/calendar_toDateTime_error.phpt

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,36 @@ IntlCalendar::toDateTime(): bad arguments
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
8-
ini_set('date.timezone', 'Europe/Lisbon');
97

108
$cal = new IntlGregorianCalendar("Etc/Unknown");
119
try {
12-
var_dump($cal->toDateTime());
13-
} catch (Exception $e) {
14-
var_dump("exception: {$e->getMessage()}");
10+
var_dump($cal->toDateTime());
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1513
}
1614

1715
try {
1816
var_dump(intlcal_to_date_time($cal));
19-
} catch (\Exception $e) {
20-
var_dump($e->getMessage());
17+
} catch (Throwable $e) {
18+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
2119
}
2220

2321
$cal = IntlCalendar::createInstance("Etc/Unknown");
2422
try {
2523
var_dump($cal->toDateTime());
26-
} catch (\Exception $e) {
27-
var_dump($e->getMessage());
24+
} catch (Throwable $e) {
25+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
2826
}
2927

3028
try {
3129
var_dump(intlcal_to_date_time($cal));
32-
} catch (\Exception $e) {
33-
var_dump($e->getMessage());
30+
} catch (Throwable $e) {
31+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
3432
}
3533

36-
try {
37-
var_dump(intlcal_to_date_time(3));
38-
} catch (\TypeError $e) {
39-
echo $e->getMessage() . \PHP_EOL;
40-
}
4134
?>
42-
--EXPECTF--
43-
Warning: IntlCalendar::toDateTime(): DateTimeZone constructor threw exception in %s on line %d
44-
string(77) "exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)"
45-
46-
Warning: intlcal_to_date_time(): DateTimeZone constructor threw exception in %s on line %d
47-
string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)"
48-
49-
Warning: IntlCalendar::toDateTime(): DateTimeZone constructor threw exception in %s on line %d
50-
string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)"
51-
52-
Warning: intlcal_to_date_time(): DateTimeZone constructor threw exception in %s on line %d
53-
string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)"
54-
intlcal_to_date_time(): Argument #1 ($calendar) must be of type IntlCalendar, int given
35+
--EXPECT--
36+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)
37+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)
38+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)
39+
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)

ext/intl/tests/datepatterngenerator_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ IntlDatePatternGenerator::getBestPattern(): errors
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
87

98
$dtpg = new IntlDatePatternGenerator();
109
var_dump($dtpg->getBestPattern("jjmm\x80"));
10+
var_dump(intl_get_error_message());
1111

1212
?>
13-
--EXPECTF--
14-
Warning: IntlDatePatternGenerator::getBestPattern(): Skeleton is not a valid UTF-8 string in %s on line %d
13+
--EXPECT--
1514
bool(false)
15+
string(102) "IntlDatePatternGenerator::getBestPattern(): Skeleton is not a valid UTF-8 string: U_INVALID_CHAR_FOUND"

ext/intl/tests/gh11658.phpt

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

8-
ini_set("intl.error_level", E_WARNING);
9-
108
$s = MessageFormatter::formatMessage('en', 'some {wrong.format}', []);
119
var_dump($s);
10+
echo intl_get_error_message(), PHP_EOL;
1211

1312
$s = msgfmt_format_message('en', 'some {wrong.format}', []);
1413
var_dump($s);
14+
echo intl_get_error_message(), PHP_EOL;
15+
1516
?>
16-
--EXPECTF--
17-
Warning: MessageFormatter::formatMessage(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}") in %s on line %d
17+
--EXPECT--
1818
bool(false)
19-
20-
Warning: msgfmt_format_message(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}") in %s on line %d
19+
MessageFormatter::formatMessage(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}"): U_PATTERN_SYNTAX_ERROR
2120
bool(false)
21+
msgfmt_format_message(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}"): U_PATTERN_SYNTAX_ERROR

ext/intl/tests/timezone_countEquivalentIDs_error.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ IntlTimeZone::countEquivalentIDs(): errors
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
87

98
var_dump(IntlTimeZone::countEquivalentIDs("foo\x80"));
9+
echo intl_get_error_message(), PHP_EOL;
10+
1011
?>
11-
--EXPECTF--
12-
Warning: IntlTimeZone::countEquivalentIDs(): could not convert time zone id to UTF-16 in %s on line %d
12+
--EXPECT--
1313
bool(false)
14+
IntlTimeZone::countEquivalentIDs(): could not convert time zone id to UTF-16: U_INVALID_CHAR_FOUND

ext/intl/tests/timezone_createTimeZone_error.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ IntlTimeZone::createTimeZone(): errors
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
87

98
var_dump(IntlTimeZone::createTimeZone("foo\x80"));
9+
echo intl_get_error_message(), PHP_EOL;
10+
1011
?>
11-
--EXPECTF--
12-
Warning: IntlTimeZone::createTimeZone(): could not convert time zone id to UTF-16 in %s on line %d
12+
--EXPECT--
1313
NULL
14+
IntlTimeZone::createTimeZone(): could not convert time zone id to UTF-16: U_INVALID_CHAR_FOUND

ext/intl/tests/timezone_getCanonicalID_error.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ IntlTimeZone::getCanonicalID(): errors
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
87

98
var_dump(IntlTimeZone::getCanonicalID("foo\x81"));
9+
echo intl_get_error_message(), PHP_EOL;
10+
1011
?>
11-
--EXPECTF--
12-
Warning: IntlTimeZone::getCanonicalID(): could not convert time zone id to UTF-16 in %s on line %d
12+
--EXPECT--
1313
bool(false)
14+
IntlTimeZone::getCanonicalID(): could not convert time zone id to UTF-16: U_INVALID_CHAR_FOUND

0 commit comments

Comments
 (0)