|
5 | 5 | use Closure;
|
6 | 6 | use MongoDB\BSON\Javascript;
|
7 | 7 | use MongoDB\Collection;
|
| 8 | +use MongoDB\Database; |
8 | 9 | use MongoDB\Driver\BulkWrite;
|
9 | 10 | use MongoDB\Driver\ReadConcern;
|
10 | 11 | use MongoDB\Driver\ReadPreference;
|
@@ -352,21 +353,28 @@ public function testRenameToSameDatabase(): void
|
352 | 353 |
|
353 | 354 | public function testRenameToDifferentDatabase(): void
|
354 | 355 | {
|
355 |
| - $toCollectionName = $this->getCollectionName() . '.renamed'; |
| 356 | + if ($this->isShardedCluster()) { |
| 357 | + $this->markTestSkipped('Test does not apply on sharded clusters: need source and target databases to be on the same primary shard.'); |
| 358 | + } |
| 359 | + |
356 | 360 | $toDatabaseName = $this->getDatabaseName() . '_renamed';
|
| 361 | + $toCollectionName = $this->getCollectionName() . '.renamed'; |
| 362 | + $toDatabase = new Database($this->manager, $toDatabaseName); |
357 | 363 | $toCollection = new Collection($this->manager, $toDatabaseName, $toCollectionName);
|
358 | 364 |
|
359 | 365 | $writeResult = $this->collection->insertOne(['_id' => 1]);
|
360 | 366 | $this->assertEquals(1, $writeResult->getInsertedCount());
|
361 | 367 |
|
362 |
| - $commandResult = $this->collection->rename($toCollectionName, $toDatabaseName, ['dropTarget' => true]); |
| 368 | + $commandResult = $this->collection->rename($toCollectionName, $toDatabaseName); |
363 | 369 | $this->assertCommandSucceeded($commandResult);
|
364 | 370 | $this->assertCollectionDoesNotExist($this->getCollectionName());
|
365 | 371 | $this->assertCollectionExists($toCollectionName, $toDatabaseName);
|
366 | 372 |
|
367 | 373 | $document = $toCollection->findOne();
|
368 | 374 | $this->assertSameDocument(['_id' => 1], $document);
|
| 375 | + |
369 | 376 | $toCollection->drop();
|
| 377 | + $toDatabase->drop(); |
370 | 378 | }
|
371 | 379 |
|
372 | 380 | public function testWithOptionsInheritsOptions(): void
|
|
0 commit comments