Skip to content

Commit 54562a3

Browse files
committed
Add testRenameCollection() to DatabaseFunctionalTest
1 parent 07262f8 commit 54562a3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/Database/DatabaseFunctionalTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use MongoDB\Driver\WriteConcern;
1111
use MongoDB\Exception\InvalidArgumentException;
1212
use MongoDB\Operation\CreateIndexes;
13+
use MongoDB\Operation\DropCollection;
14+
use MongoDB\Operation\FindOne;
1315

1416
use function array_key_exists;
1517
use function current;
@@ -211,6 +213,29 @@ public function testModifyCollection(): void
211213
}
212214
}
213215

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+
214239
public function testSelectCollectionInheritsOptions(): void
215240
{
216241
$databaseOptions = [

0 commit comments

Comments
 (0)