Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ var_dump(MyDatePeriod::createFromISO8601String("R4/2012-07-01T00:00:00Z/P7D"));
try {
MyDatePeriod::createFromISO8601String("R4/2012-07-01T00:/P7D");
} catch (DateMalformedPeriodStringException $e) {
echo $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
MyDatePeriod::createFromISO8601String("R4/2012-07-01T00:00:00Z");
} catch (DateMalformedPeriodStringException $e) {
echo $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
Expand Down Expand Up @@ -65,5 +65,5 @@ object(MyDatePeriod)#1 (7) {
["include_end_date"]=>
bool(false)
}
Unknown or bad format (R4/2012-07-01T00:/P7D)
DatePeriod::createFromISO8601String(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given
DateMalformedPeriodStringException: Unknown or bad format (R4/2012-07-01T00:/P7D)
DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given
4 changes: 2 additions & 2 deletions ext/date/tests/DatePeriod_wrong_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ date.timezone=UTC
try {
new DatePeriod();
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
echo $exception::class, ': ', $exception->getMessage(), "\n";
}
?>
--EXPECT--
DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments
TypeError: DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ DatePeriod: Test wrong recurrence parameter on __construct
try {
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
} catch (Exception $exception) {
echo $exception->getMessage(), "\n";
echo $exception::class, ': ', $exception->getMessage(), "\n";
}

try {
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), -1);
} catch (Exception $exception) {
echo $exception->getMessage(), "\n";
echo $exception::class, ': ', $exception->getMessage(), "\n";
}

?>
--EXPECTF--
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
14 changes: 7 additions & 7 deletions ext/date/tests/bug-gh11416.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ $date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
try {
new DatePeriod($date, new DateInterval('P1D'), 2);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and following) safe us a function call; not style-only.

echo $e::class, ': ', $e->getMessage(), "\n";
}

