Skip to content

Commit b5365c8

Browse files
authored
PHPLIB-638: Ensure writeConcernError is reported for findAndModify (#983)
1 parent 3a9c15e commit b5365c8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MongoDB\Tests\Operation;
44

55
use MongoDB\Driver\BulkWrite;
6+
use MongoDB\Driver\Exception\CommandException;
67
use MongoDB\Driver\ReadPreference;
78
use MongoDB\Driver\WriteConcern;
89
use MongoDB\Exception\UnsupportedException;
@@ -92,6 +93,25 @@ public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSide
9293
$operation->execute($this->getPrimaryServer());
9394
}
9495

96+
public function testFindAndModifyReportedWriteConcernError(): void
97+
{
98+
if (($this->isShardedCluster() && ! $this->isShardedClusterUsingReplicasets()) || ! $this->isReplicaSet()) {
99+
$this->markTestSkipped('Test only applies to replica sets');
100+
}
101+
102+
$this->expectException(CommandException::class);
103+
$this->expectExceptionCode(100);
104+
$this->expectExceptionMessageMatches('/Write Concern error:/');
105+
106+
$operation = new FindAndModify(
107+
$this->getDatabaseName(),
108+
$this->getCollectionName(),
109+
['remove' => true, 'writeConcern' => new WriteConcern(50)]
110+
);
111+
112+
$operation->execute($this->getPrimaryServer());
113+
}
114+
95115
public function testSessionOption(): void
96116
{
97117
(new CommandObserver())->observe(

0 commit comments

Comments
 (0)