-
Notifications
You must be signed in to change notification settings - Fork 213
Add tests to improve coverage of untested or under-tested APIs #1975
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
tests/bulkwritecommand/bulkwritecommand-ctor-options-combined-001.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\BulkWriteCommand::__construct() multiple options combined | ||
| --SKIPIF-- | ||
| <?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
| <?php skip_if_not_live(); ?> | ||
| <?php skip_if_server_version('<', '8.0'); ?> | ||
| <?php skip_if_not_clean(); ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require_once __DIR__ . "/../utils/basic.inc"; | ||
|
|
||
| class CommandLogger implements MongoDB\Driver\Monitoring\CommandSubscriber | ||
| { | ||
| public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void | ||
| { | ||
| if ($event->getCommandName() !== 'bulkWrite') { | ||
| return; | ||
| } | ||
|
|
||
| $command = $event->getCommand(); | ||
|
|
||
| printf("ordered: %s\n", var_export($command->ordered, true)); | ||
| printf("comment: %s\n", json_encode($command->comment)); | ||
| } | ||
|
|
||
| public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void | ||
| { | ||
| } | ||
|
|
||
| public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void | ||
| { | ||
| } | ||
| } | ||
|
|
||
| $manager = create_test_manager(); | ||
|
|
||
| $bulk = new MongoDB\Driver\BulkWriteCommand([ | ||
| 'ordered' => false, | ||
| 'comment' => 'test comment', | ||
| 'verboseResults' => true, | ||
| ]); | ||
| $bulk->insertOne(NS, ['_id' => 1]); | ||
| $bulk->insertOne(NS, ['_id' => 2]); | ||
|
|
||
| $manager->addSubscriber(new CommandLogger); | ||
| $result = $manager->executeBulkWriteCommand($bulk); | ||
|
|
||
| var_dump($result->getInsertedCount()); | ||
| var_dump($result->getInsertResults() !== null); | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| ordered: false | ||
| comment: "test comment" | ||
| int(2) | ||
| bool(true) | ||
| ===DONE=== | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Command construction (invalid maxAwaitTimeMS range) | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require_once __DIR__ . '/../utils/basic.inc'; | ||
|
|
||
| echo throws(function() { | ||
| new MongoDB\Driver\Command(['ping' => 1], ['maxAwaitTimeMS' => -1]); | ||
| }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
| Expected "maxAwaitTimeMS" option to be >= 0, -1 given | ||
| ===DONE=== |
22 changes: 22 additions & 0 deletions
22
tests/exception/connectiontimeoutexception-haserrorlabel-001.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Exception\ConnectionTimeoutException::hasErrorLabel() | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $exception = new MongoDB\Driver\Exception\ConnectionTimeoutException(); | ||
| $labels = ['test', 'foo']; | ||
|
|
||
| $reflection = new ReflectionClass($exception); | ||
| $errorLabelsProperty = $reflection->getProperty('errorLabels'); | ||
|
Member
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'll note that this property will become public as part of the properties rework. I'll make a note to update the tests and remove reflection where we no longer need it. |
||
| $errorLabelsProperty->setValue($exception, $labels); | ||
|
|
||
| var_dump($exception->hasErrorLabel('foo')); | ||
| var_dump($exception->hasErrorLabel('bar')); | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(false) | ||
| ===DONE=== | ||
22 changes: 22 additions & 0 deletions
22
tests/exception/executiontimeoutexception-haserrorlabel-001.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Exception\ExecutionTimeoutException::hasErrorLabel() | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $exception = new MongoDB\Driver\Exception\ExecutionTimeoutException(); | ||
| $labels = ['test', 'foo']; | ||
|
|
||
| $reflection = new ReflectionClass($exception); | ||
| $errorLabelsProperty = $reflection->getProperty('errorLabels'); | ||
| $errorLabelsProperty->setValue($exception, $labels); | ||
|
|
||
| var_dump($exception->hasErrorLabel('foo')); | ||
| var_dump($exception->hasErrorLabel('bar')); | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(false) | ||
| ===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Query construction with maxAwaitTimeMS option | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 0]); | ||
| echo "maxAwaitTimeMS=0: OK\n"; | ||
|
|
||
| $q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 1000]); | ||
| echo "maxAwaitTimeMS=1000: OK\n"; | ||
|
GromNaN marked this conversation as resolved.
|
||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| maxAwaitTimeMS=0: OK | ||
| maxAwaitTimeMS=1000: OK | ||
| ===DONE=== | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Query construction with maxAwaitTimeMS option (64-bit) | ||
| --SKIPIF-- | ||
| <?php if (8 !== PHP_INT_SIZE) { die('skip Only for 64-bit platform'); } ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $q = new MongoDB\Driver\Query([], ['maxAwaitTimeMS' => 4294967295]); | ||
| echo "maxAwaitTimeMS=4294967295: OK\n"; | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| maxAwaitTimeMS=4294967295: OK | ||
| ===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --TEST-- | ||
| MongoDB\Driver\Session::getServer() | ||
| --SKIPIF-- | ||
| <?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
| <?php skip_if_not_libmongoc_crypto(); ?> | ||
| <?php skip_if_not_live(); ?> | ||
| --FILE-- | ||
| <?php | ||
| require_once __DIR__ . "/../utils/basic.inc"; | ||
|
|
||
| $manager = create_test_manager(); | ||
| $session = $manager->startSession(); | ||
|
|
||
| /* Session::getServer() currently returns null, as sessions are not pinned | ||
| * to a server. */ | ||
| var_dump($session->getServer()); | ||
|
|
||
| ?> | ||
| ===DONE=== | ||
| <?php exit(0); ?> | ||
| --EXPECT-- | ||
| NULL | ||
| ===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.