$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
try {
new DatePeriod($now, new DateInterval('P1D'), $date);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
Expand All @@ -27,25 +27,25 @@ $dateinterval = (new ReflectionClass(DateInterval::class))->newInstanceWithoutCo
try {
$dateperiod->__unserialize(['start' => $date]);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
$dateperiod->__unserialize(['start' => $now, 'end' => $date]);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
$dateperiod->__unserialize(['start' => $now, 'end' => $now, 'current' => $date]);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
$dateperiod->__unserialize(['start' => $now, 'end' => $now, 'current' => $now, 'interval' => $dateinterval]);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
Expand All @@ -55,7 +55,7 @@ try {
]);
echo "DatePeriod::__unserialize: SUCCESS\n";
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}
echo "OK\n";
?>
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/bug-gh15582.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $fusion = $mdtz;
try {
date_create("2005-07-14 22:30:41", $fusion);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
Expand Down
16 changes: 8 additions & 8 deletions ext/date/tests/bug-gh8471.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $mutable = $reflection->newInstanceWithoutConstructor();
try {
$immutable = \DateTimeImmutable::createFromMutable($mutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
echo $t::class, ': ', $t->getMessage(), "\n";
}


Expand All @@ -18,7 +18,7 @@ $mutable = $reflection->newInstanceWithoutConstructor();
try {
$immutable = \DateTimeImmutable::createFromInterface($mutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
echo $t::class, ': ', $t->getMessage(), "\n";
}


Expand All @@ -28,7 +28,7 @@ $immutable = $reflection->newInstanceWithoutConstructor();
try {
$mutable = \DateTime::createFromImmutable($immutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
echo $t::class, ': ', $t->getMessage(), "\n";
}


Expand All @@ -38,13 +38,13 @@ $immutable = $reflection->newInstanceWithoutConstructor();
try {
$mutable = \DateTime::createFromInterface($immutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
echo $t::class, ': ', $t->getMessage(), "\n";
}


?>
--EXPECTF--
Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
DateObjectError: Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
DateObjectError: Object of type DateTime has not been correctly initialized by calling parent::__construct() in its constructor
DateObjectError: Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
DateObjectError: Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor
2 changes: 1 addition & 1 deletion ext/date/tests/bug51819.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foreach ($aTz as $sTz) {
try {
$oDateTime = new DateTime($sDate);
} catch (Exception $oException) {
var_dump($oException->getMessage());
echo $oException::class, ': ', $oException->getMessage(), "\n";
print_r(DateTime::getLastErrors());
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/date/tests/bug54283.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Bug #54283 (new DatePeriod(NULL) causes crash)
try {
var_dump(new DatePeriod(NULL));
} catch (Exception $e) {
var_dump($e->getMessage());
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
Deprecated: DatePeriod::__construct(): Passing null to parameter #1 ($start) of type string is deprecated in %s on line %d

Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d
string(24) "Unknown or bad format ()"
DateMalformedPeriodStringException: Unknown or bad format ()
4 changes: 2 additions & 2 deletions ext/date/tests/bug62500.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Crasher extends DateInterval {
try {
$c = new Crasher('blah');
} catch (Exception $e) {
var_dump($e->getMessage());
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECTF--
Expand All @@ -26,4 +26,4 @@ int(3)

Warning: Undefined property: Crasher::$2 in %s on line %d
NULL
string(28) "Unknown or bad format (blah)"
DateMalformedIntervalStringException: Unknown or bad format (blah)
1 change: 0 additions & 1 deletion ext/date/tests/bug71826.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ int(28)
c(Asia/Tokyo): 2015-4-1 <--> 2015-4-29
int(0)
int(28)

@NickSdot NickSdot Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and following) removes double empty last line.

12 changes: 6 additions & 6 deletions ext/date/tests/bug72963.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ foreach ($strings as $string) {
try {
$d1 = DateTime::createFromFormat('!m/d/Y', $string);
} catch (ValueError $v) {
echo $v->getMessage(), "\n";
echo $v::class, ': ', $v->getMessage(), "\n";
}

try {
$d2 = DateTimeImmutable::createFromFormat('!m/d/Y', $string);
} catch (ValueError $v) {
echo $v->getMessage(), "\n";
echo $v::class, ': ', $v->getMessage(), "\n";
}

try {
$d3 = date_parse_from_format('m/d/Y', $string);
} catch (ValueError $v) {
echo $v->getMessage(), "\n";
echo $v::class, ': ', $v->getMessage(), "\n";
}

var_dump($d1, $d2, $d3);
Expand Down Expand Up @@ -84,9 +84,9 @@ array(12) {

Covering string: 8/8/2016\0asf

DateTime::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
DateTimeImmutable::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
date_parse_from_format(): Argument #2 ($datetime) must not contain any null bytes
ValueError: DateTime::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
ValueError: DateTimeImmutable::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
ValueError: date_parse_from_format(): Argument #2 ($datetime) must not contain any null bytes
NULL
NULL
NULL
1 change: 0 additions & 1 deletion ext/date/tests/bug77097.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ float(0.781751)
int(0)
int(0)
float(0.781751)

1 change: 0 additions & 1 deletion ext/date/tests/bug78139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ Parsing 'UTC xx':
Warning: timezone_open(): Unknown or bad timezone (UTC xx) in %sbug78139.php on line %d
bool(false)
DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)

8 changes: 4 additions & 4 deletions ext/date/tests/createFromTimestamp.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ foreach ($timestamps as $ts) {
try {
var_dump(DateTime::createFromTimestamp($ts));
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo 'DateTimeImmutable::createFromTimestamp(' . var_export($ts, true) . '): ';
try {
var_dump(DateTimeImmutable::createFromTimestamp($ts));
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}
}

echo 'MyDateTime::createFromTimestamp(' . var_export(0, true) . '): ';
try {
var_dump(MyDateTime::createFromTimestamp(0));
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo 'MyDateTimeImmutable::createFromTimestamp(' . var_export(0, true) . '): ';
try {
var_dump(MyDateTimeImmutable::createFromTimestamp(0));
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
Expand Down
4 changes: 2 additions & 2 deletions ext/date/tests/date_interval_set_state_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ try {
]
);
} catch (Error $e) {
echo $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

var_dump($interval);
Expand Down Expand Up @@ -43,7 +43,7 @@ object(DateInterval)#%d (%d) {
["from_string"]=>
bool(false)
}
Unknown or bad format (wrong) at position 0 (w) while unserializing: The timezone could not be found in the database
Error: Unknown or bad format (wrong) at position 0 (w) while unserializing: The timezone could not be found in the database
object(DateInterval)#%d (%d) {
["y"]=>
int(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ foreach ($dp as $day) {
2010-06-08
2010-06-09
2010-06-10

32 changes: 16 additions & 16 deletions ext/date/tests/date_period_unset_property.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,58 @@ unset($period->prop);
try {
$period->prop;
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->start);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->current);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->end);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->interval);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->recurrences);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->include_start_date);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
unset($period->include_end_date);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Typed property MyDatePeriod::$prop must not be accessed before initialization
Cannot unset MyDatePeriod::$start
Cannot unset MyDatePeriod::$current
Cannot unset MyDatePeriod::$end
Cannot unset MyDatePeriod::$interval
Cannot unset MyDatePeriod::$recurrences
Cannot unset MyDatePeriod::$include_start_date
Cannot unset MyDatePeriod::$include_end_date
Error: Typed property MyDatePeriod::$prop must not be accessed before initialization
Error: Cannot unset MyDatePeriod::$start
Error: Cannot unset MyDatePeriod::$current
Error: Cannot unset MyDatePeriod::$end
Error: Cannot unset MyDatePeriod::$interval
Error: Cannot unset MyDatePeriod::$recurrences
Error: Cannot unset MyDatePeriod::$include_start_date
Error: Cannot unset MyDatePeriod::$include_end_date
Loading
Loading