Skip to content

PHPLIB-638: Ensure writeConcernError is reported for findAndModify #983

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 1 commit into from
Sep 30, 2022
Merged
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
20 changes: 20 additions & 0 deletions tests/Operation/FindAndModifyFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MongoDB\Tests\Operation;

use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Exception\CommandException;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\UnsupportedException;
Expand Down Expand Up @@ -92,6 +93,25 @@ public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSide
$operation->execute($this->getPrimaryServer());
}

public function testFindAndModifyReportedWriteConcernError(): void
{
if (($this->isShardedCluster() && ! $this->isShardedClusterUsingReplicasets()) || ! $this->isReplicaSet()) {
$this->markTestSkipped('Test only applies to replica sets');
}

$this->expectException(CommandException::class);
$this->expectExceptionCode(100);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

$this->expectExceptionMessageMatches('/Write Concern error:/');

$operation = new FindAndModify(
$this->getDatabaseName(),
$this->getCollectionName(),
['remove' => true, 'writeConcern' => new WriteConcern(50)]
);

$operation->execute($this->getPrimaryServer());
}

public function testSessionOption(): void
{
(new CommandObserver())->observe(
Expand Down