From 4739a6c60501db3c69eb9b1b7917422fef92a96d Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 19 Sep 2024 08:20:08 +0200 Subject: [PATCH] Consolidate tests for invalid values --- tests/bson/bson-utcdatetime-008.phpt | 16 --------- tests/bson/bson-utcdatetime_error-003.phpt | 38 ---------------------- tests/bson/bson-utcdatetime_error-004.phpt | 19 ++++++++--- 3 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 tests/bson/bson-utcdatetime-008.phpt delete mode 100644 tests/bson/bson-utcdatetime_error-003.phpt diff --git a/tests/bson/bson-utcdatetime-008.phpt b/tests/bson/bson-utcdatetime-008.phpt deleted file mode 100644 index e8a9bb10f..000000000 --- a/tests/bson/bson-utcdatetime-008.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime construction from 64-bit integer as string ---FILE-- - new MongoDB\BSON\UTCDateTime('1416445411987'), MongoDB\Driver\Exception\InvalidArgumentException::class), PHP_EOL; - -?> -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or object, string given -===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-003.phpt b/tests/bson/bson-utcdatetime_error-003.phpt deleted file mode 100644 index 3b5afdcf3..000000000 --- a/tests/bson/bson-utcdatetime_error-003.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime constructor requires strings to parse as 64-bit integers ---FILE-- - -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or object, string given -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or object, string given -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or object, string given -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected integer or object, string given -===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-004.phpt b/tests/bson/bson-utcdatetime_error-004.phpt index e4d123a43..9e8798050 100644 --- a/tests/bson/bson-utcdatetime_error-004.phpt +++ b/tests/bson/bson-utcdatetime_error-004.phpt @@ -8,12 +8,19 @@ require_once __DIR__ . '/../utils/basic.inc'; /* UTCDateTime::__construct() internally converts floats to integers, so we will * not use a float to test for an invalid value. We also don't test an object, * since that is used for validating a possible DateTimeInterface argument. */ -$invalidValues = [true, []]; +$invalidValues = [ + true, + [], + // Numeric strings are no longer supported as of 2.0 + '1416445411987', + '1234.5678', +]; foreach ($invalidValues as $invalidValue) { - echo throws(function() use ($invalidValue) { - new MongoDB\BSON\UTCDateTime($invalidValue); - }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; + echo throws( + fn () => new MongoDB\BSON\UTCDateTime($invalidValue), + MongoDB\Driver\Exception\InvalidArgumentException::class, + ), PHP_EOL; } ?> @@ -24,4 +31,8 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected integer or object, bool given OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected integer or object, array given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected integer or object, string given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +Expected integer or object, string given ===DONE===