From bad31a20020ddd4d0dde968a0f8055a731512f31 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 5 Jan 2017 12:18:11 -0500 Subject: [PATCH 1/3] PHPLIB-231: Implement test harness for CRUD spec tests Generated from mongodb/specifications#126 --- .../CrudSpec/AggregateFunctionalTest.php | 95 ----- .../CrudSpec/CountFunctionalTest.php | 38 -- .../CrudSpec/DeleteManyFunctionalTest.php | 48 --- .../CrudSpec/DeleteOneFunctionalTest.php | 64 --- .../CrudSpec/DistinctFunctionalTest.php | 30 -- .../CrudSpec/FindFunctionalTest.php | 64 --- .../FindOneAndDeleteFunctionalTest.php | 76 ---- .../FindOneAndReplaceFunctionalTest.php | 198 --------- .../FindOneAndUpdateFunctionalTest.php | 196 --------- .../CrudSpec/FunctionalTestCase.php | 33 -- .../CrudSpec/InsertManyFunctionalTest.php | 38 -- .../CrudSpec/InsertOneFunctionalTest.php | 34 -- .../CrudSpec/ReplaceOneFunctionalTest.php | 119 ------ .../CrudSpec/UpdateManyFunctionalTest.php | 97 ----- .../CrudSpec/UpdateOneFunctionalTest.php | 97 ----- tests/Collection/CrudSpecFunctionalTest.php | 353 ++++++++++++++++ .../spec-tests/read/aggregate-collation.json | 38 ++ .../spec-tests/read/aggregate-out.json | 70 ++++ .../Collection/spec-tests/read/aggregate.json | 53 +++ .../spec-tests/read/count-collation.json | 29 ++ tests/Collection/spec-tests/read/count.json | 60 +++ .../spec-tests/read/distinct-collation.json | 33 ++ .../Collection/spec-tests/read/distinct.json | 55 +++ .../spec-tests/read/find-collation.json | 34 ++ tests/Collection/spec-tests/read/find.json | 105 +++++ .../write/deleteMany-collation.json | 47 +++ .../spec-tests/write/deleteMany.json | 76 ++++ .../spec-tests/write/deleteOne-collation.json | 51 +++ .../spec-tests/write/deleteOne.json | 96 +++++ .../write/findOneAndDelete-collation.json | 59 +++ .../spec-tests/write/findOneAndDelete.json | 127 ++++++ .../write/findOneAndReplace-collation.json | 58 +++ .../write/findOneAndReplace-upsert.json | 201 ++++++++++ .../findOneAndReplace-upsert_pre_2.6.json | 161 ++++++++ .../spec-tests/write/findOneAndReplace.json | 273 +++++++++++++ .../write/findOneAndUpdate-collation.json | 67 ++++ .../spec-tests/write/findOneAndUpdate.json | 379 ++++++++++++++++++ .../spec-tests/write/insertMany.json | 52 +++ .../spec-tests/write/insertOne.json | 39 ++ .../write/replaceOne-collation.json | 53 +++ .../spec-tests/write/replaceOne-pre_2.6.json | 179 +++++++++ .../spec-tests/write/replaceOne-upsert.json | 104 +++++ .../spec-tests/write/replaceOne.json | 205 ++++++++++ .../write/updateMany-collation.json | 62 +++ .../spec-tests/write/updateMany-pre_2.6.json | 179 +++++++++ .../spec-tests/write/updateMany.json | 183 +++++++++ .../spec-tests/write/updateOne-collation.json | 54 +++ .../spec-tests/write/updateOne-pre_2.6.json | 163 ++++++++ .../spec-tests/write/updateOne.json | 167 ++++++++ 49 files changed, 3865 insertions(+), 1227 deletions(-) delete mode 100644 tests/Collection/CrudSpec/AggregateFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/CountFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/DeleteManyFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/DeleteOneFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/DistinctFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/FindFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/FunctionalTestCase.php delete mode 100644 tests/Collection/CrudSpec/InsertManyFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/InsertOneFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/UpdateManyFunctionalTest.php delete mode 100644 tests/Collection/CrudSpec/UpdateOneFunctionalTest.php create mode 100644 tests/Collection/CrudSpecFunctionalTest.php create mode 100644 tests/Collection/spec-tests/read/aggregate-collation.json create mode 100644 tests/Collection/spec-tests/read/aggregate-out.json create mode 100644 tests/Collection/spec-tests/read/aggregate.json create mode 100644 tests/Collection/spec-tests/read/count-collation.json create mode 100644 tests/Collection/spec-tests/read/count.json create mode 100644 tests/Collection/spec-tests/read/distinct-collation.json create mode 100644 tests/Collection/spec-tests/read/distinct.json create mode 100644 tests/Collection/spec-tests/read/find-collation.json create mode 100644 tests/Collection/spec-tests/read/find.json create mode 100644 tests/Collection/spec-tests/write/deleteMany-collation.json create mode 100644 tests/Collection/spec-tests/write/deleteMany.json create mode 100644 tests/Collection/spec-tests/write/deleteOne-collation.json create mode 100644 tests/Collection/spec-tests/write/deleteOne.json create mode 100644 tests/Collection/spec-tests/write/findOneAndDelete-collation.json create mode 100644 tests/Collection/spec-tests/write/findOneAndDelete.json create mode 100644 tests/Collection/spec-tests/write/findOneAndReplace-collation.json create mode 100644 tests/Collection/spec-tests/write/findOneAndReplace-upsert.json create mode 100644 tests/Collection/spec-tests/write/findOneAndReplace-upsert_pre_2.6.json create mode 100644 tests/Collection/spec-tests/write/findOneAndReplace.json create mode 100644 tests/Collection/spec-tests/write/findOneAndUpdate-collation.json create mode 100644 tests/Collection/spec-tests/write/findOneAndUpdate.json create mode 100644 tests/Collection/spec-tests/write/insertMany.json create mode 100644 tests/Collection/spec-tests/write/insertOne.json create mode 100644 tests/Collection/spec-tests/write/replaceOne-collation.json create mode 100644 tests/Collection/spec-tests/write/replaceOne-pre_2.6.json create mode 100644 tests/Collection/spec-tests/write/replaceOne-upsert.json create mode 100644 tests/Collection/spec-tests/write/replaceOne.json create mode 100644 tests/Collection/spec-tests/write/updateMany-collation.json create mode 100644 tests/Collection/spec-tests/write/updateMany-pre_2.6.json create mode 100644 tests/Collection/spec-tests/write/updateMany.json create mode 100644 tests/Collection/spec-tests/write/updateOne-collation.json create mode 100644 tests/Collection/spec-tests/write/updateOne-pre_2.6.json create mode 100644 tests/Collection/spec-tests/write/updateOne.json diff --git a/tests/Collection/CrudSpec/AggregateFunctionalTest.php b/tests/Collection/CrudSpec/AggregateFunctionalTest.php deleted file mode 100644 index 46ec7ba5d..000000000 --- a/tests/Collection/CrudSpec/AggregateFunctionalTest.php +++ /dev/null @@ -1,95 +0,0 @@ -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); - } -} diff --git a/tests/Collection/CrudSpec/CountFunctionalTest.php b/tests/Collection/CrudSpec/CountFunctionalTest.php deleted file mode 100644 index 0885657cd..000000000 --- a/tests/Collection/CrudSpec/CountFunctionalTest.php +++ /dev/null @@ -1,38 +0,0 @@ -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)); - } -} diff --git a/tests/Collection/CrudSpec/DeleteManyFunctionalTest.php b/tests/Collection/CrudSpec/DeleteManyFunctionalTest.php deleted file mode 100644 index 38570f8c0..000000000 --- a/tests/Collection/CrudSpec/DeleteManyFunctionalTest.php +++ /dev/null @@ -1,48 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/DeleteOneFunctionalTest.php b/tests/Collection/CrudSpec/DeleteOneFunctionalTest.php deleted file mode 100644 index 1e63c06fd..000000000 --- a/tests/Collection/CrudSpec/DeleteOneFunctionalTest.php +++ /dev/null @@ -1,64 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/DistinctFunctionalTest.php b/tests/Collection/CrudSpec/DistinctFunctionalTest.php deleted file mode 100644 index 0b92d83b4..000000000 --- a/tests/Collection/CrudSpec/DistinctFunctionalTest.php +++ /dev/null @@ -1,30 +0,0 @@ -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)); - } -} diff --git a/tests/Collection/CrudSpec/FindFunctionalTest.php b/tests/Collection/CrudSpec/FindFunctionalTest.php deleted file mode 100644 index 342c67085..000000000 --- a/tests/Collection/CrudSpec/FindFunctionalTest.php +++ /dev/null @@ -1,64 +0,0 @@ -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)); - } -} diff --git a/tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php b/tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php deleted file mode 100644 index 5e222cc11..000000000 --- a/tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php +++ /dev/null @@ -1,76 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php b/tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php deleted file mode 100644 index 5ec0ef97a..000000000 --- a/tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php +++ /dev/null @@ -1,198 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php b/tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php deleted file mode 100644 index cd531a841..000000000 --- a/tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php +++ /dev/null @@ -1,196 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/FunctionalTestCase.php b/tests/Collection/CrudSpec/FunctionalTestCase.php deleted file mode 100644 index 24e4f2fa1..000000000 --- a/tests/Collection/CrudSpec/FunctionalTestCase.php +++ /dev/null @@ -1,33 +0,0 @@ - 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()); - } -} diff --git a/tests/Collection/CrudSpec/InsertManyFunctionalTest.php b/tests/Collection/CrudSpec/InsertManyFunctionalTest.php deleted file mode 100644 index 6ca7390ef..000000000 --- a/tests/Collection/CrudSpec/InsertManyFunctionalTest.php +++ /dev/null @@ -1,38 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/InsertOneFunctionalTest.php b/tests/Collection/CrudSpec/InsertOneFunctionalTest.php deleted file mode 100644 index c697783de..000000000 --- a/tests/Collection/CrudSpec/InsertOneFunctionalTest.php +++ /dev/null @@ -1,34 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php b/tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php deleted file mode 100644 index 04978306f..000000000 --- a/tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php +++ /dev/null @@ -1,119 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/UpdateManyFunctionalTest.php b/tests/Collection/CrudSpec/UpdateManyFunctionalTest.php deleted file mode 100644 index 997f7be1d..000000000 --- a/tests/Collection/CrudSpec/UpdateManyFunctionalTest.php +++ /dev/null @@ -1,97 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpec/UpdateOneFunctionalTest.php b/tests/Collection/CrudSpec/UpdateOneFunctionalTest.php deleted file mode 100644 index 5b7c8b22d..000000000 --- a/tests/Collection/CrudSpec/UpdateOneFunctionalTest.php +++ /dev/null @@ -1,97 +0,0 @@ -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()); - } -} diff --git a/tests/Collection/CrudSpecFunctionalTest.php b/tests/Collection/CrudSpecFunctionalTest.php new file mode 100644 index 000000000..0461851d8 --- /dev/null +++ b/tests/Collection/CrudSpecFunctionalTest.php @@ -0,0 +1,353 @@ +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; + } +} diff --git a/tests/Collection/spec-tests/read/aggregate-collation.json b/tests/Collection/spec-tests/read/aggregate-collation.json new file mode 100644 index 000000000..903a5834e --- /dev/null +++ b/tests/Collection/spec-tests/read/aggregate-collation.json @@ -0,0 +1,38 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/aggregate-out.json b/tests/Collection/spec-tests/read/aggregate-out.json new file mode 100644 index 000000000..cbc8ca47b --- /dev/null +++ b/tests/Collection/spec-tests/read/aggregate-out.json @@ -0,0 +1,70 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/aggregate.json b/tests/Collection/spec-tests/read/aggregate.json new file mode 100644 index 000000000..479fcb9b7 --- /dev/null +++ b/tests/Collection/spec-tests/read/aggregate.json @@ -0,0 +1,53 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/count-collation.json b/tests/Collection/spec-tests/read/count-collation.json new file mode 100644 index 000000000..462120942 --- /dev/null +++ b/tests/Collection/spec-tests/read/count-collation.json @@ -0,0 +1,29 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/count.json b/tests/Collection/spec-tests/read/count.json new file mode 100644 index 000000000..85c17e11a --- /dev/null +++ b/tests/Collection/spec-tests/read/count.json @@ -0,0 +1,60 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/distinct-collation.json b/tests/Collection/spec-tests/read/distinct-collation.json new file mode 100644 index 000000000..4d688cc3d --- /dev/null +++ b/tests/Collection/spec-tests/read/distinct-collation.json @@ -0,0 +1,33 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/distinct.json b/tests/Collection/spec-tests/read/distinct.json new file mode 100644 index 000000000..408d8a480 --- /dev/null +++ b/tests/Collection/spec-tests/read/distinct.json @@ -0,0 +1,55 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/find-collation.json b/tests/Collection/spec-tests/read/find-collation.json new file mode 100644 index 000000000..b2d268ae3 --- /dev/null +++ b/tests/Collection/spec-tests/read/find-collation.json @@ -0,0 +1,34 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/read/find.json b/tests/Collection/spec-tests/read/find.json new file mode 100644 index 000000000..d92081d55 --- /dev/null +++ b/tests/Collection/spec-tests/read/find.json @@ -0,0 +1,105 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/deleteMany-collation.json b/tests/Collection/spec-tests/write/deleteMany-collation.json new file mode 100644 index 000000000..593ad6856 --- /dev/null +++ b/tests/Collection/spec-tests/write/deleteMany-collation.json @@ -0,0 +1,47 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/deleteMany.json b/tests/Collection/spec-tests/write/deleteMany.json new file mode 100644 index 000000000..885ebd200 --- /dev/null +++ b/tests/Collection/spec-tests/write/deleteMany.json @@ -0,0 +1,76 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/deleteOne-collation.json b/tests/Collection/spec-tests/write/deleteOne-collation.json new file mode 100644 index 000000000..9f22b1124 --- /dev/null +++ b/tests/Collection/spec-tests/write/deleteOne-collation.json @@ -0,0 +1,51 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/deleteOne.json b/tests/Collection/spec-tests/write/deleteOne.json new file mode 100644 index 000000000..50226bdd5 --- /dev/null +++ b/tests/Collection/spec-tests/write/deleteOne.json @@ -0,0 +1,96 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndDelete-collation.json b/tests/Collection/spec-tests/write/findOneAndDelete-collation.json new file mode 100644 index 000000000..e848d754d --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndDelete-collation.json @@ -0,0 +1,59 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndDelete.json b/tests/Collection/spec-tests/write/findOneAndDelete.json new file mode 100644 index 000000000..2bfcc32c6 --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndDelete.json @@ -0,0 +1,127 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndReplace-collation.json b/tests/Collection/spec-tests/write/findOneAndReplace-collation.json new file mode 100644 index 000000000..5227b0f8f --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndReplace-collation.json @@ -0,0 +1,58 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndReplace-upsert.json b/tests/Collection/spec-tests/write/findOneAndReplace-upsert.json new file mode 100644 index 000000000..e13eb9c2b --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndReplace-upsert.json @@ -0,0 +1,201 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndReplace-upsert_pre_2.6.json b/tests/Collection/spec-tests/write/findOneAndReplace-upsert_pre_2.6.json new file mode 100644 index 000000000..613c664bf --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndReplace-upsert_pre_2.6.json @@ -0,0 +1,161 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndReplace.json b/tests/Collection/spec-tests/write/findOneAndReplace.json new file mode 100644 index 000000000..f8eb5ebb6 --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndReplace.json @@ -0,0 +1,273 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndUpdate-collation.json b/tests/Collection/spec-tests/write/findOneAndUpdate-collation.json new file mode 100644 index 000000000..172149ac8 --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndUpdate-collation.json @@ -0,0 +1,67 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/findOneAndUpdate.json b/tests/Collection/spec-tests/write/findOneAndUpdate.json new file mode 100644 index 000000000..c257b7402 --- /dev/null +++ b/tests/Collection/spec-tests/write/findOneAndUpdate.json @@ -0,0 +1,379 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/insertMany.json b/tests/Collection/spec-tests/write/insertMany.json new file mode 100644 index 000000000..f604ef75f --- /dev/null +++ b/tests/Collection/spec-tests/write/insertMany.json @@ -0,0 +1,52 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/insertOne.json b/tests/Collection/spec-tests/write/insertOne.json new file mode 100644 index 000000000..83597fca8 --- /dev/null +++ b/tests/Collection/spec-tests/write/insertOne.json @@ -0,0 +1,39 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/replaceOne-collation.json b/tests/Collection/spec-tests/write/replaceOne-collation.json new file mode 100644 index 000000000..c2a08c9b1 --- /dev/null +++ b/tests/Collection/spec-tests/write/replaceOne-collation.json @@ -0,0 +1,53 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/replaceOne-pre_2.6.json b/tests/Collection/spec-tests/write/replaceOne-pre_2.6.json new file mode 100644 index 000000000..363bad50b --- /dev/null +++ b/tests/Collection/spec-tests/write/replaceOne-pre_2.6.json @@ -0,0 +1,179 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/replaceOne-upsert.json b/tests/Collection/spec-tests/write/replaceOne-upsert.json new file mode 100644 index 000000000..f3040dcc9 --- /dev/null +++ b/tests/Collection/spec-tests/write/replaceOne-upsert.json @@ -0,0 +1,104 @@ +{ + "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 + } + } + } + ] +} diff --git a/tests/Collection/spec-tests/write/replaceOne.json b/tests/Collection/spec-tests/write/replaceOne.json new file mode 100644 index 000000000..580e3b939 --- /dev/null +++ b/tests/Collection/spec-tests/write/replaceOne.json @@ -0,0 +1,205 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateMany-collation.json b/tests/Collection/spec-tests/write/updateMany-collation.json new file mode 100644 index 000000000..d88ce60fc --- /dev/null +++ b/tests/Collection/spec-tests/write/updateMany-collation.json @@ -0,0 +1,62 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateMany-pre_2.6.json b/tests/Collection/spec-tests/write/updateMany-pre_2.6.json new file mode 100644 index 000000000..89e8a5c91 --- /dev/null +++ b/tests/Collection/spec-tests/write/updateMany-pre_2.6.json @@ -0,0 +1,179 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateMany.json b/tests/Collection/spec-tests/write/updateMany.json new file mode 100644 index 000000000..533e3f308 --- /dev/null +++ b/tests/Collection/spec-tests/write/updateMany.json @@ -0,0 +1,183 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateOne-collation.json b/tests/Collection/spec-tests/write/updateOne-collation.json new file mode 100644 index 000000000..8e45ff328 --- /dev/null +++ b/tests/Collection/spec-tests/write/updateOne-collation.json @@ -0,0 +1,54 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateOne-pre_2.6.json b/tests/Collection/spec-tests/write/updateOne-pre_2.6.json new file mode 100644 index 000000000..de15c6162 --- /dev/null +++ b/tests/Collection/spec-tests/write/updateOne-pre_2.6.json @@ -0,0 +1,163 @@ +{ + "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 diff --git a/tests/Collection/spec-tests/write/updateOne.json b/tests/Collection/spec-tests/write/updateOne.json new file mode 100644 index 000000000..1a51dff13 --- /dev/null +++ b/tests/Collection/spec-tests/write/updateOne.json @@ -0,0 +1,167 @@ +{ + "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 From f7702951a89c5011b154faaea30667ce4db79988 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 5 Jan 2017 14:59:40 -0500 Subject: [PATCH 2/3] Add missing use statement for BSONArray class --- tests/FunctionalTestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index c9855ea6a..e39beddf9 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -6,6 +6,7 @@ use MongoDB\Driver\Cursor; use MongoDB\Driver\Manager; use MongoDB\Driver\ReadPreference; +use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; use InvalidArgumentException; use stdClass; From 5d785088379d8b34ad454526f701fa1c8ab43e3d Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 5 Jan 2017 15:00:56 -0500 Subject: [PATCH 3/3] Remove obsolete doc block lines --- tests/GridFS/SpecFunctionalTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/GridFS/SpecFunctionalTest.php b/tests/GridFS/SpecFunctionalTest.php index 1fb739494..135c60983 100644 --- a/tests/GridFS/SpecFunctionalTest.php +++ b/tests/GridFS/SpecFunctionalTest.php @@ -202,7 +202,6 @@ private function executeAct(array $act) * @param array $assert * @param mixed $actualResult * @return mixed - * @throws FileNotFoundException * @throws LogicException if the operation is unsupported */ private function executeAssert(array $assert, $actualResult) @@ -241,7 +240,6 @@ private function executeAssert(array $assert, $actualResult) * * @param mixed $expectedResult * @param mixed $actualResult - * @param array $data * @throws LogicException if the result assertion is unsupported */ private function executeAssertResult($expectedResult, $actualResult)