Skip to content

Commit d3f3d7b

Browse files
authored
PHPC-1957 Add tests for out-of-range UTCDateTime values (#1614)
1 parent 0ab1737 commit d3f3d7b

4 files changed

+73
-4
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===

tests/bson/bson-utcdatetime-set_state_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
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '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+
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '9223372036854775808']);
15+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
16+
17+
echo throws(function() {
18+
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '-9223372036854775809']);
19+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
20+
21+
echo throws(function() {
22+
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '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_error-003.phpt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,30 @@ echo throws(function() {
99
new MongoDB\BSON\UTCDateTime('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+
new MongoDB\BSON\UTCDateTime('9223372036854775808');
15+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
16+
17+
echo throws(function() {
18+
new MongoDB\BSON\UTCDateTime('-9223372036854775809');
19+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
20+
21+
echo throws(function() {
22+
new MongoDB\BSON\UTCDateTime('18446744073709551615');
23+
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
24+
1325

1426
?>
1527
===DONE===
1628
<?php exit(0); ?>
1729
--EXPECT--
1830
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
1931
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
32+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33+
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
34+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35+
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
36+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
37+
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
2038
===DONE===

0 commit comments

Comments
 (0)