public function testInsertBatchError()
{
$collection = $this->getCollection();
$batch = new \MongoInsertBatch($collection);
$collection->createIndex(['foo' => 1], ['unique' => true]);
$this->assertTrue($batch->add(['foo' => 'bar']));
$this->assertTrue($batch->add(['foo' => 'bar']));
$expected = ['writeErrors' => [['index' => 1, 'code' => 11000]], 'nInserted' => 1, 'ok' => true];
try {
$batch->execute();
$this->fail('Expected MongoWriteConcernException');
} catch (\MongoWriteConcernException $e) {
$this->assertSame('Failed write', $e->getMessage());
$this->assertSame(911, $e->getCode());
$this->assertArraySubset($expected, $e->getDocument());
}
}