Skip to content

Commit 7604f4f

Browse files
author
levon80999
committed
Add check for replica set
1 parent 996522c commit 7604f4f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use MongoDB\Driver\BulkWrite;
66
use MongoDB\Driver\Exception\CommandException;
77
use MongoDB\Driver\ReadPreference;
8+
use MongoDB\Driver\Server;
89
use MongoDB\Driver\WriteConcern;
910
use MongoDB\Exception\UnsupportedException;
1011
use MongoDB\Model\BSONDocument;
@@ -95,19 +96,21 @@ public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSide
9596

9697
public function testFindAndModifyReportedWriteConcernError(): void
9798
{
98-
try {
99-
$operation = new FindAndModify(
100-
$this->getDatabaseName(),
101-
$this->getCollectionName(),
102-
['remove' => true, 'writeConcern' => new WriteConcern(50)]
103-
);
104-
105-
$operation->execute($this->getPrimaryServer());
106-
} catch (CommandException $e) {
107-
$this->assertInstanceOf(CommandException::class, $e);
108-
$this->assertStringContainsString('Write Concern error', $e->getMessage());
109-
$this->assertSame(100, $e->getCode());
99+
if (($this->isShardedCluster() && !$this->isShardedClusterUsingReplicasets()) || !$this->isReplicaSet()) {
100+
$this->markTestSkipped(sprintf('Cannot find topology for primary of type "%d".', $this->getPrimaryServer()->getType()));
110101
}
102+
103+
$this->expectException(CommandException::class);
104+
$this->expectExceptionCode(100);
105+
$this->expectExceptionMessageMatches('/Write Concern error:/');
106+
107+
$operation = new FindAndModify(
108+
$this->getDatabaseName(),
109+
$this->getCollectionName(),
110+
['remove' => true, 'writeConcern' => new WriteConcern(50)]
111+
);
112+
113+
$operation->execute($this->getPrimaryServer());
111114
}
112115

113116
public function testSessionOption(): void

0 commit comments

Comments
 (0)