Skip to content

Commit 17b564c

Browse files
committed
Prefix the exception message with the exception class
1 parent 30277a4 commit 17b564c

File tree

53 files changed

+294
-286
lines changed

Some content is hidden

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

53 files changed

+294
-286
lines changed

ext/date/tests/68062.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ echo $tz->getOffset($dt), "\n";
1010
try {
1111
echo $tz->getOffset(1);
1212
} catch (TypeError $e) {
13-
echo $e->getMessage(), "\n";
13+
echo $e::class, ': ', $e->getMessage(), "\n";
1414
}
1515
?>
1616
--EXPECT--
1717
3600
18-
DateTimeZone::getOffset(): Argument #1 ($datetime) must be of type DateTimeInterface, int given
18+
TypeError: DateTimeZone::getOffset(): Argument #1 ($datetime) must be of type DateTimeInterface, int given

ext/date/tests/DateInterval_construct_exceptions.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function check(callable $c)
99
try {
1010
var_dump($c());
1111
} catch (\DateMalformedIntervalStringException $e) {
12-
echo $e->getMessage(), "\n";
12+
echo $e::class, ': ', $e->getMessage(), "\n";
1313
}
1414
}
1515

1616
check(fn() => new DateInterval(""));
1717
check(fn() => new DateInterval("2007-05-11T15:30:00Z/"));
1818
?>
1919
--EXPECTF--
20-
Unknown or bad format ()
21-
Failed to parse interval (2007-05-11T15:30:00Z/)
20+
DateMalformedIntervalStringException: Unknown or bad format ()
21+
DateMalformedIntervalStringException: Failed to parse interval (2007-05-11T15:30:00Z/)

ext/date/tests/DateInterval_createFromDateString_broken.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Test DateInterval::createFromDateString() function : nonsense data
55
try {
66
$i = DateInterval::createFromDateString("foobar");
77
} catch (DateMalformedIntervalStringException $e) {
8-
echo $e->getMessage(), "\n";
8+
echo $e::class, ': ', $e->getMessage(), "\n";
99
}
1010
var_dump($i);
1111
?>
1212
--EXPECTF--
13-
Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database
13+
DateMalformedIntervalStringException: Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database
1414

1515
Warning: Undefined variable $i in %s
1616
NULL

ext/date/tests/DateInterval_serialize-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var_dump($now->add($e));
3535
try {
3636
var_dump($now->sub($e));
3737
} catch (DateInvalidOperationException $e) {
38-
echo $e->getMessage(), "\n";
38+
echo $e::class, ': ', $e->getMessage(), "\n";
3939
}
4040
?>
4141
--EXPECTF--
@@ -88,4 +88,4 @@ object(DateTimeImmutable)#4 (3) {
8888
["timezone"]=>
8989
string(3) "BST"
9090
}
91-
DateTimeImmutable::sub(): Only non-special relative time specifications are supported for subtraction
91+
DateInvalidOperationException: DateTimeImmutable::sub(): Only non-special relative time specifications are supported for subtraction

ext/date/tests/DateInterval_set_state_exception.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ foreach( $propertySets as $propertySet )
1313
$d = DateInterval::__set_state( [ 'date_string' => $propertySet ] );
1414
echo "OK\n";
1515
} catch (\Error $e) {
16-
echo $e->getMessage(), "\n";
16+
echo $e::class, ': ', $e->getMessage(), "\n";
1717
}
1818
}
1919
?>
2020
--EXPECT--
2121
OK
22-
Unknown or bad format (2023-01-16-foobar$*) at position 10 (-) while unserializing: Unexpected character
22+
Error: Unknown or bad format (2023-01-16-foobar$*) at position 10 (-) while unserializing: Unexpected character

ext/date/tests/DateInterval_uninitialised_exceptions.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function check(callable $c)
1616
try {
1717
var_dump($c());
1818
} catch (\DateObjectError $e) {
19-
echo $e->getMessage(), "\n";
19+
echo $e::class, ': ', $e->getMessage(), "\n";
2020
}
2121
}
2222

@@ -26,5 +26,5 @@ check(fn() => serialize($mdi));
2626
check(fn() => $mdi->format("Y-m-d"));
2727
?>
2828
--EXPECTF--
29-
Object of type MyDateInterval (inheriting DateInterval) has not been correctly initialized by calling parent::__construct() in its constructor
30-
Object of type MyDateInterval (inheriting DateInterval) has not been correctly initialized by calling parent::__construct() in its constructor
29+
DateObjectError: Object of type MyDateInterval (inheriting DateInterval) has not been correctly initialized by calling parent::__construct() in its constructor
30+
DateObjectError: Object of type MyDateInterval (inheriting DateInterval) has not been correctly initialized by calling parent::__construct() in its constructor

