-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-355: Add test for ConnectionTimeoutException #773
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
Conversation
tests/manager/connect-error-001.phpt
Outdated
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; |
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.
We're not using any of the mongo-orchestration constants, so this can be require_once __DIR__ . '/../utils/tools.php';
instead.
tests/manager/connect-error-001.phpt
Outdated
--TEST-- | ||
MongoDB\Driver\Manager - no connection (command) | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
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 --SKIPIF--
shouldn't be needed, as we don't depend on mongo-orchestration.
tests/manager/connect-error-001.phpt
Outdated
$command = new MongoDB\Driver\Command(['drop' => 'test']); | ||
|
||
throws(function() use($manager, $command) { | ||
$retval = $manager->executeCommand(NS, $command); |
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 probably doesn't need to assign the return value to anything.
tests/manager/connect-error-001.phpt
Outdated
|
||
$command = new MongoDB\Driver\Command(['drop' => 'test']); | ||
|
||
throws(function() use($manager, $command) { |
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.
Can we use echo throws(...), "\n";
and add the exception message to the expected output? That may require some pattern matching for dynamic values in the string, which will warrant using EXPECTF
instead of EXPECT
. For reference on pattern matching, see https://qa.php.net/phpt_details.php#expectf_section.
tests/manager/connect-error-001.phpt
Outdated
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException | ||
===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.
If it's easy to configure Vim to do so: newlines at the end of the file 👌
tests/manager/connect-error-001.phpt
Outdated
|
||
$manager = new MongoDB\Driver\Manager("mongodb://localhost:44444/?serverselectiontimeoutms=10"); | ||
|
||
$command = new MongoDB\Driver\Command(['drop' => 'test']); |
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.
I know it makes no difference in execution, but ['ping' => 1]
would be more appropriate. Also considering we're using executeCommand()
below instead of executeWriteCommand()
, that sets a better example for any users that might see this.
tests/manager/connect-error-001.phpt
Outdated
@@ -0,0 +1,22 @@ | |||
--TEST-- | |||
MongoDB\Driver\Manager - no connection (command) |
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.
I'd suggest naming the file manager-executeCommand_error-003.phpt
(there is a gap between 002
and 004
, so we can fill it. And then "MongoDB\Driver\Manager::executeCommand() connection error" as a test name.
Down the line, we can make copies of this test for other execute methods on Manager and Server. The naming convention becomes much more practical in that case.
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.
LGTM.
https://jira.mongodb.org/browse/PHPC-355