-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-424: Validate that RP tag set is an array of documents #399
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,15 @@ echo throws(function() { | |
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, array('readPreference' => 'nothing')); | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, ['readPreference' => 'nothing']); | ||
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE . '/?readPreference=primary', array('readPreferenceTags' => array(array()))); | ||
$manager = new MongoDB\Driver\Manager(STANDALONE . '/?readPreference=primary', ['readPreferenceTags' => [[]]]); | ||
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE . '/?readPreference=primary', ['readPreferenceTags' => ['invalid']]); | ||
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n"; | ||
|
||
?> | ||
|
@@ -28,4 +32,6 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException | |
Unsupported readPreference value: 'nothing' | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Primary read preference mode conflicts with tags | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Read preference tags must be an array of zero or more documents | ||
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. I think this should say "Primary read preference mode conflicts with tags". It doesn't matter whether they're valid or not yet. 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 is more consistent with the ReadPreference constructor. We're validating individual values before we check the combined state of the read preference. Of course, they'll end up seeing both exceptions in due time (the second will appear after they resolve the first issue). On that note, I think there's an oversight in 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. I added another case to the ReadPreference ctor test to demonstrate that it also reports invalid tag set structure first (before the primary conflict). |
||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
--TEST-- | ||
MongoDB\Driver\ReadPreference construction (invalid arguments) | ||
MongoDB\Driver\ReadPreference construction (invalid mode) | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
echo throws(function() { | ||
new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, array(array("tag" => "one"))); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
new MongoDB\Driver\ReadPreference(42); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Invalid tagSets | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Invalid mode: 42 | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
MongoDB\Driver\ReadPreference construction (invalid tagSets) | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
echo throws(function() { | ||
new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, [['tag' => 'one']]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, ['invalid']); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, ['invalid']); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
tagSets may not be used with primary mode | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
tagSets must be an array of zero or more documents | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
tagSets must be an array of zero or more documents | ||
===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.
This single-case
switch
should make sense once you see #400. Since I was refactoring the tagSet validation already, I opted to restructure this early. It should also make the diff for PHPC-752's commit easier to understand.