Skip to content

Commit

Permalink
Consolidate tests for invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 20, 2024
1 parent 7cbea84 commit 4739a6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 58 deletions.
16 changes: 0 additions & 16 deletions tests/bson/bson-utcdatetime-008.phpt

This file was deleted.

38 changes: 0 additions & 38 deletions tests/bson/bson-utcdatetime_error-003.phpt

This file was deleted.

19 changes: 15 additions & 4 deletions tests/bson/bson-utcdatetime_error-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

?>
Expand All @@ -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===

0 comments on commit 4739a6c

Please sign in to comment.