From b398dbbec0f53cfbc9b2fe8e54a1c13915f7ee4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 19 Jul 2024 13:32:27 +0200 Subject: [PATCH] PHPC-1957 Add tests for out-of-range UTCDateTime values --- ...n-utcdatetime-serialization_error-002.phpt | 19 +++++++++++++++++- ...n-utcdatetime-serialization_error-004.phpt | 19 +++++++++++++++++- .../bson-utcdatetime-set_state_error-002.phpt | 19 +++++++++++++++++- tests/bson/bson-utcdatetime_error-003.phpt | 20 ++++++++++++++++++- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/tests/bson/bson-utcdatetime-serialization_error-002.phpt b/tests/bson/bson-utcdatetime-serialization_error-002.phpt index 01dd45ced..ad59d46dd 100644 --- a/tests/bson/bson-utcdatetime-serialization_error-002.phpt +++ b/tests/bson/bson-utcdatetime-serialization_error-002.phpt @@ -9,7 +9,18 @@ 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=== @@ -17,4 +28,10 @@ echo throws(function() { --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=== diff --git a/tests/bson/bson-utcdatetime-serialization_error-004.phpt b/tests/bson/bson-utcdatetime-serialization_error-004.phpt index c5ceeb274..d84d78918 100644 --- a/tests/bson/bson-utcdatetime-serialization_error-004.phpt +++ b/tests/bson/bson-utcdatetime-serialization_error-004.phpt @@ -9,7 +9,18 @@ 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=== @@ -17,4 +28,10 @@ echo throws(function() { --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=== diff --git a/tests/bson/bson-utcdatetime-set_state_error-002.phpt b/tests/bson/bson-utcdatetime-set_state_error-002.phpt index 15c4c9377..0bf5f47ac 100644 --- a/tests/bson/bson-utcdatetime-set_state_error-002.phpt +++ b/tests/bson/bson-utcdatetime-set_state_error-002.phpt @@ -9,7 +9,18 @@ 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=== @@ -17,4 +28,10 @@ echo throws(function() { --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=== diff --git a/tests/bson/bson-utcdatetime_error-003.phpt b/tests/bson/bson-utcdatetime_error-003.phpt index d18042c85..760eff8b2 100644 --- a/tests/bson/bson-utcdatetime_error-003.phpt +++ b/tests/bson/bson-utcdatetime_error-003.phpt @@ -9,7 +9,19 @@ 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=== @@ -17,4 +29,10 @@ echo throws(function() { --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===