Skip to content

Commit 8f6639b

Browse files
committed
PHPC-1957 Add tests for out-of-range UTCDateTime values
1 parent 0ab1737 commit 8f6639b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tests/bson/bson-utcdatetime-serialization_error-002.phpt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,29 @@ echo throws(function() {
99
unserialize('C:24:"MongoDB\BSON\UTCDateTime":42:{a:1:{s:12:"milliseconds";s:9:"1234.5678";}}');
1010
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1111

12-
/* TODO: Add tests for out-of-range values once CDRIVER-1377 is resolved */
12+
// Out-of-range values
13+
echo throws(function() {
14+
unserialize('C:24:"MongoDB\BSON\UTCDateTime":53:{a:1:{s:12:"milliseconds";s:19:"9223372036854775808";}}');
15+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
16+
17+
echo throws(function() {
18+
unserialize('C:24:"MongoDB\BSON\UTCDateTime":54:{a:1:{s:12:"milliseconds";s:20:"-9223372036854775809";}}');
19+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
20+
21+
echo throws(function() {
22+
unserialize('C:24:"MongoDB\BSON\UTCDateTime":54:{a:1:{s:12:"milliseconds";s:20:"18446744073709551615";}}');
23+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1324

1425
?>
1526
===DONE===
1627
<?php exit(0); ?>
1728
--EXPECT--
1829
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
1930
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
31+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
32+
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
33+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
34+
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
35+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
36+
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
2037
===DONE===

tests/bson/bson-utcdatetime-serialization_error-004.phpt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,29 @@ echo throws(function() {
99
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:9:"1234.5678";}');
1010
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1111

12-
/* TODO: Add tests for out-of-range values once CDRIVER-1377 is resolved */
12+
// Out-of-range values
13+
echo throws(function() {
14+
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:19:"9223372036854775808";}');
15+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
16+
17+
echo throws(function() {
18+
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:20:"-9223372036854775809";}');
19+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
20+
21+
echo throws(function() {
22+
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:20:"18446744073709551615";}');
23+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1324

1425
?>
1526
===DONE===
1627
<?php exit(0); ?>
1728
--EXPECT--
1829
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
1930
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
31+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
32+
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
33+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
34+
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
35+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
36+
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
2037
===DONE===

0 commit comments

Comments
 (0)