Skip to content

Commit d57b052

Browse files
committed
Extended tests
1 parent 5fb3641 commit d57b052

4 files changed

+77
-1
lines changed

ext/date/tests/DateInterval_serialize-001.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ var_dump($e);
1818

1919
echo "\n\nCalling __serialize manually:\n";
2020
var_dump($d->__serialize());
21+
22+
echo "\n\nUsed serialised interval:\n";
23+
$now = new DateTimeImmutable("2022-04-22 16:25:11 BST");
24+
var_dump($now->add($e));
25+
var_dump($now->sub($e));
2126
?>
2227
--EXPECTF--
2328
Original object:
@@ -97,3 +102,22 @@ array(%d) {
97102
["from_string"]=>
98103
bool(false)
99104
}
105+
106+
107+
Used serialised interval:
108+
object(DateTimeImmutable)#4 (3) {
109+
["date"]=>
110+
string(26) "2024-04-26 22:33:11.000000"
111+
["timezone_type"]=>
112+
int(2)
113+
["timezone"]=>
114+
string(3) "BST"
115+
}
116+
object(DateTimeImmutable)#4 (3) {
117+
["date"]=>
118+
string(26) "2020-04-18 10:17:11.000000"
119+
["timezone_type"]=>
120+
int(2)
121+
["timezone"]=>
122+
string(3) "BST"
123+
}

ext/date/tests/DateInterval_serialize-002.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ $d->__unserialize(
3737
]
3838
);
3939
var_dump($d);
40+
41+
echo "\n\nUsed serialised interval:\n";
42+
$now = new DateTimeImmutable("2022-04-15 10:27:27 BST");
43+
var_dump($now->add($e));
44+
var_dump($now->sub($e));
4045
?>
4146
--EXPECTF--
4247
Original object:
@@ -141,3 +146,22 @@ object(DateInterval)#5 (10) {
141146
["from_string"]=>
142147
bool(false)
143148
}
149+
150+
151+
Used serialised interval:
152+
object(DateTimeImmutable)#6 (3) {
153+
["date"]=>
154+
string(26) "2065-08-08 11:39:54.000000"
155+
["timezone_type"]=>
156+
int(2)
157+
["timezone"]=>
158+
string(3) "BST"
159+
}
160+
object(DateTimeImmutable)#6 (3) {
161+
["date"]=>
162+
string(26) "1978-12-22 09:15:00.000000"
163+
["timezone_type"]=>
164+
int(2)
165+
["timezone"]=>
166+
string(3) "BST"
167+
}

ext/date/tests/DateInterval_serialize-003.phpt

+28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Test DateInterval::__serialize and DateInterval::__unserialize
44
<?php
55
date_default_timezone_set("Europe/London");
66

7+
// the 15:30 gets ignored, as it's not a "relative" interval.
8+
// See: https://github.com/php/php-src/issues/8458
79
$d = DateInterval::createFromDateString('next weekday 15:30');
810
echo "Original object:\n";
911
var_dump($d);
@@ -28,6 +30,11 @@ $d->__unserialize(
2830
]
2931
);
3032
var_dump($d);
33+
34+
echo "\n\nUsed serialised interval:\n";
35+
$now = new DateTimeImmutable("2022-04-22 16:25:11 BST");
36+
var_dump($now->add($e));
37+
var_dump($now->sub($e));
3138
?>
3239
--EXPECTF--
3340
Original object:
@@ -68,3 +75,24 @@ object(DateInterval)#3 (2) {
6875
["date_string"]=>
6976
string(18) "next weekday 15:30"
7077
}
78+
79+
80+
Used serialised interval:
81+
object(DateTimeImmutable)#4 (3) {
82+
["date"]=>
83+
string(26) "2022-04-25 16:25:11.000000"
84+
["timezone_type"]=>
85+
int(2)
86+
["timezone"]=>
87+
string(3) "BST"
88+
}
89+
90+
Warning: DateTimeImmutable::sub(): Only non-special relative time specifications are supported for subtraction in %s on line %d
91+
object(DateTimeImmutable)#4 (3) {
92+
["date"]=>
93+
string(26) "2022-04-22 16:25:11.000000"
94+
["timezone_type"]=>
95+
int(2)
96+
["timezone"]=>
97+
string(3) "BST"
98+
}

ext/date/tests/bug52113.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object(DateInterval)#%d (%d) {
5656
bool(false)
5757
}
5858
string(164) "O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:11:"from_string";b:0;}"
59-
DateInterval::__set_state(array(
59+
\DateInterval::__set_state(array(
6060
'y' => 0,
6161
'm' => 0,
6262
'd' => 0,

0 commit comments

Comments
 (0)