-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-2444: Remove support for string arguments in UTCDateTime constructor #1662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,20 +8,31 @@ 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; | ||
} | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Expected integer or string, bool given | ||
Expected integer or object, bool given | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test file looks perfectly serviceable to add a case for a numeric string. I don't think we need to bother with testing a non-numeric string since it'd just trigger the same code path in the constructor. I'd suggest removing both of the other test files and adding to the comment about |
||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Expected integer or string, array given | ||
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=== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd that "object" was never included in the original message. Looks like that dates back to 8d7e358.