Skip to content

Commit 188c7ec

Browse files
committed
PHPC-631: Regression tests for UTCDateTime::toDateTime()
1 parent 08902ba commit 188c7ec

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

tests/bson/bson-utcdatetime-int-size.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object(MongoDB\BSON\UTCDateTime)#%d (1) {
2626
}
2727
object(DateTime)#%d (3) {
2828
["date"]=>
29-
string(29) "2014-11-20 01:03:31.987000000"
29+
string(26) "2014-11-20 01:03:31.987000"
3030
["timezone_type"]=>
3131
int(1)
3232
["timezone"]=>
@@ -39,7 +39,7 @@ object(MongoDB\BSON\UTCDateTime)#%d (1) {
3939
}
4040
object(DateTime)#%d (3) {
4141
["date"]=>
42-
string(29) "2014-11-20 01:03:31.987000000"
42+
string(26) "2014-11-20 01:03:31.987000"
4343
["timezone_type"]=>
4444
int(1)
4545
["timezone"]=>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
BSON BSON\UTCDateTime::toDateTime() dumping seconds and microseconds
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
use MongoDB\BSON as BSON;
8+
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$utcdatetime = new BSON\UTCDateTime("1416445411987");
12+
$datetime = $utcdatetime->toDateTime();
13+
echo $datetime->format('U.u'), "\n";
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECT--
19+
1416445411.987000
20+
===DONE===

tests/bson/bug0631.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
PHPC-631: UTCDateTime::toDateTime() may return object that cannot be serialized
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$utcdatetime = new MongoDB\BSON\UTCDateTime(1466540755123);
10+
$datetime = $utcdatetime->toDateTime();
11+
$s = serialize($datetime);
12+
13+
var_dump($datetime);
14+
15+
echo "\n", $s, "\n\n";
16+
17+
var_dump(unserialize($s));
18+
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECTF--
23+
object(DateTime)#%d (%d) {
24+
["date"]=>
25+
string(26) "2016-06-21 20:25:55.123000"
26+
["timezone_type"]=>
27+
int(1)
28+
["timezone"]=>
29+
string(6) "+00:00"
30+
}
31+
32+
O:8:"DateTime":3:{s:4:"date";s:26:"2016-06-21 20:25:55.123000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}
33+
34+
object(DateTime)#%d (%d) {
35+
["date"]=>
36+
string(26) "2016-06-21 20:25:55.123000"
37+
["timezone_type"]=>
38+
int(1)
39+
["timezone"]=>
40+
string(6) "+00:00"
41+
}
42+
===DONE===

0 commit comments

Comments
 (0)