|
2 | 2 |
|
3 | 3 | namespace MongoDB\Tests\Operation; |
4 | 4 |
|
| 5 | +use MongoDB\Driver\WriteConcern; |
5 | 6 | use MongoDB\Exception\InvalidArgumentException; |
6 | 7 | use MongoDB\Operation\FindAndModify; |
7 | 8 |
|
@@ -83,4 +84,46 @@ public function testConstructorUpdateAndRemoveOptionsAreMutuallyExclusive(): voi |
83 | 84 | $this->expectExceptionMessage('The "remove" option must be true or an "update" document must be specified, but not both'); |
84 | 85 | new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), ['remove' => true, 'update' => []]); |
85 | 86 | } |
| 87 | + |
| 88 | + public function testExplainableCommandDocument(): void |
| 89 | + { |
| 90 | + $options = [ |
| 91 | + 'arrayFilters' => [['x' => 1]], |
| 92 | + 'bypassDocumentValidation' => true, |
| 93 | + 'collation' => ['locale' => 'fr'], |
| 94 | + 'comment' => 'explain me', |
| 95 | + 'fields' => ['_id' => 0], |
| 96 | + 'hint' => '_id_', |
| 97 | + 'maxTimeMS' => 100, |
| 98 | + 'new' => true, |
| 99 | + 'query' => ['y' => 2], |
| 100 | + 'sort' => ['x' => 1], |
| 101 | + 'update' => ['$set' => ['x' => 2]], |
| 102 | + 'upsert' => true, |
| 103 | + 'let' => ['a' => 3], |
| 104 | + // Intentionally omitted options |
| 105 | + 'remove' => false, // When "update" is set |
| 106 | + 'typeMap' => ['root' => 'array'], |
| 107 | + 'writeConcern' => new WriteConcern(0), |
| 108 | + ]; |
| 109 | + $operation = new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), $options); |
| 110 | + |
| 111 | + $expected = [ |
| 112 | + 'findAndModify' => $this->getCollectionName(), |
| 113 | + 'new' => true, |
| 114 | + 'upsert' => true, |
| 115 | + 'collation' => (object) ['locale' => 'fr'], |
| 116 | + 'fields' => (object) ['_id' => 0], |
| 117 | + 'let' => (object) ['a' => 3], |
| 118 | + 'query' => (object) ['y' => 2], |
| 119 | + 'sort' => (object) ['x' => 1], |
| 120 | + 'update' => (object) ['$set' => ['x' => 2]], |
| 121 | + 'arrayFilters' => [['x' => 1]], |
| 122 | + 'bypassDocumentValidation' => true, |
| 123 | + 'comment' => 'explain me', |
| 124 | + 'hint' => '_id_', |
| 125 | + 'maxTimeMS' => 100, |
| 126 | + ]; |
| 127 | + $this->assertEquals($expected, $operation->getCommandDocument()); |
| 128 | + } |
86 | 129 | } |
0 commit comments