Skip to content

Commit 71fcdb0

Browse files
committed
Merge pull request #733
* phplib-540: PHPLIB-540: Ensure that the WriteConcernError "errInfo" object is propagated
2 parents 90ad22a + c457ece commit 71fcdb0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/SpecTests/CrudSpecTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace MongoDB\Tests\SpecTests;
44

5+
use MongoDB\Client;
6+
use MongoDB\Driver\Exception\BulkWriteException;
57
use stdClass;
68
use function basename;
79
use function file_get_contents;
@@ -111,4 +113,44 @@ public function provideTests()
111113

112114
return $testArgs;
113115
}
116+
117+
/**
118+
* Prose test 1: "errInfo" is propagated
119+
*/
120+
public function testErrInfoIsPropagated()
121+
{
122+
$runOn = [(object) ['minServerVersion' => '4.0.0']];
123+
$this->checkServerRequirements($runOn);
124+
125+
$errInfo = (object) [
126+
'writeConcern' => (object) [
127+
'w' => 2,
128+
'wtimeout' => 0,
129+
'provenance' => 'clientSupplied',
130+
],
131+
];
132+
133+
$this->configureFailPoint([
134+
'configureFailPoint' => 'failCommand',
135+
'mode' => ['times' => 1],
136+
'data' => [
137+
'failCommands' => ['insert'],
138+
'writeConcernError' => [
139+
'code' => 100,
140+
'codeName' => 'UnsatisfiableWriteConcern',
141+
'errmsg' => 'Not enough data-bearing nodes',
142+
'errInfo' => $errInfo,
143+
],
144+
],
145+
]);
146+
147+
$client = new Client(static::getUri());
148+
149+
try {
150+
$client->selectCollection($this->getDatabaseName(), $this->getCollectionName())->insertOne(['fail' => 1]);
151+
$this->fail('Expected insert command to fail');
152+
} catch (BulkWriteException $e) {
153+
self::assertEquals($errInfo, $e->getWriteResult()->getWriteConcernError()->getInfo());
154+
}
155+
}
114156
}

0 commit comments

Comments
 (0)