Skip to content

Commit

Permalink
Merge pull request #733
Browse files Browse the repository at this point in the history
* phplib-540:
  PHPLIB-540: Ensure that the WriteConcernError "errInfo" object is propagated
  • Loading branch information
alcaeus committed Apr 3, 2020
2 parents 90ad22a + c457ece commit 71fcdb0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/SpecTests/CrudSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace MongoDB\Tests\SpecTests;

use MongoDB\Client;
use MongoDB\Driver\Exception\BulkWriteException;
use stdClass;
use function basename;
use function file_get_contents;
Expand Down Expand Up @@ -111,4 +113,44 @@ public function provideTests()

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());
}
}
}

0 comments on commit 71fcdb0

Please sign in to comment.