Unverified Commit 71fcdb0d authored by Andreas Braun's avatar Andreas Braun

Merge pull request #733

* phplib-540:
  PHPLIB-540: Ensure that the WriteConcernError "errInfo" object is propagated
parents 90ad22ab c457ecec
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace MongoDB\Tests\SpecTests; namespace MongoDB\Tests\SpecTests;
use MongoDB\Client;
use MongoDB\Driver\Exception\BulkWriteException;
use stdClass; use stdClass;
use function basename; use function basename;
use function file_get_contents; use function file_get_contents;
...@@ -111,4 +113,44 @@ class CrudSpecTest extends FunctionalTestCase ...@@ -111,4 +113,44 @@ class CrudSpecTest extends FunctionalTestCase
return $testArgs; return $testArgs;
} }
/**
* Prose test 1: "errInfo" is propagated
*/
public function testErrInfoIsPropagated()
{
$runOn = [(object) ['minServerVersion' => '4.0.0']];
$this->checkServerRequirements($runOn);
$errInfo = (object) [
'writeConcern' => (object) [
'w' => 2,
'wtimeout' => 0,
'provenance' => 'clientSupplied',
],
];
$this->configureFailPoint([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'failCommands' => ['insert'],
'writeConcernError' => [
'code' => 100,
'codeName' => 'UnsatisfiableWriteConcern',
'errmsg' => 'Not enough data-bearing nodes',
'errInfo' => $errInfo,
],
],
]);
$client = new Client(static::getUri());
try {
$client->selectCollection($this->getDatabaseName(), $this->getCollectionName())->insertOne(['fail' => 1]);
$this->fail('Expected insert command to fail');
} catch (BulkWriteException $e) {
self::assertEquals($errInfo, $e->getWriteResult()->getWriteConcernError()->getInfo());
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment