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 b398dbb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 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===
19 changes: 18 additions & 1 deletion tests/bson/bson-utcdatetime-set_state_error-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ echo throws(function() {
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '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() {
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '9223372036854775808']);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '-9223372036854775809']);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
MongoDB\BSON\UTCDateTime::__set_state(['milliseconds' => '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===
20 changes: 19 additions & 1 deletion tests/bson/bson-utcdatetime_error-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ echo throws(function() {
new MongoDB\BSON\UTCDateTime('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() {
new MongoDB\BSON\UTCDateTime('9223372036854775808');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
new MongoDB\BSON\UTCDateTime('-9223372036854775809');
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
new MongoDB\BSON\UTCDateTime('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 b398dbb

Please sign in to comment.