Skip to content

Commit 0738070

Browse files
committed
Explicitly set the database and collection name
1 parent 8c70472 commit 0738070

14 files changed

+45
-63
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testAggregateWithinTransaction(): void
114114
$this->skipIfTransactionsAreNotSupported();
115115

116116
// Collection must be created before the transaction starts
117-
$this->createCollection();
117+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
118118

119119
$session = $this->manager->startSession();
120120
$session->startTransaction();
@@ -294,7 +294,7 @@ public function testFindWithinTransaction(): void
294294
$this->skipIfTransactionsAreNotSupported();
295295

296296
// Collection must be created before the transaction starts
297-
$this->createCollection();
297+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
298298

299299
$session = $this->manager->startSession();
300300
$session->startTransaction();
@@ -727,7 +727,7 @@ public function testMethodDoesNotInheritReadWriteConcernInTranasaction(Closure $
727727
{
728728
$this->skipIfTransactionsAreNotSupported();
729729

730-
$this->createCollection();
730+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
731731

732732
$session = $this->manager->startSession();
733733
$session->startTransaction();
@@ -753,7 +753,7 @@ public function testMethodInTransactionWithWriteConcernOption($method): void
753753
{
754754
$this->skipIfTransactionsAreNotSupported();
755755

756-
$this->createCollection();
756+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
757757

758758
$session = $this->manager->startSession();
759759
$session->startTransaction();
@@ -773,7 +773,7 @@ public function testMethodInTransactionWithReadConcernOption($method): void
773773
{
774774
$this->skipIfTransactionsAreNotSupported();
775775

776-
$this->createCollection();
776+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
777777

778778
$session = $this->manager->startSession();
779779
$session->startTransaction();

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function setUp(): void
4848
{
4949
parent::setUp();
5050

51-
$this->dropCollection(null, $this->getCollectionName() . '.expected');
51+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName() . '.expected');
5252
$this->expectedCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.expected');
5353
}
5454

tests/Collection/FunctionalTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public function setUp(): void
1919

2020
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
2121

22-
$this->dropCollection();
22+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
2323
}
2424
}

tests/DocumentationExamplesTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
3333
{
3434
public function testExample_1_2(): void
3535
{
36-
$this->dropCollection(null, 'inventory');
36+
$this->dropCollection($this->getDatabaseName(), 'inventory');
3737
$db = new Database($this->manager, $this->getDatabaseName());
3838

3939
// Start Example 1
@@ -58,7 +58,7 @@ public function testExample_1_2(): void
5858

5959
public function testExample_3(): void
6060
{
61-
$this->dropCollection(null, 'inventory');
61+
$this->dropCollection($this->getDatabaseName(), 'inventory');
6262
$db = new Database($this->manager, $this->getDatabaseName());
6363

6464
// Start Example 3
@@ -94,7 +94,7 @@ public function testExample_3(): void
9494

9595
public function testExample_6_13(): void
9696
{
97-
$this->dropCollection(null, 'inventory');
97+
$this->dropCollection($this->getDatabaseName(), 'inventory');
9898
$db = new Database($this->manager, $this->getDatabaseName());
9999

100100
// Start Example 6
@@ -199,7 +199,7 @@ public function testExample_6_13(): void
199199

200200
public function testExample_14_19(): void
201201
{
202-
$this->dropCollection(null, 'inventory');
202+
$this->dropCollection($this->getDatabaseName(), 'inventory');
203203
$db = new Database($this->manager, $this->getDatabaseName());
204204

205205
// Start Example 14
@@ -281,7 +281,7 @@ public function testExample_14_19(): void
281281

282282
public function testExample_20_28(): void
283283
{
284-
$this->dropCollection(null, 'inventory');
284+
$this->dropCollection($this->getDatabaseName(), 'inventory');
285285
$db = new Database($this->manager, $this->getDatabaseName());
286286

287287
// Start Example 20
@@ -389,7 +389,7 @@ public function testExample_20_28(): void
389389

390390
public function testExample_29_37(): void
391391
{
392-
$this->dropCollection(null, 'inventory');
392+
$this->dropCollection($this->getDatabaseName(), 'inventory');
393393
$db = new Database($this->manager, $this->getDatabaseName());
394394

395395
// Start Example 29
@@ -489,7 +489,7 @@ public function testExample_29_37(): void
489489

490490
public function testExample_38_41(): void
491491
{
492-
$this->dropCollection(null, 'inventory');
492+
$this->dropCollection($this->getDatabaseName(), 'inventory');
493493
$db = new Database($this->manager, $this->getDatabaseName());
494494

495495
// Start Example 38
@@ -527,7 +527,7 @@ public function testExample_38_41(): void
527527

528528
public function testExample_42_50(): void
529529
{
530-
$this->dropCollection(null, 'inventory');
530+
$this->dropCollection($this->getDatabaseName(), 'inventory');
531531
$db = new Database($this->manager, $this->getDatabaseName());
532532

533533
// Start Example 42
@@ -733,7 +733,7 @@ public function testExample_42_50(): void
733733

734734
public function testExample_51_54(): void
735735
{
736-
$this->dropCollection(null, 'inventory');
736+
$this->dropCollection($this->getDatabaseName(), 'inventory');
737737
$db = new Database($this->manager, $this->getDatabaseName());
738738

739739
// Start Example 51
@@ -875,7 +875,7 @@ public function testExample_51_54(): void
875875

876876
public function testExample_55_58(): void
877877
{
878-
$this->dropCollection(null, 'inventory');
878+
$this->dropCollection($this->getDatabaseName(), 'inventory');
879879
$db = new Database($this->manager, $this->getDatabaseName());
880880

881881
// Start Example 55
@@ -953,7 +953,7 @@ public function testChangeStreamExample_1_4(): void
953953
$this->markTestSkipped('Test does not apply on sharded clusters: need more than a single getMore call on the change stream.');
954954
}
955955

956-
$this->dropCollection(null, 'inventory');
956+
$this->dropCollection($this->getDatabaseName(), 'inventory');
957957
$db = new Database($this->manager, $this->getDatabaseName());
958958
$db->createCollection('inventory');
959959

@@ -1053,7 +1053,7 @@ public function testChangeStreamExample_1_4(): void
10531053

10541054
public function testAggregation_example_1(): void
10551055
{
1056-
$this->dropCollection(null, 'sales');
1056+
$this->dropCollection($this->getDatabaseName(), 'sales');
10571057
$db = new Database($this->manager, $this->getDatabaseName());
10581058

10591059
// Start Aggregation Example 1
@@ -1068,7 +1068,7 @@ public function testAggregation_example_1(): void
10681068

10691069
public function testAggregation_example_2(): void
10701070
{
1071-
$this->dropCollection(null, 'sales');
1071+
$this->dropCollection($this->getDatabaseName(), 'sales');
10721072
$db = new Database($this->manager, $this->getDatabaseName());
10731073

10741074
// Start Aggregation Example 2
@@ -1097,7 +1097,7 @@ public function testAggregation_example_2(): void
10971097

10981098
public function testAggregation_example_3(): void
10991099
{
1100-
$this->dropCollection(null, 'sales');
1100+
$this->dropCollection($this->getDatabaseName(), 'sales');
11011101
$db = new Database($this->manager, $this->getDatabaseName());
11021102

11031103
// Start Aggregation Example 3
@@ -1136,7 +1136,7 @@ public function testAggregation_example_3(): void
11361136

11371137
public function testAggregation_example_4(): void
11381138
{
1139-
$this->dropCollection(null, 'air_airlines');
1139+
$this->dropCollection($this->getDatabaseName(), 'air_airlines');
11401140
$db = new Database($this->manager, $this->getDatabaseName());
11411141

11421142
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
@@ -1189,7 +1189,7 @@ public function testRunCommand_example_1(): void
11891189

11901190
public function testRunCommand_example_2(): void
11911191
{
1192-
$this->dropCollection(null, 'restaurants');
1192+
$this->dropCollection($this->getDatabaseName(), 'restaurants');
11931193
$db = new Database($this->manager, $this->getDatabaseName());
11941194
$db->createCollection('restaurants');
11951195

@@ -1203,7 +1203,7 @@ public function testRunCommand_example_2(): void
12031203

12041204
public function testIndex_example_1(): void
12051205
{
1206-
$this->dropCollection(null, 'records');
1206+
$this->dropCollection($this->getDatabaseName(), 'records');
12071207
$db = new Database($this->manager, $this->getDatabaseName());
12081208

12091209
// Start Index Example 1
@@ -1215,7 +1215,7 @@ public function testIndex_example_1(): void
12151215

12161216
public function testIndex_example_2(): void
12171217
{
1218-
$this->dropCollection(null, 'restaurants');
1218+
$this->dropCollection($this->getDatabaseName(), 'restaurants');
12191219
$db = new Database($this->manager, $this->getDatabaseName());
12201220

12211221
// Start Index Example 2
@@ -1724,7 +1724,7 @@ public function testVersionedApiMigration(): void
17241724
$this->markTestSkipped('The count command was added to API version 1 (SERVER-63850)');
17251725
}
17261726

1727-
$this->dropCollection(null, 'sales');
1727+
$this->dropCollection($this->getDatabaseName(), 'sales');
17281728
$uriString = static::getUri(true);
17291729

17301730
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
@@ -1865,7 +1865,7 @@ public function testQueryableEncryption(): void
18651865
$this->markTestSkipped('Automatic encryption requires MongoDB Enterprise');
18661866
}
18671867

1868-
$this->dropCollection();
1868+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
18691869

18701870
// Fetch names for the database and collection under test
18711871
$collectionName = $this->getCollectionName();

tests/FunctionalTestCase.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,9 @@ public static function getModuleInfo(string $row): ?string
266266
* transaction can acquire the required locks.
267267
* See: https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-operations
268268
*/
269-
protected function createCollection(?string $databaseName = null, ?string $collectionName = null, array $options = []): void
269+
protected function createCollection(string $databaseName, string $collectionName, array $options = []): void
270270
{
271271
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
272-
273-
if (null === $databaseName) {
274-
$databaseName = $this->getDatabaseName();
275-
}
276-
277-
if (null === $collectionName) {
278-
$collectionName = $this->getCollectionName();
279-
}
280-
281272
$operation = new CreateCollection($databaseName, $collectionName, $options);
282273
$operation->execute($this->getPrimaryServer());
283274
$this->collectionsToCleanup[$databaseName][$collectionName] = true;
@@ -290,18 +281,9 @@ protected function createCollection(?string $databaseName = null, ?string $colle
290281
* transaction can acquire the required locks.
291282
* See: https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-operations
292283
*/
293-
protected function dropCollection(?string $databaseName = null, ?string $collectionName = null): void
284+
protected function dropCollection(string $databaseName, string $collectionName): void
294285
{
295286
$options = ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
296-
297-
if (null === $databaseName) {
298-
$databaseName = $this->getDatabaseName();
299-
}
300-
301-
if (null === $collectionName) {
302-
$collectionName = $this->getCollectionName();
303-
}
304-
305287
$operation = new DropCollection($databaseName, $collectionName, $options);
306288
$operation->execute($this->getPrimaryServer());
307289
$this->collectionsToCleanup[$databaseName][$collectionName] = true;

tests/Model/ChangeStreamIteratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function setUp(): void
2828
{
2929
parent::setUp();
3030

31-
$this->dropCollection();
32-
$this->createCollection(null, null, ['capped' => true, 'size' => 8192]);
31+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
32+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName(), ['capped' => true, 'size' => 8192]);
3333

3434
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
3535
}

tests/Model/IndexInfoFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp(): void
1414
{
1515
parent::setUp();
1616

17-
$this->dropCollection();
17+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
1818
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
1919
}
2020

tests/Operation/AggregateFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function testReadPreferenceWithinTransaction(): void
305305
$this->skipIfTransactionsAreNotSupported();
306306

307307
// Collection must be created before the transaction starts
308-
$this->createCollection();
308+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
309309

310310
$session = $this->manager->startSession();
311311
$session->startTransaction();

tests/Operation/FindFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function testReadPreferenceWithinTransaction(): void
210210
$this->skipIfTransactionsAreNotSupported();
211211

212212
// Collection must be created before the transaction starts
213-
$this->createCollection();
213+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
214214

215215
$session = $this->manager->startSession();
216216
$session->startTransaction();

tests/Operation/FunctionalTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function setUp(): void
1515
{
1616
parent::setUp();
1717

18-
$this->dropCollection();
18+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
1919
}
2020

2121
protected function createDefaultReadConcern()

tests/Operation/ListIndexesFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
1212
{
1313
public function testListIndexesForNewlyCreatedCollection(): void
1414
{
15-
$this->dropCollection();
15+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
1616

1717
$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1]);
1818
$writeResult = $insertOne->execute($this->getPrimaryServer());
@@ -34,7 +34,7 @@ public function testListIndexesForNewlyCreatedCollection(): void
3434

3535
public function testListIndexesForNonexistentCollection(): void
3636
{
37-
$this->dropCollection();
37+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
3838

3939
$operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName());
4040
$indexes = $operation->execute($this->getPrimaryServer());

tests/Operation/MapReduceFunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MapReduceFunctionalTest extends FunctionalTestCase
2525
public function testDefaultReadConcernIsOmitted(): void
2626
{
2727
// Collection must exist for mapReduce command
28-
$this->createCollection();
28+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
2929

3030
(new CommandObserver())->observe(
3131
function (): void {
@@ -49,8 +49,8 @@ function (array $event): void {
4949
public function testDefaultWriteConcernIsOmitted(): void
5050
{
5151
// Collection must exist for mapReduce command
52-
$this->createCollection();
53-
$this->dropCollection(null, $this->getCollectionName() . '.output');
52+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
53+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName() . '.output');
5454

5555
(new CommandObserver())->observe(
5656
function (): void {
@@ -270,7 +270,7 @@ public function testTypeMapOptionWithOutputCollection(?array $typeMap, array $ex
270270
$map = new Javascript('function() { emit(this.x, this.y); }');
271271
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
272272
$out = $this->getCollectionName() . '.output';
273-
$this->dropCollection(null, $out);
273+
$this->dropCollection($this->getDatabaseName(), $out);
274274

275275
$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['typeMap' => $typeMap]);
276276
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
@@ -288,7 +288,7 @@ public function testTypeMapOptionWithOutputCollection(?array $typeMap, array $ex
288288
*/
289289
private function createFixtures(int $n): void
290290
{
291-
$this->dropCollection();
291+
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
292292
$bulkWrite = new BulkWrite(['ordered' => true]);
293293

294294
for ($i = 1; $i <= $n; $i++) {

tests/Operation/ModifyCollectionFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testCollMod(): void
1818
$this->markTestSkipped('Sharded clusters may report result inconsistently');
1919
}
2020

21-
$this->createCollection();
21+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
2222

2323
$indexes = [['key' => ['lastAccess' => 1], 'expireAfterSeconds' => 3]];
2424
$createIndexes = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);

0 commit comments

Comments
 (0)