Alcaeus\MongoDbAdapter\Tests\Mongo\MongoUpdateBatchTest::testUpdateManyException PHP Method

testUpdateManyException() public method

    public function testUpdateManyException()
    {
        $collection = $this->getCollection();
        $batch = new \MongoUpdateBatch($collection);
        $document = ['foo' => 'bar', 'bar' => 'bar'];
        $collection->insert($document);
        $document = ['foo' => 'foobar', 'bar' => 'bar'];
        $collection->insert($document);
        $collection->createIndex(['foo' => 1], ['unique' => true]);
        $batch->add(['q' => ['bar' => 'bar'], 'u' => ['$set' => ['foo' => 'foo']], 'multi' => true]);
        $expected = ['writeErrors' => [['index' => 0, 'code' => 11000]], 'nMatched' => 0, 'nModified' => 0, 'nUpserted' => 0, '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());
        }
    }