Skip to content

Commit fe1dcb4

Browse files
author
levon80999
committed
PHPLIB-638: Ensure writeConcernError is reported for findAndModify
1 parent 3a9c15e commit fe1dcb4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
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;
9+
use MongoDB\Exception\Exception;
810
use MongoDB\Exception\UnsupportedException;
911
use MongoDB\Model\BSONDocument;
1012
use MongoDB\Operation\FindAndModify;
@@ -92,6 +94,23 @@ public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSide
9294
$operation->execute($this->getPrimaryServer());
9395
}
9496

97+
public function testFindAndModifyReportedWriteConcernError(): void
98+
{
99+
try {
100+
$operation = new FindAndModify(
101+
$this->getDatabaseName(),
102+
$this->getCollectionName(),
103+
['remove' => true, 'writeConcern' => new WriteConcern(50) ]
104+
);
105+
106+
$operation->execute($this->getPrimaryServer());
107+
} catch (CommandException $e) {
108+
$this->assertInstanceOf(CommandException::class, $e);
109+
$this->assertStringContainsString('Write Concern error', $e->getMessage());
110+
$this->assertSame(100, $e->getCode());
111+
}
112+
}
113+
95114
public function testSessionOption(): void
96115
{
97116
(new CommandObserver())->observe(

0 commit comments

Comments
 (0)