Skip to content

Commit cb6947a

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

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 5 additions & 1 deletion
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,8 +353,9 @@ 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]);
@@ -366,7 +368,9 @@ public function testRenameToDifferentDatabase(): void
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: 4 additions & 1 deletion
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();
@@ -262,7 +263,9 @@ public function testRenameCollectionToDifferentDatabase(): void
262263

263264
$document = $toCollection->findOne();
264265
$this->assertSameDocument(['_id' => 1], $document);
266+
265267
$toCollection->drop();
268+
$toDatabase->drop();
266269
}
267270

268271
public function testSelectCollectionInheritsOptions(): void

0 commit comments

Comments
 (0)