Skip to content

Commit 9fcabfa

Browse files
committed
Fix tests for renaming collection to different database
1 parent 8762274 commit 9fcabfa

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use MongoDB\BSON\Javascript;
77
use MongoDB\Collection;
8+
use MongoDB\Database;
89
use MongoDB\Driver\BulkWrite;
910
use MongoDB\Driver\ReadConcern;
1011
use MongoDB\Driver\ReadPreference;
@@ -352,21 +353,24 @@ public function testRenameToSameDatabase(): void
352353

353354
public function testRenameToDifferentDatabase(): void
354355
{
355-
$toCollectionName = $this->getCollectionName() . '.renamed';
356356
$toDatabaseName = $this->getDatabaseName() . '_renamed';
357+
$toCollectionName = $this->getCollectionName() . '.renamed';
358+
$toDatabase = new Database($this->manager, $toDatabaseName);
357359
$toCollection = new Collection($this->manager, $toDatabaseName, $toCollectionName);
358360

359361
$writeResult = $this->collection->insertOne(['_id' => 1]);
360362
$this->assertEquals(1, $writeResult->getInsertedCount());
361363

362-
$commandResult = $this->collection->rename($toCollectionName, $toDatabaseName, ['dropTarget' => true]);
364+
$commandResult = $this->collection->rename($toCollectionName, $toDatabaseName);
363365
$this->assertCommandSucceeded($commandResult);
364366
$this->assertCollectionDoesNotExist($this->getCollectionName());
365367
$this->assertCollectionExists($toCollectionName, $toDatabaseName);
366368

367369
$document = $toCollection->findOne();
368370
$this->assertSameDocument(['_id' => 1], $document);
371+
369372
$toCollection->drop();
373+
$toDatabase->drop();
370374
}
371375

372376
public function testWithOptionsInheritsOptions(): void

tests/Database/DatabaseFunctionalTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ public function testRenameCollectionToSameDatabase(): void
240240

241241
public function testRenameCollectionToDifferentDatabase(): void
242242
{
243-
$toCollectionName = $this->getCollectionName() . '.renamed';
244243
$toDatabaseName = $this->getDatabaseName() . '_renamed';
244+
$toCollectionName = $this->getCollectionName() . '.renamed';
245+
$toDatabase = new Database($this->manager, $toDatabaseName);
245246
$toCollection = new Collection($this->manager, $toDatabaseName, $toCollectionName);
246247

247248
$bulkWrite = new BulkWrite();
@@ -253,16 +254,17 @@ public function testRenameCollectionToDifferentDatabase(): void
253254
$commandResult = $this->database->renameCollection(
254255
$this->getCollectionName(),
255256
$toCollectionName,
256-
$toDatabaseName,
257-
['dropTarget' => true]
257+
$toDatabaseName
258258
);
259259
$this->assertCommandSucceeded($commandResult);
260260
$this->assertCollectionDoesNotExist($this->getCollectionName());
261261
$this->assertCollectionExists($toCollectionName, $toDatabaseName);
262262

263263
$document = $toCollection->findOne();
264264
$this->assertSameDocument(['_id' => 1], $document);
265+
265266
$toCollection->drop();
267+
$toDatabase->drop();
266268
}
267269

268270
public function testSelectCollectionInheritsOptions(): void

0 commit comments

Comments
 (0)