Skip to content

Commit

Permalink
PHPC-1957 Add tests for out-of-range UTCDateTime values
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jul 19, 2024
1 parent 0ab1737 commit 8f6639b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion tests/bson/bson-utcdatetime-serialization_error-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ echo throws(function() {
unserialize('C:24:"MongoDB\BSON\UTCDateTime":42:{a:1:{s:12:"milliseconds";s:9:"1234.5678";}}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

/* TODO: Add tests for out-of-range values once CDRIVER-1377 is resolved */
// Out-of-range values
echo throws(function() {
unserialize('C:24:"MongoDB\BSON\UTCDateTime":53:{a:1:{s:12:"milliseconds";s:19:"9223372036854775808";}}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
unserialize('C:24:"MongoDB\BSON\UTCDateTime":54:{a:1:{s:12:"milliseconds";s:20:"-9223372036854775809";}}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
unserialize('C:24:"MongoDB\BSON\UTCDateTime":54:{a:1:{s:12:"milliseconds";s:20:"18446744073709551615";}}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
===DONE===
19 changes: 18 additions & 1 deletion tests/bson/bson-utcdatetime-serialization_error-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ echo throws(function() {
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:9:"1234.5678";}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

/* TODO: Add tests for out-of-range values once CDRIVER-1377 is resolved */
// Out-of-range values
echo throws(function() {
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:19:"9223372036854775808";}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:20:"-9223372036854775809";}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
unserialize('O:24:"MongoDB\BSON\UTCDateTime":1:{s:12:"milliseconds";s:20:"18446744073709551615";}');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization
===DONE===

0 comments on commit 8f6639b

Please sign in to comment.