ext/date/tests/DatePeriod_by_ref_iterator.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ try {
1515
}
1616
echo "OK\n";
1717
} catch (\Error $e) {
18-
echo $e->getMessage(), "\n";
18+
echo $e::class, ': ', $e->getMessage(), "\n";
1919
}
2020
?>
2121
--EXPECT--
22-
An iterator cannot be used with foreach by reference
22+
Error: An iterator cannot be used with foreach by reference

ext/date/tests/DatePeriod_modify_readonly_property.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ $dp = new \DatePeriod(
1111
try {
1212
$dp->interval = "foo";
1313
} catch( \Error $e ) {
14-
echo $e->getMessage(), "\n";
14+
echo $e::class, ': ', $e->getMessage(), "\n";
1515
}
1616

1717
try {
1818
$foo =& $dp->interval;
1919
} catch( \Error $e ) {
20-
echo $e->getMessage(), "\n";
20+
echo $e::class, ': ', $e->getMessage(), "\n";
2121
}
2222
?>
2323
--EXPECTF--
24-
Cannot modify readonly property DatePeriod::$interval
25-
Cannot modify readonly property DatePeriod::$interval
24+
Error: Cannot modify readonly property DatePeriod::$interval
25+
Error: Cannot modify readonly property DatePeriod::$interval

ext/date/tests/DatePeriod_properties2.phpt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ foreach ($properties as $property) {
2020
try {
2121
$period->$property = "new";
2222
} catch (Error $e) {
23-
echo $e->getMessage() . "\n";
23+
echo $e::class, ': ', $e->getMessage(), "\n";
2424
}
2525

2626
try {
2727
$period->$property[] = "extra";
2828
} catch (Error $e) {
29-
echo $e->getMessage() . "\n";
29+
echo $e::class, ': ', $e->getMessage(), "\n";
3030
}
3131
}
3232

3333
try {
3434
$period->start->modify("+1 hour");
3535
} catch (Error $e) {
36-
echo $e->getMessage() . "\n";
36+
echo $e::class, ': ', $e->getMessage(), "\n";
3737
}
3838

3939
?>
4040
--EXPECT--
41-
Cannot modify readonly property DatePeriod::$recurrences
42-
Cannot modify readonly property DatePeriod::$recurrences
43-
Cannot modify readonly property DatePeriod::$include_start_date
44-
Cannot modify readonly property DatePeriod::$include_start_date
45-
Cannot modify readonly property DatePeriod::$start
46-
Cannot modify readonly property DatePeriod::$start
47-
Cannot modify readonly property DatePeriod::$current
48-
Cannot modify readonly property DatePeriod::$current
49-
Cannot modify readonly property DatePeriod::$end
50-
Cannot modify readonly property DatePeriod::$end
51-
Cannot modify readonly property DatePeriod::$interval
52-
Cannot modify readonly property DatePeriod::$interval
41+
Error: Cannot modify readonly property DatePeriod::$recurrences
42+
Error: Cannot modify readonly property DatePeriod::$recurrences
43+
Error: Cannot modify readonly property DatePeriod::$include_start_date
44+
Error: Cannot modify readonly property DatePeriod::$include_start_date
45+
Error: Cannot modify readonly property DatePeriod::$start
46+
Error: Cannot modify readonly property DatePeriod::$start
47+
Error: Cannot modify readonly property DatePeriod::$current
48+
Error: Cannot modify readonly property DatePeriod::$current
49+
Error: Cannot modify readonly property DatePeriod::$end
50+
Error: Cannot modify readonly property DatePeriod::$end
51+
Error: Cannot modify readonly property DatePeriod::$interval
52+
Error: Cannot modify readonly property DatePeriod::$interval

ext/date/tests/DatePeriod_set_state_exception.phpt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ DatePeriod invalid serialization data
33
--FILE--
44
<?php
55
$propertySets = [
6+
/* Two correct elements */
67
[
78
'start' => new \DateTimeImmutable("2023-01-13 12:29:30"), 'end' => new \DateTimeImmutable("2023-01-16 16:49:29"), 'current' => new \DateTimeImmutable("2023-01-15 00:00:00"),
89
'interval' => DateInterval::createFromDateString("tomorrow"), 'recurrences' => 1, 'include_start_date' => true, 'include_end_date' => true,
@@ -11,6 +12,7 @@ $propertySets = [
1112
'start' => null, 'end' => null, 'current' => null,
1213
'interval' => DateInterval::createFromDateString("tomorrow"), 'recurrences' => 1, 'include_start_date' => false, 'include_end_date' => false,
1314
],
15+
/* Error situations */
1416
[
1517
'start' => "2023-01-13 12:29:30", 'end' => new \DateTimeImmutable("2023-01-16 16:49:29"), 'current' => new \DateTimeImmutable("2023-01-15 00:00:00"),
1618
'interval' => DateInterval::createFromDateString("tomorrow"), 'recurrences' => 1, 'include_start_date' => true, 'include_end_date' => true,
@@ -47,17 +49,17 @@ foreach( $propertySets as $propertySet )
4749
$d = DatePeriod::__set_state( $propertySet );
4850
echo "OK\n";
4951
} catch (\Error $e) {
50-
echo $e->getMessage(), "\n";
52+
echo $e::class, ': ', $e->getMessage(), "\n";
5153
}
5254
}
5355
?>
5456
--EXPECT--
5557
OK
5658
OK
57-
Invalid serialization data for DatePeriod object
58-
Invalid serialization data for DatePeriod object
59-
Invalid serialization data for DatePeriod object
60-
Invalid serialization data for DatePeriod object
61-
Invalid serialization data for DatePeriod object
62-
Invalid serialization data for DatePeriod object
63-
Invalid serialization data for DatePeriod object
59+
Error: Invalid serialization data for DatePeriod object
60+
Error: Invalid serialization data for DatePeriod object
61+
Error: Invalid serialization data for DatePeriod object
62+
Error: Invalid serialization data for DatePeriod object
63+
Error: Invalid serialization data for DatePeriod object
64+
Error: Invalid serialization data for DatePeriod object
65+
Error: Invalid serialization data for DatePeriod object

ext/date/tests/DatePeriod_uninitialised_exceptions.phpt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,30 @@ function check(callable $c)
1616
try {
1717
var_dump($c());
1818
} catch (\DateObjectError $e) {
19-
echo $e->getMessage(), "\n";
19+
echo $e::class, ': ', $e->getMessage(), "\n";
2020
}
2121
}
2222

2323
$mdp = new MyDatePeriod();
2424

2525
check(fn() => serialize($mdp));
2626
check(fn() => $mdp->getStartDate());
27-
check(fn() => $mdp->getEndDate());
2827
check(fn() => $mdp->getDateInterval());
29-
check(fn() => $mdp->getRecurrences());
3028

3129
check(function() use ($mdp) {
3230
foreach($mdp as $foo)
3331
{
3432
}
3533
});
34+
35+
/* Allowed to be empty */
36+
check(fn() => $mdp->getEndDate());
37+
check(fn() => $mdp->getRecurrences());
3638
?>
3739
--EXPECTF--
38-
Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
39-
Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
40+
DateObjectError: Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
41+
DateObjectError: Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
42+
DateObjectError: Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
43+
DateObjectError: Object of type DatePeriod has not been correctly initialized by calling parent::__construct() in its constructor
4044
NULL
41-
Object of type MyDatePeriod (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
4245
NULL
43-
Object of type DatePeriod has not been correctly initialized by calling parent::__construct() in its constructor

ext/date/tests/DatePeriod_wrong_arguments.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ try {
1515
$dp = new DatePeriod("2023-01-13 17:24:58", DateInterval::createFromDateString("tomorrow"), 4);
1616
echo "OK\n";
1717
} catch (\TypeError $e) {
18-
echo $e->getMessage(), "\n";
18+
echo $e::class, ': ', $e->getMessage(), "\n";
1919
}
2020
?>
2121
--EXPECT--
2222
OK
2323
OK
2424
OK
25-
DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments
25+
TypeError: DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments

ext/date/tests/DateTimeImmutable_createFromInterface_exceptions.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ $i = new MyDateTime();
2222
try {
2323
$m = DateTimeImmutable::createFromInterface( $i );
2424
} catch (\DateObjectError $e) {
25-
echo $e->getMessage(), "\n";
25+
echo $e::class, ': ', $e->getMessage(), "\n";
2626
}
2727

2828
$i = new MyDateTimeImmutable();
2929
try {
3030
$m = DateTimeImmutable::createFromInterface( $i );
3131
} catch (\DateObjectError $e) {
32-
echo $e->getMessage(), "\n";
32+
echo $e::class, ': ', $e->getMessage(), "\n";
3333
}
3434
?>
3535
--EXPECTF--
36-
Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
37-
Object of type MyDateTimeImmutable (inheriting DateTimeImmutable) has not been correctly initialized by calling parent::__construct() in its constructor
36+
DateObjectError: Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
37+
DateObjectError: Object of type MyDateTimeImmutable (inheriting DateTimeImmutable) has not been correctly initialized by calling parent::__construct() in its constructor

ext/date/tests/DateTimeImmutable_createFromMutable-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var_dump( $i );
1212
try {
1313
DateTimeImmutable::createFromMutable( date_create_immutable( $current ) );
1414
} catch (TypeError $e) {
15-
echo $e->getMessage(), "\n";
15+
echo $e::class, ': ', $e->getMessage(), "\n";
1616
}
1717
?>
1818
--EXPECTF--
@@ -24,4 +24,4 @@ object(DateTimeImmutable)#%d (3) {
2424
["timezone"]=>
2525
string(13) "Europe/London"
2626
}
27-
DateTimeImmutable::createFromMutable(): Argument #1 ($object) must be of type DateTime, DateTimeImmutable given
27+
TypeError: DateTimeImmutable::createFromMutable(): Argument #1 ($object) must be of type DateTime, DateTimeImmutable given

ext/date/tests/DateTimeImmutable_createFromMutable-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var_dump( $i );
1414
try {
1515
MyDateTimeImmutable::createFromMutable( date_create_immutable( $current ) );
1616
} catch (TypeError $e) {
17-
echo $e->getMessage(), "\n";
17+
echo $e::class, ': ', $e->getMessage(), "\n";
1818
}
1919
?>
2020
--EXPECTF--
@@ -26,4 +26,4 @@ object(MyDateTimeImmutable)#%d (3) {
2626
["timezone"]=>
2727
string(13) "Europe/London"
2828
}
29-
DateTimeImmutable::createFromMutable(): Argument #1 ($object) must be of type DateTime, DateTimeImmutable given
29+
TypeError: DateTimeImmutable::createFromMutable(): Argument #1 ($object) must be of type DateTime, DateTimeImmutable given

