Skip to content

Commit 7334dcf

Browse files
authored
Applied fixers to improve test robustness (ext/intl, ext/phar) (#22985)
This commit hardens tests in the phar and intl extension. By: - Testing exception type in error tests, and formating them consistently. - Removing useless blank lines
1 parent 1a48f90 commit 7334dcf

250 files changed

Lines changed: 977 additions & 1033 deletions

File tree

Some content is hidden

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

ext/intl/tests/breakiter_getPartsIterator_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ $it = IntlBreakIterator::createWordInstance(NULL);
1010
try {
1111
var_dump($it->getPartsIterator(-1));
1212
} catch(\ValueError $e) {
13-
echo $e->getMessage() . \PHP_EOL;
13+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1414
}
1515

1616
?>
1717
--EXPECT--
18-
IntlBreakIterator::getPartsIterator(): Argument #1 ($type) must be one of IntlPartsIterator::KEY_SEQUENTIAL, IntlPartsIterator::KEY_LEFT, or IntlPartsIterator::KEY_RIGHT
18+
ValueError: IntlBreakIterator::getPartsIterator(): Argument #1 ($type) must be one of IntlPartsIterator::KEY_SEQUENTIAL, IntlPartsIterator::KEY_LEFT, or IntlPartsIterator::KEY_RIGHT

ext/intl/tests/bug48227.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ foreach (['', 1, NULL, $x] as $value) {
1010
try {
1111
var_dump($x->format($value));
1212
} catch (TypeError $ex) {
13-
echo $ex->getMessage(), PHP_EOL;
13+
echo $ex::class, ': ', $ex->getMessage(), PHP_EOL;
1414
}
1515
}
1616

1717
?>
1818
--EXPECTF--
19-
NumberFormatter::format(): Argument #1 ($num) must be of type int|float, string given
19+
TypeError: NumberFormatter::format(): Argument #1 ($num) must be of type int|float, string given
2020
string(1) "1"
2121

2222
Deprecated: NumberFormatter::format(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
2323
string(1) "0"
24-
NumberFormatter::format(): Argument #1 ($num) must be of type int|float, NumberFormatter given
24+
TypeError: NumberFormatter::format(): Argument #1 ($num) must be of type int|float, NumberFormatter given

ext/intl/tests/bug61487.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ intl
1010
try {
1111
grapheme_stripos(1,1,2147483648);
1212
} catch (ValueError $exception) {
13-
echo $exception->getMessage() . "\n";
13+
echo $exception::class, ': ', $exception->getMessage(), "\n";
1414
}
1515

1616
try {
1717
grapheme_strpos(1,1,2147483648);
1818
} catch (ValueError $exception) {
19-
echo $exception->getMessage() . "\n";
19+
echo $exception::class, ': ', $exception->getMessage(), "\n";
2020
}
2121
?>
2222
--EXPECT--
23-
grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
24-
grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
23+
ValueError: grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
24+
ValueError: grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)

ext/intl/tests/bug62083.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ $arr1 = array();
88
try {
99
grapheme_extract(-1, -1, -1,-1, $arr1);
1010
} catch (ValueError $exception) {
11-
echo $exception->getMessage() . "\n";
11+
echo $exception::class, ': ', $exception->getMessage(), "\n";
1212
}
1313
?>
1414
--EXPECT--
15-
grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS
15+
ValueError: grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS

ext/intl/tests/bug74063.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ $formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
88
try {
99
serialize($formatter);
1010
} catch (Exception $ex) {
11-
echo $ex->getMessage(), PHP_EOL;
11+
echo $ex::class, ': ', $ex->getMessage(), PHP_EOL;
1212
}
1313
?>
1414
--EXPECT--
15-
Serialization of 'NumberFormatter' is not allowed
15+
Exception: Serialization of 'NumberFormatter' is not allowed

ext/intl/tests/calendar_clear_error.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ $c = new IntlGregorianCalendar(NULL, 'pt_PT');
1010
try {
1111
var_dump($c->clear(-1));
1212
} catch (\ValueError $e) {
13-
echo $e->getMessage() . \PHP_EOL;
13+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1414
}
1515
try {
1616
var_dump(intlcal_clear($c, -1));
1717
} catch (\ValueError $e) {
18-
echo $e->getMessage() . \PHP_EOL;
18+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1919
}
2020

2121
?>
2222
--EXPECT--
23-
IntlCalendar::clear(): Argument #1 ($field) must be a valid field
24-
intlcal_clear(): Argument #2 ($field) must be a valid field
23+
ValueError: IntlCalendar::clear(): Argument #1 ($field) must be a valid field
24+
ValueError: intlcal_clear(): Argument #2 ($field) must be a valid field

ext/intl/tests/calendar_createInstance_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function __construct() {}
1212
try {
1313
intlcal_create_instance(new X, NULL);
1414
} catch (IntlException $e) {
15-
echo $e->getMessage();
15+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1616
}
1717
?>
1818
--EXPECT--
19-
intlcal_create_instance(): passed IntlTimeZone is not properly constructed
19+
IntlException: intlcal_create_instance(): passed IntlTimeZone is not properly constructed

ext/intl/tests/calendar_getDayOfWeekType_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ $c = new IntlGregorianCalendar(NULL, 'pt_PT');
99
try {
1010
var_dump($c->getDayOfWeekType(0));
1111
} catch (\ValueError $e) {
12-
echo $e->getMessage() . \PHP_EOL;
12+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1313
}
1414

1515
?>
1616
--EXPECT--
17-
IntlCalendar::getDayOfWeekType(): Argument #1 ($dayOfWeek) must be a valid day of the week
17+
ValueError: IntlCalendar::getDayOfWeekType(): Argument #1 ($dayOfWeek) must be a valid day of the week

ext/intl/tests/calendar_getWeekendTransition_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ $c = new IntlGregorianCalendar(NULL, 'pt_PT');
1010
try {
1111
var_dump($c->getWeekendTransition(0));
1212
} catch (\ValueError $e) {
13-
echo $e->getMessage() . \PHP_EOL;
13+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1414
}
1515

1616
?>
1717
--EXPECT--
18-
IntlCalendar::getWeekendTransition(): Argument #1 ($dayOfWeek) must be a valid day of the week
18+
ValueError: IntlCalendar::getWeekendTransition(): Argument #1 ($dayOfWeek) must be a valid day of the week

ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,52 @@ $c = new IntlGregorianCalendar(NULL, 'pt_PT');
1010
try {
1111
var_dump($c->getLeastMaximum(-1));
1212
} catch (Error $e) {
13-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
13+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
1414
}
1515
try {
1616
var_dump($c->getMaximum(-1));
1717
} catch (Error $e) {
18-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
18+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
1919
}
2020
try {
2121
var_dump($c->getGreatestMinimum(-1));
2222
} catch (Error $e) {
23-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
23+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
2424
}
2525
try {
2626
var_dump($c->getMinimum(-1));
2727
} catch (Error $e) {
28-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
28+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
2929
}
3030

3131
try {
3232
var_dump(intlcal_get_least_maximum($c, -1));
3333
} catch (Error $e) {
34-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
34+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
3535
}
3636
try {
3737
var_dump(intlcal_get_maximum($c, -1));
3838
} catch (Error $e) {
39-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
39+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
4040
}
4141
try {
4242
var_dump(intlcal_get_greatest_minimum($c, -1));
4343
} catch (Error $e) {
44-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
44+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
4545
}
4646
try {
4747
var_dump(intlcal_get_minimum($c, -1));
4848
} catch (Error $e) {
49-
echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL;
49+
echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), PHP_EOL;
5050
}
5151

