Skip to content

Commit 31b2dcb

Browse files
MarkBakerpetk
authored andcommitted
Tests for __set_state magic method
Tests for __set_state magic method for DateTime, DateTimeImmutable, DateTimeZone and DatePeriod.
1 parent 1253a68 commit 31b2dcb

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
Test __set_state magic method for recreating a DatePeriod object
3+
--CREDITS--
4+
Mark Baker [email protected] at the PHPNW2017 Conference for PHP Testfest 2017
5+
--FILE--
6+
<?php
7+
8+
$datePeriodObject = new DatePeriod(
9+
new DateTime('2017-10-06 23:30', new DateTimeZone('UTC')),
10+
new DateInterval('PT1H30M'),
11+
24
12+
);
13+
14+
$datePeriodState = var_export($datePeriodObject, true);
15+
16+
eval("\$datePeriodObjectNew = {$datePeriodState};");
17+
18+
var_dump($datePeriodObjectNew);
19+
20+
?>
21+
--EXPECTF--
22+
object(DatePeriod)#%d (6) {
23+
["start"]=>
24+
object(DateTime)#%d (3) {
25+
["date"]=>
26+
string(26) "2017-10-06 23:30:00.000000"
27+
["timezone_type"]=>
28+
int(3)
29+
["timezone"]=>
30+
string(3) "UTC"
31+
}
32+
["current"]=>
33+
NULL
34+
["end"]=>
35+
NULL
36+
["interval"]=>
37+
object(DateInterval)#%d (16) {
38+
["y"]=>
39+
int(0)
40+
["m"]=>
41+
int(0)
42+
["d"]=>
43+
int(0)
44+
["h"]=>
45+
int(1)
46+
["i"]=>
47+
int(30)
48+
["s"]=>
49+
int(0)
50+
["f"]=>
51+
float(0)
52+
["weekday"]=>
53+
int(0)
54+
["weekday_behavior"]=>
55+
int(0)
56+
["first_last_day_of"]=>
57+
int(0)
58+
["invert"]=>
59+
int(0)
60+
["days"]=>
61+
int(0)
62+
["special_type"]=>
63+
int(0)
64+
["special_amount"]=>
65+
int(0)
66+
["have_weekday_relative"]=>
67+
int(0)
68+
["have_special_relative"]=>
69+
int(0)
70+
}
71+
["recurrences"]=>
72+
int(25)
73+
["include_start_date"]=>
74+
bool(true)
75+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test __set_state magic method for recreating a DateTimeImmutable object
3+
--CREDITS--
4+
Mark Baker [email protected] at the PHPNW2017 Conference for PHP Testfest 2017
5+
--FILE--
6+
<?php
7+
8+
$datettimeObject = new DateTimeImmutable('2017-10-06 23:30:00', new DateTimezone('UTC'));
9+
10+
$datetimeState = var_export($datettimeObject, true);
11+
12+
eval("\$datetimeObjectNew = {$datetimeState};");
13+
14+
var_dump($datetimeObjectNew);
15+
16+
?>
17+
--EXPECTF--
18+
object(DateTimeImmutable)#%d (3) {
19+
["date"]=>
20+
string(26) "2017-10-06 23:30:00.000000"
21+
["timezone_type"]=>
22+
int(3)
23+
["timezone"]=>
24+
string(3) "UTC"
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Test __set_state magic method for recreating a DateTimeZone object
3+
--CREDITS--
4+
Mark Baker [email protected] at the PHPNW2017 Conference for PHP Testfest 2017
5+
--FILE--
6+
<?php
7+
8+
$datetimezoneObject = new DateTimezone('UTC');
9+
10+
$datetimezoneState = var_export($datetimezoneObject, true);
11+
12+
eval("\$datetimezoneObjectNew = {$datetimezoneState};");
13+
14+
var_dump($datetimezoneObjectNew);
15+
16+
?>
17+
--EXPECTF--
18+
object(DateTimeZone)#%d (2) {
19+
["timezone_type"]=>
20+
int(3)
21+
["timezone"]=>
22+
string(3) "UTC"
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test __set_state magic method for recreating a DateTime object
3+
--CREDITS--
4+
Mark Baker [email protected] at the PHPNW2017 Conference for PHP Testfest 2017
5+
--FILE--
6+
<?php
7+
8+
$datettimeObject = new DateTime('2017-10-06 23:30:00', new DateTimezone('UTC'));
9+
10+
$datetimeState = var_export($datettimeObject, true);
11+
12+
eval("\$datetimeObjectNew = {$datetimeState};");
13+
14+
var_dump($datetimeObjectNew);
15+
16+
?>
17+
--EXPECTF--
18+
object(DateTime)#%d (3) {
19+
["date"]=>
20+
string(26) "2017-10-06 23:30:00.000000"
21+
["timezone_type"]=>
22+
int(3)
23+
["timezone"]=>
24+
string(3) "UTC"
25+
}

0 commit comments

Comments
 (0)