Skip to content

Commit 83b8d5b

Browse files
committed
Change Collection::renameCollection toCollection::rename(), update CollectionFunctionalTest
1 parent d5504bd commit 83b8d5b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce,
10161016
* @throws InvalidArgumentException for parameter/option parsing errors
10171017
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
10181018
*/
1019-
public function renameCollection($toNamespace, array $options = [])
1019+
public function rename($toNamespace, array $options = [])
10201020
{
10211021
if (! isset($options['typeMap'])) {
10221022
$options['typeMap'] = $this->typeMap;

tests/Collection/CollectionFunctionalTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use MongoDB\Exception\UnsupportedException;
1414
use MongoDB\MapReduceResult;
1515
use MongoDB\Operation\Count;
16+
use MongoDB\Operation\DropCollection;
17+
use MongoDB\Operation\FindOne;
1618
use MongoDB\Tests\CommandObserver;
1719

1820
use function array_filter;
@@ -332,13 +334,21 @@ public function testFindWithinTransaction(): void
332334
}
333335
}
334336

335-
public function testRenameCollection(): void
337+
public function testRename(): void
336338
{
337-
$writeResult = $this->collection->insertOne(['x' => 1]);
339+
$renamedCollection = $this->getCollectionName() . '.renamed';
340+
$operation = new DropCollection($this->getDatabaseName(), $renamedCollection);
341+
$operation->execute($this->getPrimaryServer());
342+
343+
$writeResult = $this->collection->insertOne(['_id' => 1, 'x' => 'foo']);
338344
$this->assertEquals(1, $writeResult->getInsertedCount());
339345

340-
$commandResult = $this->collection->renameCollection($this->getCollectionName() . 'renamed');
346+
$commandResult = $this->collection->rename($this->getDatabaseName() . '.' . $renamedCollection);
341347
$this->assertCommandSucceeded($commandResult);
348+
349+
$operation = new FindOne($this->getDatabaseName(), $renamedCollection, []);
350+
$cursor = $operation->execute($this->getPrimaryServer());
351+
$this->assertSameDocument(['_id' => 1, 'x' => 'foo'], $cursor);
342352
}
343353

344354
public function testWithOptionsInheritsOptions(): void

0 commit comments

Comments
 (0)