Skip to content

PHPLIB-909: Add more error response tests #1012

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 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,15 @@ axes:
display_name: Driver Version
values:
- id: "oldest-supported"
display_name: "PHPC 1.15.0"
display_name: "PHPC 1.16.0"
variables:
EXTENSION_VERSION: "1.15.0"
EXTENSION_BRANCH: "master"
# EXTENSION_VERSION: "1.16.0"
- id: "latest-stable"
display_name: "PHPC (1.15.x)"
display_name: "PHPC (1.16.x)"
variables:
EXTENSION_VERSION: "stable"
EXTENSION_BRANCH: "master"
# EXTENSION_VERSION: "stable"
- id: "latest-dev"
display_name: "PHPC (1.16-dev)"
variables:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^7.2 || ^8.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.15.0",
"ext-mongodb": "^1.16.0",
"jean85/pretty-package-versions": "^1.2 || ^2.0.1",
"symfony/polyfill-php80": "^1.19"
},
Expand Down
15 changes: 13 additions & 2 deletions tests/UnifiedSpecTests/ExpectedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MongoDB\Driver\Exception\ExecutionTimeoutException;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Exception\ServerException;
use MongoDB\Driver\Exception\WriteException;
use MongoDB\Tests\UnifiedSpecTests\Constraint\Matches;
use PHPUnit\Framework\Assert;
use stdClass;
Expand All @@ -15,6 +16,7 @@
use function get_class;
use function PHPUnit\Framework\assertArrayHasKey;
use function PHPUnit\Framework\assertContainsOnly;
use function PHPUnit\Framework\assertCount;
use function PHPUnit\Framework\assertFalse;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertIsArray;
Expand All @@ -30,6 +32,8 @@
use function PHPUnit\Framework\assertStringContainsStringIgnoringCase;
use function PHPUnit\Framework\assertThat;
use function PHPUnit\Framework\assertTrue;
use function PHPUnit\Framework\isInstanceOf;
use function PHPUnit\Framework\logicalOr;
use function property_exists;
use function sprintf;

Expand Down Expand Up @@ -166,8 +170,15 @@ public function assert(?Throwable $e = null): void
}

if (isset($this->matchesResultDocument)) {
assertInstanceOf(CommandException::class, $e);
assertThat($e->getResultDocument(), $this->matchesResultDocument, 'CommandException result document matches');
assertThat($e, logicalOr(isInstanceOf(CommandException::class), isInstanceOf(WriteException::class)));

if ($e instanceof CommandException) {
assertThat($e->getResultDocument(), $this->matchesResultDocument, 'CommandException result document matches');
} elseif ($e instanceof WriteException) {
$writeErrors = $e->getWriteResult()->getErrorReplies();
assertCount(1, $writeErrors);
assertThat($writeErrors[0], $this->matchesResultDocument, 'WriteException result document matches');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't addressed in the spec (see: expectedError) but this is the correct approach. I intentionally only issued to single commands in the corresponding write command tests for this reason.

}
}

if (! empty($this->excludedLabels) || ! empty($this->includedLabels)) {
Expand Down
5 changes: 0 additions & 5 deletions tests/UnifiedSpecTests/UnifiedSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ class UnifiedSpecTest extends FunctionalTestCase
'valid-pass/createEntities-operation: createEntities operation' => 'CSOT is not yet implemented (PHPC-1760)',
'valid-pass/entity-cursor-iterateOnce: iterateOnce' => 'CSOT is not yet implemented (PHPC-1760)',
'valid-pass/matches-lte-operator: special lte matching operator' => 'CSOT is not yet implemented (PHPC-1760)',
// BulkWriteException cannot access server response
'crud/bulkWrite-errorResponse: bulkWrite operations support errorResponse assertions' => 'BulkWriteException cannot access server response',
'crud/deleteOne-errorResponse: delete operations support errorResponse assertions' => 'BulkWriteException cannot access server response',
'crud/insertOne-errorResponse: insert operations support errorResponse assertions' => 'BulkWriteException cannot access server response',
'crud/updateOne-errorResponse: update operations support errorResponse assertions' => 'BulkWriteException cannot access server response',
];

/** @var UnifiedTestRunner */
Expand Down