ext/date/tests/DateTimeImmutable_createFromMutable_exceptions.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ $i = new MyDateTime();
1616
try {
1717
$m = DateTimeImmutable::createFromMutable( $i );
1818
} catch (\DateObjectError $e) {
19-
echo $e->getMessage(), "\n";
19+
echo $e::class, ': ', $e->getMessage(), "\n";
2020
}
2121
?>
2222
--EXPECTF--
23-
Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
23+
DateObjectError: Object of type MyDateTime (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor

ext/date/tests/DateTimeImmutable_modify_invalid_format.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ $datetime = new DateTimeImmutable;
77
try {
88
var_dump($datetime->modify(''));
99
} catch (DateMalformedStringException $e) {
10-
echo $e->getMessage(), "\n";
10+
echo $e::class, ': ', $e->getMessage(), "\n";
1111
}
1212

1313
?>
1414
--EXPECTF--
15-
DateTimeImmutable::modify(): Failed to parse time string () at position 0 ( ): Empty string
15+
DateMalformedStringException: DateTimeImmutable::modify(): Failed to parse time string () at position 0 ( ): Empty string

ext/date/tests/DateTimeImmutable_set_state_exception.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ foreach( $propertySets as $propertySet )
2121
$d = DateTimeImmutable::__set_state( $propertySet );
2222
echo "OK\n";
2323
} catch (\Error $e) {
24-
echo $e->getMessage(), "\n";
24+
echo $e::class, ': ', $e->getMessage(), "\n";
2525
}
2626
}
2727
?>
2828
--EXPECT--
2929
OK
3030
OK
31-
Invalid serialization data for DateTimeImmutable object
32-
Invalid serialization data for DateTimeImmutable object
33-
Invalid serialization data for DateTimeImmutable object
34-
Invalid serialization data for DateTimeImmutable object
35-
Invalid serialization data for DateTimeImmutable object
36-
Invalid serialization data for DateTimeImmutable object
37-
Invalid serialization data for DateTimeImmutable object
38-
Invalid serialization data for DateTimeImmutable object
31+
Error: Invalid serialization data for DateTimeImmutable object
32+
Error: Invalid serialization data for DateTimeImmutable object
33+
Error: Invalid serialization data for DateTimeImmutable object
34+
Error: Invalid serialization data for DateTimeImmutable object
35+
Error: Invalid serialization data for DateTimeImmutable object
36+
Error: Invalid serialization data for DateTimeImmutable object
37+
Error: Invalid serialization data for DateTimeImmutable object
38+
Error: Invalid serialization data for DateTimeImmutable object

0 commit comments

Comments
 (0)