public function testIsolatedUpsertShouldThrowDocumentModifiedException() { $testData = ['test' => 'test']; $options = ['w' => 1]; //ensure document $this->mongoCollectionMock->expects($this->atLeastOnce())->method('insert')->with($this->equalTo($testData), $this->equalTo($options))->will($this->returnValue(['ok' => true, 'n' => 0])); // MongoDB returns 0 on insert operation $this->assertEquals(1, $this->documentStore->isolatedUpsert($this->mongoCollection, $testData, $options)); //Test update with document modified $this->mongoCollectionMock->expects($this->atLeastOnce())->method('update')->with($this->equalTo($this->documentStore->get($this->mongoCollection, $testData['_id'])), $this->equalTo($testData), $this->equalTo(array_merge($options, ['multi' => false, 'upsert' => false])))->will($this->returnValue(['ok' => true, 'n' => 0, 'updatedExisting' => false])); $this->setExpectedException('\\Matryoshka\\Model\\Wrapper\\Mongo\\Exception\\DocumentModifiedException'); $this->assertEquals(1, $this->documentStore->isolatedUpsert($this->mongoCollection, $testData, $options)); }