Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f6e3c18

Browse files
committedMay 28, 2025··
Change string literals in SchemaTest to constants
1 parent f225772 commit f6e3c18

File tree

1 file changed

+127
-125
lines changed

1 file changed

+127
-125
lines changed
 

‎tests/SchemaTest.php

Lines changed: 127 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
class SchemaTest extends TestCase
2222
{
23+
private const COLL_1 = 'new_collection';
24+
private const COLL_2 = 'new_collection_two';
2325
private const COLL_WITH_COLLATION = 'collection_with_collation';
2426

2527
public function tearDown(): void
2628
{
2729
$database = $this->getConnection('mongodb')->getDatabase();
2830
assert($database instanceof Database);
29-
$database->dropCollection('newcollection');
30-
$database->dropCollection('newcollection_two');
31+
$database->dropCollection(self::COLL_1);
32+
$database->dropCollection(self::COLL_2);
3133
$database->dropCollection(self::COLL_WITH_COLLATION);
3234
$database->dropCollection('test_view');
3335

@@ -36,204 +38,204 @@ public function tearDown(): void
3638

3739
public function testCreate(): void
3840
{
39-
Schema::create('newcollection');
40-
$this->assertTrue(Schema::hasCollection('newcollection'));
41-
$this->assertTrue(Schema::hasTable('newcollection'));
41+
Schema::create(self::COLL_1);
42+
$this->assertTrue(Schema::hasCollection(self::COLL_1));
43+
$this->assertTrue(Schema::hasTable(self::COLL_1));
4244
}
4345

4446
public function testCreateWithCallback(): void
4547
{
46-
Schema::create('newcollection', static function ($collection) {
48+
Schema::create(self::COLL_1, static function ($collection) {
4749
self::assertInstanceOf(Blueprint::class, $collection);
4850
});
4951

50-
$this->assertTrue(Schema::hasCollection('newcollection'));
52+
$this->assertTrue(Schema::hasCollection(self::COLL_1));
5153
}
5254

5355
public function testCreateWithOptions(): void
5456
{
55-
Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]);
56-
$this->assertTrue(Schema::hasCollection('newcollection_two'));
57-
$this->assertTrue(Schema::hasTable('newcollection_two'));
57+
Schema::create(self::COLL_2, null, ['capped' => true, 'size' => 1024]);
58+
$this->assertTrue(Schema::hasCollection(self::COLL_2));
59+
$this->assertTrue(Schema::hasTable(self::COLL_2));
5860

59-
$collection = Schema::getCollection('newcollection_two');
61+
$collection = Schema::getCollection(self::COLL_2);
6062
$this->assertTrue($collection['options']['capped']);
6163
$this->assertEquals(1024, $collection['options']['size']);
6264
}
6365

6466
public function testDrop(): void
6567
{
66-
Schema::create('newcollection');
67-
Schema::drop('newcollection');
68-
$this->assertFalse(Schema::hasCollection('newcollection'));
68+
Schema::create(self::COLL_1);
69+
Schema::drop(self::COLL_1);
70+
$this->assertFalse(Schema::hasCollection(self::COLL_1));
6971
}
7072

7173
public function testBluePrint(): void
7274
{
73-
Schema::table('newcollection', static function ($collection) {
75+
Schema::table(self::COLL_1, static function ($collection) {
7476
self::assertInstanceOf(Blueprint::class, $collection);
7577
});
7678

77-
Schema::table('newcollection', static function ($collection) {
79+
Schema::table(self::COLL_1, static function ($collection) {
7880
self::assertInstanceOf(Blueprint::class, $collection);
7981
});
8082
}
8183

8284
public function testIndex(): void
8385
{
84-
Schema::table('newcollection', function ($collection) {
86+
Schema::table(self::COLL_1, function ($collection) {
8587
$collection->index('mykey1');
8688
});
8789

88-
$index = $this->assertIndexExists('newcollection', 'mykey1_1');
90+
$index = $this->assertIndexExists(self::COLL_1, 'mykey1_1');
8991
$this->assertEquals(1, $index['key']['mykey1']);
9092

91-
Schema::table('newcollection', function ($collection) {
93+
Schema::table(self::COLL_1, function ($collection) {
9294
$collection->index(['mykey2']);
9395
});
9496

95-
$index = $this->assertIndexExists('newcollection', 'mykey2_1');
97+
$index = $this->assertIndexExists(self::COLL_1, 'mykey2_1');
9698
$this->assertEquals(1, $index['key']['mykey2']);
9799

98-
Schema::table('newcollection', function ($collection) {
100+
Schema::table(self::COLL_1, function ($collection) {
99101
$collection->string('mykey3')->index();
100102
});
101103

102-
$index = $this->assertIndexExists('newcollection', 'mykey3_1');
104+
$index = $this->assertIndexExists(self::COLL_1, 'mykey3_1');
103105
$this->assertEquals(1, $index['key']['mykey3']);
104106
}
105107

106108
public function testPrimary(): void
107109
{
108-
Schema::table('newcollection', function ($collection) {
110+
Schema::table(self::COLL_1, function ($collection) {
109111
$collection->string('mykey', 100)->primary();
110112
});
111113

112-
$index = $this->assertIndexExists('newcollection', 'mykey_1');
114+
$index = $this->assertIndexExists(self::COLL_1, 'mykey_1');
113115
$this->assertEquals(1, $index['unique']);
114116
}
115117

116118
public function testUnique(): void
117119
{
118-
Schema::table('newcollection', function ($collection) {
120+
Schema::table(self::COLL_1, function ($collection) {
119121
$collection->unique('uniquekey');
120122
});
121123

122-
$index = $this->assertIndexExists('newcollection', 'uniquekey_1');
124+
$index = $this->assertIndexExists(self::COLL_1, 'uniquekey_1');
123125
$this->assertEquals(1, $index['unique']);
124126
}
125127

126128
public function testDropIndex(): void
127129
{
128-
Schema::table('newcollection', function ($collection) {
130+
Schema::table(self::COLL_1, function ($collection) {
129131
$collection->unique('uniquekey');
130132
$collection->dropIndex('uniquekey_1');
131133
});
132134

133-
$this->assertIndexNotExists('newcollection', 'uniquekey_1');
135+
$this->assertIndexNotExists(self::COLL_1, 'uniquekey_1');
134136

135-
Schema::table('newcollection', function ($collection) {
137+
Schema::table(self::COLL_1, function ($collection) {
136138
$collection->unique('uniquekey');
137139
$collection->dropIndex(['uniquekey']);
138140
});
139141

140-
$this->assertIndexNotExists('newcollection', 'uniquekey_1');
142+
$this->assertIndexNotExists(self::COLL_1, 'uniquekey_1');
141143

142-
Schema::table('newcollection', function ($collection) {
144+
Schema::table(self::COLL_1, function ($collection) {
143145
$collection->index(['field_a', 'field_b']);
144146
});
145147

146-
$this->assertIndexExists('newcollection', 'field_a_1_field_b_1');
148+
$this->assertIndexExists(self::COLL_1, 'field_a_1_field_b_1');
147149

148-
Schema::table('newcollection', function ($collection) {
150+
Schema::table(self::COLL_1, function ($collection) {
149151
$collection->dropIndex(['field_a', 'field_b']);
150152
});
151153

152-
$this->assertIndexNotExists('newcollection', 'field_a_1_field_b_1');
154+
$this->assertIndexNotExists(self::COLL_1, 'field_a_1_field_b_1');
153155

154156
$indexName = 'field_a_-1_field_b_1';
155-
Schema::table('newcollection', function ($collection) {
157+
Schema::table(self::COLL_1, function ($collection) {
156158
$collection->index(['field_a' => -1, 'field_b' => 1]);
157159
});
158160

159-
$this->assertIndexExists('newcollection', $indexName);
161+
$this->assertIndexExists(self::COLL_1, $indexName);
160162

161-
Schema::table('newcollection', function ($collection) {
163+
Schema::table(self::COLL_1, function ($collection) {
162164
$collection->dropIndex(['field_a' => -1, 'field_b' => 1]);
163165
});
164166

165-
$this->assertIndexNotExists('newcollection', $indexName);
167+
$this->assertIndexNotExists(self::COLL_1, $indexName);
166168

167169
$indexName = 'custom_index_name';
168-
Schema::table('newcollection', function ($collection) use ($indexName) {
170+
Schema::table(self::COLL_1, function ($collection) use ($indexName) {
169171
$collection->index(['field_a', 'field_b'], $indexName);
170172
});
171173

172-
$this->assertIndexExists('newcollection', $indexName);
174+
$this->assertIndexExists(self::COLL_1, $indexName);
173175

174-
Schema::table('newcollection', function ($collection) use ($indexName) {
176+
Schema::table(self::COLL_1, function ($collection) use ($indexName) {
175177
$collection->dropIndex($indexName);
176178
});
177179

178-
$this->assertIndexNotExists('newcollection', $indexName);
180+
$this->assertIndexNotExists(self::COLL_1, $indexName);
179181
}
180182

181183
public function testDropIndexIfExists(): void
182184
{
183-
Schema::table('newcollection', function (Blueprint $collection) {
185+
Schema::table(self::COLL_1, function (Blueprint $collection) {
184186
$collection->unique('uniquekey');
185187
$collection->dropIndexIfExists('uniquekey_1');
186188
});
187189

188-
$this->assertIndexNotExists('newcollection', 'uniquekey');
190+
$this->assertIndexNotExists(self::COLL_1, 'uniquekey');
189191

190-
Schema::table('newcollection', function (Blueprint $collection) {
192+
Schema::table(self::COLL_1, function (Blueprint $collection) {
191193
$collection->unique('uniquekey');
192194
$collection->dropIndexIfExists(['uniquekey']);
193195
});
194196

195-
$this->assertIndexNotExists('newcollection', 'uniquekey');
197+
$this->assertIndexNotExists(self::COLL_1, 'uniquekey');
196198

197-
Schema::table('newcollection', function (Blueprint $collection) {
199+
Schema::table(self::COLL_1, function (Blueprint $collection) {
198200
$collection->index(['field_a', 'field_b']);
199201
});
200202

201-
$this->assertIndexExists('newcollection', 'field_a_1_field_b_1');
203+
$this->assertIndexExists(self::COLL_1, 'field_a_1_field_b_1');
202204

203-
Schema::table('newcollection', function (Blueprint $collection) {
205+
Schema::table(self::COLL_1, function (Blueprint $collection) {
204206
$collection->dropIndexIfExists(['field_a', 'field_b']);
205207
});
206208

207-
$this->assertIndexNotExists('newcollection', 'field_a_1_field_b_1');
209+
$this->assertIndexNotExists(self::COLL_1, 'field_a_1_field_b_1');
208210

209-
Schema::table('newcollection', function (Blueprint $collection) {
211+
Schema::table(self::COLL_1, function (Blueprint $collection) {
210212
$collection->index(['field_a', 'field_b'], 'custom_index_name');
211213
});
212214

213-
$this->assertIndexExists('newcollection', 'custom_index_name');
215+
$this->assertIndexExists(self::COLL_1, 'custom_index_name');
214216

215-
Schema::table('newcollection', function (Blueprint $collection) {
217+
Schema::table(self::COLL_1, function (Blueprint $collection) {
216218
$collection->dropIndexIfExists('custom_index_name');
217219
});
218220

219-
$this->assertIndexNotExists('newcollection', 'custom_index_name');
221+
$this->assertIndexNotExists(self::COLL_1, 'custom_index_name');
220222
}
221223

222224
public function testHasIndex(): void
223225
{
224-
Schema::table('newcollection', function (Blueprint $collection) {
226+
Schema::table(self::COLL_1, function (Blueprint $collection) {
225227
$collection->index('myhaskey1');
226228
$this->assertTrue($collection->hasIndex('myhaskey1_1'));
227229
$this->assertFalse($collection->hasIndex('myhaskey1'));
228230
});
229231

230-
Schema::table('newcollection', function (Blueprint $collection) {
232+
Schema::table(self::COLL_1, function (Blueprint $collection) {
231233
$collection->index('myhaskey2');
232234
$this->assertTrue($collection->hasIndex(['myhaskey2']));
233235
$this->assertFalse($collection->hasIndex(['myhaskey2_1']));
234236
});
235237

236-
Schema::table('newcollection', function (Blueprint $collection) {
238+
Schema::table(self::COLL_1, function (Blueprint $collection) {
237239
$collection->index(['field_a', 'field_b']);
238240
$this->assertTrue($collection->hasIndex(['field_a_1_field_b']));
239241
$this->assertFalse($collection->hasIndex(['field_a_1_field_b_1']));
@@ -242,74 +244,74 @@ public function testHasIndex(): void
242244

243245
public function testSparse(): void
244246
{
245-
Schema::table('newcollection', function ($collection) {
247+
Schema::table(self::COLL_1, function ($collection) {
246248
$collection->sparse('sparsekey');
247249
});
248250

249-
$index = $this->assertIndexExists('newcollection', 'sparsekey_1');
251+
$index = $this->assertIndexExists(self::COLL_1, 'sparsekey_1');
250252
$this->assertEquals(1, $index['sparse']);
251253
}
252254

253255
public function testExpire(): void
254256
{
255-
Schema::table('newcollection', function ($collection) {
257+
Schema::table(self::COLL_1, function ($collection) {
256258
$collection->expire('expirekey', 60);
257259
});
258260

259-
$index = $this->assertIndexExists('newcollection', 'expirekey_1');
261+
$index = $this->assertIndexExists(self::COLL_1, 'expirekey_1');
260262
$this->assertEquals(60, $index['expireAfterSeconds']);
261263
}
262264

263265
public function testSoftDeletes(): void
264266
{
265-
Schema::table('newcollection', function ($collection) {
267+
Schema::table(self::COLL_1, function ($collection) {
266268
$collection->softDeletes();
267269
});
268270

269-
Schema::table('newcollection', function ($collection) {
271+
Schema::table(self::COLL_1, function ($collection) {
270272
$collection->string('email')->nullable()->index();
271273
});
272274

273-
$index = $this->assertIndexExists('newcollection', 'email_1');
275+
$index = $this->assertIndexExists(self::COLL_1, 'email_1');
274276
$this->assertEquals(1, $index['key']['email']);
275277
}
276278

277279
public function testFluent(): void
278280
{
279-
Schema::table('newcollection', function ($collection) {
281+
Schema::table(self::COLL_1, function ($collection) {
280282
$collection->string('email')->index();
281283
$collection->string('token')->index();
282284
$collection->timestamp('created_at');
283285
});
284286

285-
$index = $this->assertIndexExists('newcollection', 'email_1');
287+
$index = $this->assertIndexExists(self::COLL_1, 'email_1');
286288
$this->assertEquals(1, $index['key']['email']);
287289

288-
$index = $this->assertIndexExists('newcollection', 'token_1');
290+
$index = $this->assertIndexExists(self::COLL_1, 'token_1');
289291
$this->assertEquals(1, $index['key']['token']);
290292
}
291293

292294
public function testGeospatial(): void
293295
{
294-
Schema::table('newcollection', function ($collection) {
296+
Schema::table(self::COLL_1, function ($collection) {
295297
$collection->geospatial('point');
296298
$collection->geospatial('area', '2d');
297299
$collection->geospatial('continent', '2dsphere');
298300
});
299301

300-
$index = $this->assertIndexExists('newcollection', 'point_2d');
302+
$index = $this->assertIndexExists(self::COLL_1, 'point_2d');
301303
$this->assertEquals('2d', $index['key']['point']);
302304

303-
$index = $this->assertIndexExists('newcollection', 'area_2d');
305+
$index = $this->assertIndexExists(self::COLL_1, 'area_2d');
304306
$this->assertEquals('2d', $index['key']['area']);
305307

306-
$index = $this->assertIndexExists('newcollection', 'continent_2dsphere');
308+
$index = $this->assertIndexExists(self::COLL_1, 'continent_2dsphere');
307309
$this->assertEquals('2dsphere', $index['key']['continent']);
308310
}
309311

310312
public function testDummies(): void
311313
{
312-
Schema::table('newcollection', function ($collection) {
314+
Schema::table(self::COLL_1, function ($collection) {
313315
$collection->boolean('activated')->default(0);
314316
$collection->integer('user_id')->unsigned();
315317
});
@@ -318,22 +320,22 @@ public function testDummies(): void
318320

319321
public function testSparseUnique(): void
320322
{
321-
Schema::table('newcollection', function ($collection) {
323+
Schema::table(self::COLL_1, function ($collection) {
322324
$collection->sparse_and_unique('sparseuniquekey');
323325
});
324326

325-
$index = $this->assertIndexExists('newcollection', 'sparseuniquekey_1');
327+
$index = $this->assertIndexExists(self::COLL_1, 'sparseuniquekey_1');
326328
$this->assertEquals(1, $index['sparse']);
327329
$this->assertEquals(1, $index['unique']);
328330
}
329331

330332
public function testRenameColumn(): void
331333
{
332-
DB::connection()->table('newcollection')->insert(['test' => 'value']);
333-
DB::connection()->table('newcollection')->insert(['test' => 'value 2']);
334-
DB::connection()->table('newcollection')->insert(['column' => 'column value']);
334+
DB::connection()->table(self::COLL_1)->insert(['test' => 'value']);
335+
DB::connection()->table(self::COLL_1)->insert(['test' => 'value 2']);
336+
DB::connection()->table(self::COLL_1)->insert(['column' => 'column value']);
335337

336-
$check = DB::connection()->table('newcollection')->get();
338+
$check = DB::connection()->table(self::COLL_1)->get();
337339
$this->assertCount(3, $check);
338340

339341
$this->assertObjectHasProperty('test', $check[0]);
@@ -346,11 +348,11 @@ public function testRenameColumn(): void
346348
$this->assertObjectNotHasProperty('test', $check[2]);
347349
$this->assertObjectNotHasProperty('newtest', $check[2]);
348350

349-
Schema::table('newcollection', function (Blueprint $collection) {
351+
Schema::table(self::COLL_1, function (Blueprint $collection) {
350352
$collection->renameColumn('test', 'newtest');
351353
});
352354

353-
$check2 = DB::connection()->table('newcollection')->get();
355+
$check2 = DB::connection()->table(self::COLL_1)->get();
354356
$this->assertCount(3, $check2);
355357

356358
$this->assertObjectHasProperty('newtest', $check2[0]);
@@ -369,30 +371,30 @@ public function testRenameColumn(): void
369371

370372
public function testHasColumn(): void
371373
{
372-
$this->assertTrue(Schema::hasColumn('newcollection', '_id'));
373-
$this->assertTrue(Schema::hasColumn('newcollection', 'id'));
374+
$this->assertTrue(Schema::hasColumn(self::COLL_1, '_id'));
375+
$this->assertTrue(Schema::hasColumn(self::COLL_1, 'id'));
374376

375-
DB::connection()->table('newcollection')->insert(['column1' => 'value', 'embed' => ['_id' => 1]]);
377+
DB::connection()->table(self::COLL_1)->insert(['column1' => 'value', 'embed' => ['_id' => 1]]);
376378

377-
$this->assertTrue(Schema::hasColumn('newcollection', 'column1'));
378-
$this->assertFalse(Schema::hasColumn('newcollection', 'column2'));
379-
$this->assertTrue(Schema::hasColumn('newcollection', 'embed._id'));
380-
$this->assertTrue(Schema::hasColumn('newcollection', 'embed.id'));
379+
$this->assertTrue(Schema::hasColumn(self::COLL_1, 'column1'));
380+
$this->assertFalse(Schema::hasColumn(self::COLL_1, 'column2'));
381+
$this->assertTrue(Schema::hasColumn(self::COLL_1, 'embed._id'));
382+
$this->assertTrue(Schema::hasColumn(self::COLL_1, 'embed.id'));
381383
}
382384

383385
public function testHasColumns(): void
384386
{
385-
$this->assertTrue(Schema::hasColumns('newcollection', ['_id']));
386-
$this->assertTrue(Schema::hasColumns('newcollection', ['id']));
387+
$this->assertTrue(Schema::hasColumns(self::COLL_1, ['_id']));
388+
$this->assertTrue(Schema::hasColumns(self::COLL_1, ['id']));
387389

388390
// Insert documents with both column1 and column2
389-
DB::connection()->table('newcollection')->insert([
391+
DB::connection()->table(self::COLL_1)->insert([
390392
['column1' => 'value1', 'column2' => 'value2'],
391393
['column1' => 'value3'],
392394
]);
393395

394-
$this->assertTrue(Schema::hasColumns('newcollection', ['column1', 'column2']));
395-
$this->assertFalse(Schema::hasColumns('newcollection', ['column1', 'column3']));
396+
$this->assertTrue(Schema::hasColumns(self::COLL_1, ['column1', 'column2']));
397+
$this->assertFalse(Schema::hasColumns(self::COLL_1, ['column1', 'column3']));
396398
}
397399

398400
public function testGetTables()
@@ -405,9 +407,9 @@ public function testGetTables()
405407
],
406408
]);
407409

408-
DB::connection('mongodb')->table('newcollection')->insert(['test' => 'value']);
409-
DB::connection('mongodb')->table('newcollection_two')->insert(['test' => 'value']);
410-
$db->createCollection('test_view', ['viewOn' => 'newcollection']);
410+
DB::connection('mongodb')->table(self::COLL_1)->insert(['test' => 'value']);
411+
DB::connection('mongodb')->table(self::COLL_2)->insert(['test' => 'value']);
412+
$db->createCollection('test_view', ['viewOn' => self::COLL_1]);
411413
$dbName = DB::connection('mongodb')->getDatabaseName();
412414

413415
$tables = Schema::getTables();
@@ -422,10 +424,10 @@ public function testGetTables()
422424
$this->assertArrayHasKey('schema_qualified_name', $table);
423425
$this->assertNotEquals('test_view', $table['name'], 'Standard views should not be included in the result of getTables.');
424426

425-
if ($table['name'] === 'newcollection') {
427+
if ($table['name'] === self::COLL_1) {
426428
$this->assertEquals(8192, $table['size']);
427429
$this->assertEquals($dbName, $table['schema']);
428-
$this->assertEquals($dbName . '.newcollection', $table['schema_qualified_name']);
430+
$this->assertEquals($dbName . '.' . self::COLL_1, $table['schema_qualified_name']);
429431
$found = true;
430432
}
431433

@@ -435,17 +437,17 @@ public function testGetTables()
435437
}
436438

437439
if (! $found) {
438-
$this->fail('Collection "newcollection" not found');
440+
$this->fail('Collection "' . self::COLL_1 . '" not found');
439441
}
440442
}
441443

442444
public function testGetViews()
443445
{
444-
DB::connection('mongodb')->table('newcollection')->insert(['test' => 'value']);
445-
DB::connection('mongodb')->table('newcollection_two')->insert(['test' => 'value']);
446+
DB::connection('mongodb')->table(self::COLL_1)->insert(['test' => 'value']);
447+
DB::connection('mongodb')->table(self::COLL_2)->insert(['test' => 'value']);
446448
$dbName = DB::connection('mongodb')->getDatabaseName();
447449

448-
DB::connection('mongodb')->getDatabase()->createCollection('test_view', ['viewOn' => 'newcollection']);
450+
DB::connection('mongodb')->getDatabase()->createCollection('test_view', ['viewOn' => self::COLL_1]);
449451

450452
$tables = Schema::getViews();
451453

@@ -459,7 +461,7 @@ public function testGetViews()
459461
$this->assertArrayHasKey('schema_qualified_name', $table);
460462

461463
// Ensure "normal collections" are not in the views list
462-
$this->assertNotEquals('newcollection', $table['name'], 'Normal collections should not be included in the result of getViews.');
464+
$this->assertNotEquals(self::COLL_1, $table['name'], 'Normal collections should not be included in the result of getViews.');
463465

464466
if ($table['name'] === 'test_view') {
465467
$this->assertEquals($dbName, $table['schema']);
@@ -475,45 +477,45 @@ public function testGetViews()
475477

476478
public function testGetTableListing()
477479
{
478-
DB::connection('mongodb')->table('newcollection')->insert(['test' => 'value']);
479-
DB::connection('mongodb')->table('newcollection_two')->insert(['test' => 'value']);
480+
DB::connection('mongodb')->table(self::COLL_1)->insert(['test' => 'value']);
481+
DB::connection('mongodb')->table(self::COLL_2)->insert(['test' => 'value']);
480482

481483
$tables = Schema::getTableListing();
482484

483485
$this->assertIsArray($tables);
484486
$this->assertGreaterThanOrEqual(2, count($tables));
485-
$this->assertContains('newcollection', $tables);
486-
$this->assertContains('newcollection_two', $tables);
487+
$this->assertContains(self::COLL_1, $tables);
488+
$this->assertContains(self::COLL_2, $tables);
487489
}
488490

489491
public function testGetTableListingBySchema()
490492
{
491-
DB::connection('mongodb')->table('newcollection')->insert(['test' => 'value']);
492-
DB::connection('mongodb')->table('newcollection_two')->insert(['test' => 'value']);
493+
DB::connection('mongodb')->table(self::COLL_1)->insert(['test' => 'value']);
494+
DB::connection('mongodb')->table(self::COLL_2)->insert(['test' => 'value']);
493495
$dbName = DB::connection('mongodb')->getDatabaseName();
494496

495497
$tables = Schema::getTableListing([$dbName, 'database__that_does_not_exists'], schemaQualified: true);
496498

497499
$this->assertIsArray($tables);
498500
$this->assertGreaterThanOrEqual(2, count($tables));
499-
$this->assertContains($dbName . '.newcollection', $tables);
500-
$this->assertContains($dbName . '.newcollection_two', $tables);
501+
$this->assertContains($dbName . '.' . self::COLL_1, $tables);
502+
$this->assertContains($dbName . '.' . self::COLL_2, $tables);
501503

502504
$tables = Schema::getTableListing([$dbName, 'database__that_does_not_exists'], schemaQualified: false);
503505

504506
$this->assertIsArray($tables);
505507
$this->assertGreaterThanOrEqual(2, count($tables));
506-
$this->assertContains('newcollection', $tables);
507-
$this->assertContains('newcollection_two', $tables);
508+
$this->assertContains(self::COLL_1, $tables);
509+
$this->assertContains(self::COLL_2, $tables);
508510
}
509511

510512
public function testGetColumns()
511513
{
512-
$collection = DB::connection('mongodb')->table('newcollection');
514+
$collection = DB::connection('mongodb')->table(self::COLL_1);
513515
$collection->insert(['text' => 'value', 'mixed' => ['key' => 'value']]);
514516
$collection->insert(['date' => new UTCDateTime(), 'binary' => new Binary('binary'), 'mixed' => true]);
515517

516-
$columns = Schema::getColumns('newcollection');
518+
$columns = Schema::getColumns(self::COLL_1);
517519
$this->assertIsArray($columns);
518520
$this->assertCount(5, $columns);
519521

@@ -544,20 +546,20 @@ public function testGetColumns()
544546
$this->assertSame([], $columns);
545547

546548
// Qualified table name
547-
$columns = Schema::getColumns(DB::getDatabaseName() . '.newcollection');
549+
$columns = Schema::getColumns(DB::getDatabaseName() . '.' . self::COLL_1);
548550
$this->assertIsArray($columns);
549551
$this->assertCount(5, $columns);
550552
}
551553

552554
/** @see AtlasSearchTest::testGetIndexes() */
553555
public function testGetIndexes()
554556
{
555-
Schema::create('newcollection', function (Blueprint $collection) {
557+
Schema::create(self::COLL_1, function (Blueprint $collection) {
556558
$collection->index('mykey1');
557559
$collection->string('mykey2')->unique('unique_index');
558560
$collection->string('mykey3')->index();
559561
});
560-
$indexes = Schema::getIndexes('newcollection');
562+
$indexes = Schema::getIndexes(self::COLL_1);
561563
self::assertIsArray($indexes);
562564
self::assertCount(4, $indexes);
563565

@@ -603,7 +605,7 @@ public function testSearchIndex(): void
603605
{
604606
$this->skipIfSearchIndexManagementIsNotSupported();
605607

606-
Schema::create('newcollection', function (Blueprint $collection) {
608+
Schema::create(self::COLL_1, function (Blueprint $collection) {
607609
$collection->searchIndex([
608610
'mappings' => [
609611
'dynamic' => false,
@@ -614,47 +616,47 @@ public function testSearchIndex(): void
614616
]);
615617
});
616618

617-
$index = $this->getSearchIndex('newcollection', 'default');
619+
$index = $this->getSearchIndex(self::COLL_1, 'default');
618620
self::assertNotNull($index);
619621

620622
self::assertSame('default', $index['name']);
621623
self::assertSame('search', $index['type']);
622624
self::assertFalse($index['latestDefinition']['mappings']['dynamic']);
623625
self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']);
624626

625-
Schema::table('newcollection', function (Blueprint $collection) {
627+
Schema::table(self::COLL_1, function (Blueprint $collection) {
626628
$collection->dropSearchIndex('default');
627629
});
628630

629-
$index = $this->getSearchIndex('newcollection', 'default');
631+
$index = $this->getSearchIndex(self::COLL_1, 'default');
630632
self::assertNull($index);
631633
}
632634

633635
public function testVectorSearchIndex()
634636
{
635637
$this->skipIfSearchIndexManagementIsNotSupported();
636638

637-
Schema::create('newcollection', function (Blueprint $collection) {
639+
Schema::create(self::COLL_1, function (Blueprint $collection) {
638640
$collection->vectorSearchIndex([
639641
'fields' => [
640642
['type' => 'vector', 'path' => 'foo', 'numDimensions' => 128, 'similarity' => 'euclidean', 'quantization' => 'none'],
641643
],
642644
], 'vector');
643645
});
644646

645-
$index = $this->getSearchIndex('newcollection', 'vector');
647+
$index = $this->getSearchIndex(self::COLL_1, 'vector');
646648
self::assertNotNull($index);
647649

648650
self::assertSame('vector', $index['name']);
649651
self::assertSame('vectorSearch', $index['type']);
650652
self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']);
651653

652654
// Drop the index
653-
Schema::table('newcollection', function (Blueprint $collection) {
655+
Schema::table(self::COLL_1, function (Blueprint $collection) {
654656
$collection->dropSearchIndex('vector');
655657
});
656658

657-
$index = $this->getSearchIndex('newcollection', 'vector');
659+
$index = $this->getSearchIndex(self::COLL_1, 'vector');
658660
self::assertNull($index);
659661
}
660662

0 commit comments

Comments
 (0)
Please sign in to comment.