Commit 391334a8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #320

parents fbbf5bad 5d785088
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Collection;
use MongoDB\Driver\ReadPreference;
use MongoDB\Operation\DropCollection;
/**
* CRUD spec functional tests for aggregate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class AggregateFunctionalTest extends FunctionalTestCase
{
private static $wireVersionForOutOperator = 2;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testAggregateWithMultipleStages()
{
$cursor = $this->collection->aggregate(
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
],
['batchSize' => 2]
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $cursor);
}
public function testAggregateWithOut()
{
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if ( ! \MongoDB\server_supports_feature($server, self::$wireVersionForOutOperator)) {
$this->markTestSkipped('$out aggregation pipeline operator is not supported');
}
$outputCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '_output');
$operation = new DropCollection($this->getDatabaseName(), $outputCollection->getCollectionName());
$operation->execute($this->getPrimaryServer());
$this->collection->aggregate(
[
['$sort' => ['x' => 1]],
['$match' => ['_id' => ['$gt' => 1]]],
['$out' => $outputCollection->getCollectionName()],
]
);
$expected = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $outputCollection->find());
// Manually clean up our output collection
$operation = new DropCollection($this->getDatabaseName(), $outputCollection->getCollectionName());
$operation->execute($this->getPrimaryServer());
}
public function testAggregateWithoutCursorDoesNotApplyTypemap()
{
$pipeline = [
['$group' => [
'_id' => null,
'count' => ['$sum' => 1]
]]
];
$options = ['useCursor' => false];
$result = $this->collection->aggregate($pipeline, $options);
$expected = [
[
'_id' => null,
'count' => 3,
],
];
$this->assertSameDocuments($expected, $result);
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for count().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class CountFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testCountWithoutFilter()
{
$this->assertSame(3, $this->collection->count());
}
public function testCountWithFilter()
{
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame(2, $this->collection->count($filter));
}
public function testCountWithSkipAndLimit()
{
$filter = [];
$options = ['skip' => 1, 'limit' => 3];
$this->assertSame(2, $this->collection->count($filter, $options));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for deleteMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DeleteManyFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDeleteManyWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteMany($filter);
$this->assertSame(2, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteManyWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$result = $this->collection->deleteMany($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for deleteOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DeleteOneFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDeleteOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenOneDocumentMatches()
{
$filter = ['_id' => 2];
$result = $this->collection->deleteOne($filter);
$this->assertSame(1, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testDeleteOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$result = $this->collection->deleteOne($filter);
$this->assertSame(0, $result->getDeletedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for distinct().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class DistinctFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testDistinctWithoutFilter()
{
$this->assertSame([11, 22, 33], $this->collection->distinct('x'));
}
public function testDistinctWithFilter()
{
$filter = ['_id' => ['$gt' => 1]];
$this->assertSame([22, 33], $this->collection->distinct('x', $filter));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for find().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(5);
}
public function testFindWithFilter()
{
$filter = ['_id' => 1];
$expected = [
['_id' => 1, 'x' => 11],
];
$this->assertSameDocuments($expected, $this->collection->find($filter));
}
public function testFindWithFilterSortSkipAndLimit()
{
$filter = ['_id' => ['$gt' => 2]];
$options = [
'sort' => ['_id' => 1],
'skip' => 2,
'limit' => 2,
];
$expected = [
['_id' => 5, 'x' => 55],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
public function testFindWithLimitSortAndBatchSize()
{
$filter = [];
$options = [
'sort' => ['_id' => 1],
'limit' => 4,
'batchSize' => 2,
];
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find($filter, $options));
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for findOneAndDelete().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndDeleteFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndDeleteWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenOneDocumentMatches()
{
$filter = ['_id' => 2];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndDeleteWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndDelete($filter, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Operation\FindOneAndReplace;
/**
* CRUD spec functional tests for findOneAndReplace().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndReplaceFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 32], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = ['_id' => 2];
$replacement = ['x' => 32];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 32], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 32],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$replacement = ['x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 44];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
'upsert' => true,
];
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
$this->assertSameDocument(['x' => 44], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 44],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Operation\FindOneAndUpdate;
/**
* CRUD spec functional tests for findOneAndUpdate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class FindOneAndUpdateFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
}
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 23], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBeforeModification()
{
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 22], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfterModification()
{
$filter = ['_id' => 2];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 23], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentBeforeModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'upsert' => true,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertNull($document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocumentAfterModification()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = [
'projection' => ['x' => 1, '_id' => 0],
'sort' => ['x' => 1],
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
'upsert' => true,
];
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
$this->assertSameDocument(['x' => 1], $document);
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
use MongoDB\Driver\BulkWrite;
use MongoDB\Tests\Collection\FunctionalTestCase as BaseFunctionalTestCase;
/**
* Base class for Collection CRUD spec functional tests.
*/
abstract class FunctionalTestCase extends BaseFunctionalTestCase
{
/**
* Create data fixtures.
*
* @param integer $n
*/
protected function createFixtures($n)
{
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals($n, $result->getInsertedCount());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for insertMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class InsertManyFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(1);
}
public function testInsertManyWithNonexistentDocuments()
{
$documents = [
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$result = $this->collection->insertMany($documents);
$this->assertSame(2, $result->getInsertedCount());
$this->assertSame([2, 3], $result->getInsertedIds());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for insertOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class InsertOneFunctionalTest extends FunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->createFixtures(1);
}
public function testInsertOneWithANonexistentDocument()
{
$document = ['_id' => 2, 'x' => 22];
$result = $this->collection->insertOne($document);
$this->assertSame(1, $result->getInsertedCount());
$this->assertSame(2, $result->getInsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for replaceOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class ReplaceOneFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testReplaceOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 111],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 111],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$replacement = ['x' => 111];
$result = $this->collection->replaceOne($filter, $replacement);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified()
{
$filter = ['_id' => 4];
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified()
{
$filter = ['_id' => 4];
// Server 2.4 and earlier requires any custom ID to also be in the replacement document
$replacement = ['_id' => 4, 'x' => 1];
$options = ['upsert' => true];
$result = $this->collection->replaceOne($filter, $replacement, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for updateMany().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class UpdateManyFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testUpdateManyWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(2, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(2, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 34],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateMany($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateManyWithUpsertWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateMany($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection\CrudSpec;
/**
* CRUD spec functional tests for updateOne().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class UpdateOneFunctionalTest extends FunctionalTestCase
{
private $omitModifiedCount;
public function setUp()
{
parent::setUp();
$this->createFixtures(3);
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
}
public function testUpdateOneWhenManyDocumentsMatch()
{
$filter = ['_id' => ['$gt' => 1]];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 23],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenOneDocumentMatches()
{
$filter = ['_id' => 1];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(1, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 12],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$result = $this->collection->updateOne($filter, $update);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
public function testUpdateOneWithUpsertWhenNoDocumentsMatch()
{
$filter = ['_id' => 4];
$update = ['$inc' => ['x' => 1]];
$options = ['upsert' => true];
$result = $this->collection->updateOne($filter, $update, $options);
$this->assertSame(0, $result->getMatchedCount());
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
$this->assertSame(4, $result->getUpsertedId());
$expected = [
['_id' => 1, 'x' => 11],
['_id' => 2, 'x' => 22],
['_id' => 3, 'x' => 33],
['_id' => 4, 'x' => 1],
];
$this->assertSameDocuments($expected, $this->collection->find());
}
}
<?php
namespace MongoDB\Tests\Collection;
use MongoDB\Collection;
use MongoDB\Operation\FindOneAndReplace;
use IteratorIterator;
use LogicException;
use MultipleIterator;
/**
* CRUD spec functional tests.
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class CrudSpecFunctionalTest extends FunctionalTestCase
{
private $expectedCollection;
public function setUp()
{
parent::setUp();
$this->expectedCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.expected');
$this->expectedCollection->drop();
}
/**
* @dataProvider provideSpecificationTests
*/
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion)
{
$this->setName(str_replace(' ', '_', $test['description']));
if (isset($minServerVersion) || isset($maxServerVersion)) {
$this->checkServerVersion($minServerVersion, $maxServerVersion);
}
$expectedData = isset($test['outcome']['collection']['data']) ? $test['outcome']['collection']['data'] : null;
$this->initializeData($initialData, $expectedData);
$result = $this->executeOperation($test['operation']);
$this->executeOutcome($test['operation'], $test['outcome'], $result);
}
public function provideSpecificationTests()
{
$testArgs = [];
foreach (glob(__DIR__ . '/spec-tests/*/*.json') as $filename) {
$json = json_decode(file_get_contents($filename), true);
$minServerVersion = isset($json['minServerVersion']) ? $json['minServerVersion'] : null;
$maxServerVersion = isset($json['maxServerVersion']) ? $json['maxServerVersion'] : null;
foreach ($json['tests'] as $test) {
$testArgs[] = [$json['data'], $test, $minServerVersion, $maxServerVersion];
}
}
return $testArgs;
}
/**
* Assert that the collections contain equivalent documents.
*
* @param Collection $expectedCollection
* @param Collection $actualCollection
*/
private function assertEquivalentCollections($expectedCollection, $actualCollection)
{
$mi = new MultipleIterator;
$mi->attachIterator(new IteratorIterator($expectedCollection->find()));
$mi->attachIterator(new IteratorIterator($actualCollection->find()));
foreach ($mi as $documents) {
list($expectedDocument, $actualDocument) = $documents;
$this->assertSameDocument($expectedDocument, $actualDocument);
}
}
/**
* Checks that the server version is within the allowed bounds (if any).
*
* @param string|null $minServerVersion
* @param string|null $maxServerVersion
* @throws \PHPUnit_Framework_SkippedTestError
*/
private function checkServerVersion($minServerVersion, $maxServerVersion)
{
$serverVersion = $this->getServerVersion();
if (isset($minServerVersion) && version_compare($serverVersion, $minServerVersion, '<')) {
$this->markTestSkipped(sprintf('Server version "%s" < minServerVersion "%s"', $serverVersion, $minServerVersion));
}
if (isset($maxServerVersion) && version_compare($serverVersion, $maxServerVersion, '>=')) {
$this->markTestSkipped(sprintf('Server version "%s" >= maxServerVersion "%s"', $serverVersion, $maxServerVersion));
}
}
/**
* Executes an "operation" block.
*
* @param array $operation
* @return mixed
* @throws LogicException if the operation is unsupported
*/
private function executeOperation(array $operation)
{
switch ($operation['name']) {
case 'aggregate':
return $this->collection->aggregate(
$operation['arguments']['pipeline'],
array_diff_key($operation['arguments'], ['pipeline' => 1])
);
case 'count':
case 'find':
return $this->collection->{$operation['name']}(
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
array_diff_key($operation['arguments'], ['filter' => 1])
);
case 'deleteMany':
case 'deleteOne':
case 'findOneAndDelete':
return $this->collection->{$operation['name']}(
$operation['arguments']['filter'],
array_diff_key($operation['arguments'], ['filter' => 1])
);
case 'distinct':
return $this->collection->distinct(
$operation['arguments']['fieldName'],
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
array_diff_key($operation['arguments'], ['fieldName' => 1, 'filter' => 1])
);
case 'findOneAndReplace':
$operation['arguments'] = $this->prepareFindAndModifyArguments($operation['arguments']);
// Fall through
case 'replaceOne':
return $this->collection->{$operation['name']}(
$operation['arguments']['filter'],
$operation['arguments']['replacement'],
array_diff_key($operation['arguments'], ['filter' => 1, 'replacement' => 1])
);
case 'findOneAndUpdate':
$operation['arguments'] = $this->prepareFindAndModifyArguments($operation['arguments']);
// Fall through
case 'updateMany':
case 'updateOne':
return $this->collection->{$operation['name']}(
$operation['arguments']['filter'],
$operation['arguments']['update'],
array_diff_key($operation['arguments'], ['filter' => 1, 'update' => 1])
);
case 'insertMany':
return $this->collection->insertMany(
$operation['arguments']['documents'],
array_diff_key($operation['arguments'], ['documents' => 1])
);
case 'insertOne':
return $this->collection->insertOne(
$operation['arguments']['document'],
array_diff_key($operation['arguments'], ['document' => 1])
);
default:
throw new LogicException('Unsupported operation: ' . $operation['name']);
}
}
/**
* Executes an "outcome" block.
*
* @param array $operation
* @param array $outcome
* @param mixed $actualResult
* @return mixed
* @throws LogicException if the operation is unsupported
*/
private function executeOutcome(array $operation, array $outcome, $actualResult)
{
if (array_key_exists('result', $outcome)) {
$this->executeAssertResult($operation, $outcome['result'], $actualResult);
}
if (isset($outcome['collection'])) {
$actualCollection = isset($outcome['collection']['name'])
? new Collection($this->manager, $this->getDatabaseName(), $outcome['collection']['name'])
: $this->collection;
$this->assertEquivalentCollections($this->expectedCollection, $actualCollection);
}
}
/**
* Executes the "result" section of an "outcome" block.
*
* @param array $operation
* @param mixed $expectedResult
* @param mixed $actualResult
* @throws LogicException if the operation is unsupported
*/
private function executeAssertResult(array $operation, $expectedResult, $actualResult)
{
switch ($operation['name']) {
case 'aggregate':
/* Returning a cursor for the $out collection is optional per
* the CRUD specification and is not implemented in the library
* since we have no concept of lazy cursors. We will not assert
* the result here; however, assertEquivalentCollections() will
* assert the output collection's contents later.
*/
if ( ! \MongoDB\is_last_pipeline_operator_out($operation['arguments']['pipeline'])) {
$this->assertSameDocuments($expectedResult, $actualResult);
}
break;
case 'count':
$this->assertSame($expectedResult, $actualResult);
break;
case 'distinct':
$this->assertSameDocument(
['values' => $expectedResult],
['values' => $actualResult]
);
break;
case 'find':
$this->assertSameDocuments($expectedResult, $actualResult);
break;
case 'deleteMany':
case 'deleteOne':
$this->assertInstanceOf('MongoDB\DeleteResult', $actualResult);
if (isset($expectedResult['deletedCount'])) {
$this->assertSame($expectedResult['deletedCount'], $actualResult->getDeletedCount());
}
break;
case 'findOneAndDelete':
case 'findOneAndReplace':
case 'findOneAndUpdate':
$this->assertSameDocument(
['result' => $expectedResult],
['result' => $actualResult]
);
break;
case 'insertMany':
$this->assertInstanceOf('MongoDB\InsertManyResult', $actualResult);
if (isset($expectedResult['insertedCount'])) {
$this->assertSame($expectedResult['insertedCount'], $actualResult->getInsertedCount());
}
if (isset($expectedResult['insertedIds'])) {
$this->assertSameDocument(
['insertedIds' => $expectedResult['insertedIds']],
['insertedIds' => $actualResult->getInsertedIds()]
);
}
break;
case 'insertOne':
$this->assertInstanceOf('MongoDB\InsertOneResult', $actualResult);
if (isset($expectedResult['insertedCount'])) {
$this->assertSame($expectedResult['insertedCount'], $actualResult->getInsertedCount());
}
if (isset($expectedResult['insertedId'])) {
$this->assertSameDocument(
['insertedId' => $expectedResult['insertedId']],
['insertedId' => $actualResult->getInsertedId()]
);
}
break;
case 'replaceOne':
case 'updateMany':
case 'updateOne':
$this->assertInstanceOf('MongoDB\UpdateResult', $actualResult);
if (isset($expectedResult['matchedCount'])) {
$this->assertSame($expectedResult['matchedCount'], $actualResult->getMatchedCount());
}
if (isset($expectedResult['modifiedCount'])) {
$this->assertSame($expectedResult['modifiedCount'], $actualResult->getModifiedCount());
}
if (isset($expectedResult['upsertedCount'])) {
$this->assertSame($expectedResult['upsertedCount'], $actualResult->getUpsertedCount());
}
if (array_key_exists('upsertedId', $expectedResult)) {
$this->assertSameDocument(
['upsertedId' => $expectedResult['upsertedId']],
['upsertedId' => $actualResult->getUpsertedId()]
);
}
break;
default:
throw new LogicException('Unsupported operation: ' . $operationName);
}
}
/**
* Initializes data in the test collections.
*
* @param array $initialData
* @param array $expectedData
*/
private function initializeData(array $initialData, array $expectedData = null)
{
if ( ! empty($initialData)) {
$this->collection->insertMany($initialData);
}
if ( ! empty($expectedData)) {
$this->expectedCollection->insertMany($expectedData);
}
}
/**
* Prepares arguments for findOneAndReplace and findOneAndUpdate operations.
*
* @param array $arguments
* @return array
*/
private function prepareFindAndModifyArguments($arguments)
{
if (isset($arguments['returnDocument'])) {
$arguments['returnDocument'] = ('after' === strtolower($arguments['returnDocument']))
? FindOneAndReplace::RETURN_DOCUMENT_AFTER
: FindOneAndReplace::RETURN_DOCUMENT_BEFORE;
}
return $arguments;
}
}
{
"data": [
{
"_id": 1,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Aggregate with collation",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$match": {
"x": "PING"
}
}
],
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": "ping"
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "Aggregate with $out",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$out": "other_test_collection"
}
],
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"collection": {
"name": "other_test_collection",
"data": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Aggregate with multiple stages",
"operation": {
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$sort": {
"x": 1
}
},
{
"$match": {
"_id": {
"$gt": 1
}
}
}
],
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": "PING"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Count with collation",
"operation": {
"name": "count",
"arguments": {
"filter": {
"x": "ping"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": 1
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Count without a filter",
"operation": {
"name": "count",
"arguments": {
"filter": {}
}
},
"outcome": {
"result": 3
}
},
{
"description": "Count with a filter",
"operation": {
"name": "count",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": 2
}
},
{
"description": "Count with skip and limit",
"operation": {
"name": "count",
"arguments": {
"filter": {},
"skip": 1,
"limit": 3
}
},
"outcome": {
"result": 2
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"string": "PING"
},
{
"_id": 2,
"string": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Distinct with a collation",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "string",
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
"PING"
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Distinct without a filter",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "x",
"filter": {}
}
},
"outcome": {
"result": [
11,
22,
33
]
}
},
{
"description": "Distinct with a filter",
"operation": {
"name": "distinct",
"arguments": {
"fieldName": "x",
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": [
22,
33
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "Find with a collation",
"operation": {
"name": "find",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": "ping"
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
},
{
"_id": 5,
"x": 55
}
],
"tests": [
{
"description": "Find with filter",
"operation": {
"name": "find",
"arguments": {
"filter": {
"_id": 1
}
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": 11
}
]
}
},
{
"description": "Find with filter, sort, skip, and limit",
"operation": {
"name": "find",
"arguments": {
"filter": {
"_id": {
"$gt": 2
}
},
"sort": {
"_id": 1
},
"skip": 2,
"limit": 2
}
},
"outcome": {
"result": [
{
"_id": 5,
"x": 55
}
]
}
},
{
"description": "Find with limit, sort, and batchsize",
"operation": {
"name": "find",
"arguments": {
"filter": {},
"sort": {
"_id": 1
},
"limit": 4,
"batchSize": 2
}
},
"outcome": {
"result": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "DeleteMany when many documents match with collation",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "DeleteMany when many documents match",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": {
"deletedCount": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
}
]
}
}
},
{
"description": "DeleteMany when no document matches",
"operation": {
"name": "deleteMany",
"arguments": {
"filter": {
"_id": 4
}
}
},
"outcome": {
"result": {
"deletedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "DeleteOne when many documents matches with collation",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"x": "PING"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "DeleteOne when many documents match",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
}
}
},
"outcome": {
"result": {
"deletedCount": 1
}
}
},
{
"description": "DeleteOne when one document matches",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": 2
}
}
},
"outcome": {
"result": {
"deletedCount": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "DeleteOne when no documents match",
"operation": {
"name": "deleteOne",
"arguments": {
"filter": {
"_id": 4
}
}
},
"outcome": {
"result": {
"deletedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndDelete when one document matches with collation",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 2,
"x": "PING"
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "ping"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndDelete when many documents match",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndDelete when one document matches",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 2
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndDelete when no documents match",
"operation": {
"name": "findOneAndDelete",
"arguments": {
"filter": {
"_id": 4
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndReplace when one document matches with collation returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"x": "PING"
},
"replacement": {
"x": "pong"
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "pong"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null
}
},
{
"description": "FindOneAndReplace when no documents match without id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match with id specified with upsert returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 44
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 44
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndReplace when many documents match returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when many documents match returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 32
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when one document matches returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 2
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when one document matches returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 2
},
"replacement": {
"x": 32
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 32
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 32
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match returning the document before modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndReplace when no documents match returning the document after modification",
"operation": {
"name": "findOneAndReplace",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 44
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "FindOneAndUpdate when many documents match with collation returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"x": "PING"
},
"update": {
"$set": {
"x": "pong"
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"_id": 1
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"x": "ping"
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
},
{
"_id": 3,
"x": "pINg"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "FindOneAndUpdate when many documents match returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when many documents match returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 23
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when one document matches returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 2
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 22
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when one document matches returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 2
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": {
"x": 23
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match with upsert returning the document before modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"upsert": true
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
}
}
},
"outcome": {
"result": null,
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "FindOneAndUpdate when no documents match with upsert returning the document after modification",
"operation": {
"name": "findOneAndUpdate",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"projection": {
"x": 1,
"_id": 0
},
"returnDocument": "After",
"sort": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"x": 1
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
}
],
"tests": [
{
"description": "InsertMany with non-existing documents",
"operation": {
"name": "insertMany",
"arguments": {
"documents": [
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
},
"outcome": {
"result": {
"insertedIds": [
2,
3
]
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
}
],
"tests": [
{
"description": "InsertOne with a non-existing document",
"operation": {
"name": "insertOne",
"arguments": {
"document": {
"_id": 2,
"x": 22
}
}
},
"outcome": {
"result": {
"insertedId": 2
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "ReplaceOne when one document matches with collation",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"x": "PING"
},
"replacement": {
"_id": 2,
"x": "pong"
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "ReplaceOne when many documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "ReplaceOne when one document matches",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 1
},
"replacement": {
"_id": 1,
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 111
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne when no documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
},
"name": "replaceOne"
},
"outcome": {
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
},
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedId": 4
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
},
"name": "replaceOne"
},
"outcome": {
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
},
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedId": 4
}
}
}
]
}
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "ReplaceOne when many documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"replacement": {
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "ReplaceOne when one document matches",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 1
},
"replacement": {
"_id": 1,
"x": 111
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 111
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne when no documents match",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match without an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
},
{
"description": "ReplaceOne with upsert when no documents match with an id specified",
"operation": {
"name": "replaceOne",
"arguments": {
"filter": {
"_id": 4
},
"replacement": {
"_id": 4,
"x": 1
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
},
{
"_id": 3,
"x": "pINg"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "UpdateMany when many documents match with collation",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"x": "ping"
},
"update": {
"$set": {
"x": "pong"
}
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"modifiedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
},
{
"_id": 3,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "UpdateMany when many documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 34
}
]
}
}
},
{
"description": "UpdateMany when one document matches",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany with upsert when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "UpdateMany when many documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 2,
"modifiedCount": 2,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 23
},
{
"_id": 3,
"x": 34
}
]
}
}
},
{
"description": "UpdateMany when one document matches",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateMany with upsert when no documents match",
"operation": {
"name": "updateMany",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "ping"
}
],
"minServerVersion": "3.4",
"tests": [
{
"description": "UpdateOne when one document matches with collation",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"x": "PING"
},
"update": {
"$set": {
"x": "pong"
}
},
"collation": {
"locale": "en_US",
"strength": 2
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": "pong"
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"maxServerVersion": "2.4.99",
"tests": [
{
"description": "UpdateOne when many documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "UpdateOne when one document matches",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne with upsert when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
{
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"minServerVersion": "2.6",
"tests": [
{
"description": "UpdateOne when many documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": {
"$gt": 1
}
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
}
}
},
{
"description": "UpdateOne when one document matches",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 1,
"modifiedCount": 1,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 12
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
}
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 0
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
}
},
{
"description": "UpdateOne with upsert when no documents match",
"operation": {
"name": "updateOne",
"arguments": {
"filter": {
"_id": 4
},
"update": {
"$inc": {
"x": 1
}
},
"upsert": true
}
},
"outcome": {
"result": {
"matchedCount": 0,
"modifiedCount": 0,
"upsertedCount": 1,
"upsertedId": 4
},
"collection": {
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
},
{
"_id": 4,
"x": 1
}
]
}
}
}
]
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ use MongoDB\Driver\Command; ...@@ -6,6 +6,7 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use InvalidArgumentException; use InvalidArgumentException;
use stdClass; use stdClass;
......
...@@ -202,7 +202,6 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -202,7 +202,6 @@ class SpecFunctionalTest extends FunctionalTestCase
* @param array $assert * @param array $assert
* @param mixed $actualResult * @param mixed $actualResult
* @return mixed * @return mixed
* @throws FileNotFoundException
* @throws LogicException if the operation is unsupported * @throws LogicException if the operation is unsupported
*/ */
private function executeAssert(array $assert, $actualResult) private function executeAssert(array $assert, $actualResult)
...@@ -241,7 +240,6 @@ class SpecFunctionalTest extends FunctionalTestCase ...@@ -241,7 +240,6 @@ class SpecFunctionalTest extends FunctionalTestCase
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $actualResult * @param mixed $actualResult
* @param array $data
* @throws LogicException if the result assertion is unsupported * @throws LogicException if the result assertion is unsupported
*/ */
private function executeAssertResult($expectedResult, $actualResult) private function executeAssertResult($expectedResult, $actualResult)
......
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