5252
?>
5353
--EXPECT--
54-
ValueError: 0, IntlCalendar::getLeastMaximum(): Argument #1 ($field) must be a valid field
55-
ValueError: 0, IntlCalendar::getMaximum(): Argument #1 ($field) must be a valid field
56-
ValueError: 0, IntlCalendar::getGreatestMinimum(): Argument #1 ($field) must be a valid field
57-
ValueError: 0, IntlCalendar::getMinimum(): Argument #1 ($field) must be a valid field
58-
ValueError: 0, intlcal_get_least_maximum(): Argument #2 ($field) must be a valid field
59-
ValueError: 0, intlcal_get_maximum(): Argument #2 ($field) must be a valid field
60-
ValueError: 0, intlcal_get_greatest_minimum(): Argument #2 ($field) must be a valid field
61-
ValueError: 0, intlcal_get_minimum(): Argument #2 ($field) must be a valid field
54+
ValueError: 0: IntlCalendar::getLeastMaximum(): Argument #1 ($field) must be a valid field
55+
ValueError: 0: IntlCalendar::getMaximum(): Argument #1 ($field) must be a valid field
56+
ValueError: 0: IntlCalendar::getGreatestMinimum(): Argument #1 ($field) must be a valid field
57+
ValueError: 0: IntlCalendar::getMinimum(): Argument #1 ($field) must be a valid field
58+
ValueError: 0: intlcal_get_least_maximum(): Argument #2 ($field) must be a valid field
59+
ValueError: 0: intlcal_get_maximum(): Argument #2 ($field) must be a valid field
60+
ValueError: 0: intlcal_get_greatest_minimum(): Argument #2 ($field) must be a valid field
61+
ValueError: 0: intlcal_get_minimum(): Argument #2 ($field) must be a valid field

0 commit comments

Comments
 (0)