|
2 | 2 |
|
3 | 3 | namespace MongoDB\Tests\Operation;
|
4 | 4 |
|
| 5 | +use MongoDB\Driver\ReadConcern; |
| 6 | +use MongoDB\Driver\ReadPreference; |
| 7 | +use MongoDB\Driver\WriteConcern; |
5 | 8 | use MongoDB\Exception\InvalidArgumentException;
|
6 | 9 | use MongoDB\Operation\Aggregate;
|
7 | 10 |
|
@@ -104,4 +107,40 @@ private function getInvalidHintValues()
|
104 | 107 | {
|
105 | 108 | return [123, 3.14, true];
|
106 | 109 | }
|
| 110 | + |
| 111 | + public function testExplainableCommandDocument(): void |
| 112 | + { |
| 113 | + $options = [ |
| 114 | + 'allowDiskUse' => true, |
| 115 | + 'batchSize' => 100, |
| 116 | + 'bypassDocumentValidation' => true, |
| 117 | + 'collation' => ['locale' => 'fr'], |
| 118 | + 'comment' => 'explain me', |
| 119 | + 'hint' => '_id_', |
| 120 | + 'let' => ['a' => 1], |
| 121 | + 'maxTimeMS' => 100, |
| 122 | + 'readConcern' => new ReadConcern(ReadConcern::LOCAL), |
| 123 | + 'useCursor' => true, |
| 124 | + // Intentionally omitted options |
| 125 | + 'explain' => true, |
| 126 | + 'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED), |
| 127 | + 'typeMap' => ['root' => 'array', 'document' => 'array'], |
| 128 | + 'writeConcern' => new WriteConcern(0), |
| 129 | + ]; |
| 130 | + $operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$project' => ['_id' => 0]]], $options); |
| 131 | + |
| 132 | + $expected = [ |
| 133 | + 'aggregate' => $this->getCollectionName(), |
| 134 | + 'pipeline' => [['$project' => ['_id' => 0]]], |
| 135 | + 'allowDiskUse' => true, |
| 136 | + 'bypassDocumentValidation' => true, |
| 137 | + 'collation' => (object) ['locale' => 'fr'], |
| 138 | + 'comment' => 'explain me', |
| 139 | + 'hint' => '_id_', |
| 140 | + 'maxTimeMS' => 100, |
| 141 | + 'readConcern' => new ReadConcern(ReadConcern::LOCAL), |
| 142 | + 'let' => (object) ['a' => 1], |
| 143 | + ]; |
| 144 | + $this->assertEquals($expected, $operation->getCommandDocument()); |
| 145 | + } |
107 | 146 | }
|
0 commit comments