|
10 | 10 | use MongoDB\Driver\WriteConcern;
|
11 | 11 | use MongoDB\Exception\InvalidArgumentException;
|
12 | 12 | use MongoDB\Operation\CreateIndexes;
|
| 13 | +use MongoDB\Operation\DropCollection; |
| 14 | +use MongoDB\Operation\FindOne; |
13 | 15 |
|
14 | 16 | use function array_key_exists;
|
15 | 17 | use function current;
|
@@ -211,6 +213,29 @@ public function testModifyCollection(): void
|
211 | 213 | }
|
212 | 214 | }
|
213 | 215 |
|
| 216 | + public function testRenameCollection(): void |
| 217 | + { |
| 218 | + $renamedCollection = $this->getCollectionName() . '.renamed'; |
| 219 | + $renamedNamespace = $this->getDatabaseName() . '.' . $renamedCollection; |
| 220 | + $operation = new DropCollection($this->getDatabaseName(), $renamedCollection); |
| 221 | + $operation->execute($this->getPrimaryServer()); |
| 222 | + |
| 223 | + $bulkWrite = new BulkWrite(); |
| 224 | + $bulkWrite->insert(['_id' => 1, 'x' => 'foo']); |
| 225 | + |
| 226 | + $writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite); |
| 227 | + $this->assertEquals(1, $writeResult->getInsertedCount()); |
| 228 | + |
| 229 | + $commandResult = $this->database->renameCollection($this->getNamespace(), $renamedNamespace); |
| 230 | + $this->assertCommandSucceeded($commandResult); |
| 231 | + $this->assertCollectionCount($this->getNamespace(), 0); |
| 232 | + $this->assertCollectionCount($renamedNamespace, 1); |
| 233 | + |
| 234 | + $operation = new FindOne($this->getDatabaseName(), $renamedCollection, []); |
| 235 | + $cursor = $operation->execute($this->getPrimaryServer()); |
| 236 | + $this->assertSameDocument(['_id' => 1, 'x' => 'foo'], $cursor); |
| 237 | + } |
| 238 | + |
214 | 239 | public function testSelectCollectionInheritsOptions(): void
|
215 | 240 | {
|
216 | 241 | $databaseOptions = [
|
|
0 commit comments