20
20
21
21
class SchemaTest extends TestCase
22
22
{
23
+ private const COLL_1 = 'new_collection ' ;
24
+ private const COLL_2 = 'new_collection_two ' ;
23
25
private const COLL_WITH_COLLATION = 'collection_with_collation ' ;
24
26
25
27
public function tearDown (): void
26
28
{
27
29
$ database = $ this ->getConnection ('mongodb ' )->getDatabase ();
28
30
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 );
31
33
$ database ->dropCollection (self ::COLL_WITH_COLLATION );
32
34
$ database ->dropCollection ('test_view ' );
33
35
@@ -36,204 +38,204 @@ public function tearDown(): void
36
38
37
39
public function testCreate (): void
38
40
{
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 ));
42
44
}
43
45
44
46
public function testCreateWithCallback (): void
45
47
{
46
- Schema::create (' newcollection ' , static function ($ collection ) {
48
+ Schema::create (self :: COLL_1 , static function ($ collection ) {
47
49
self ::assertInstanceOf (Blueprint::class, $ collection );
48
50
});
49
51
50
- $ this ->assertTrue (Schema::hasCollection (' newcollection ' ));
52
+ $ this ->assertTrue (Schema::hasCollection (self :: COLL_1 ));
51
53
}
52
54
53
55
public function testCreateWithOptions (): void
54
56
{
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 ));
58
60
59
- $ collection = Schema::getCollection (' newcollection_two ' );
61
+ $ collection = Schema::getCollection (self :: COLL_2 );
60
62
$ this ->assertTrue ($ collection ['options ' ]['capped ' ]);
61
63
$ this ->assertEquals (1024 , $ collection ['options ' ]['size ' ]);
62
64
}
63
65
64
66
public function testDrop (): void
65
67
{
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 ));
69
71
}
70
72
71
73
public function testBluePrint (): void
72
74
{
73
- Schema::table (' newcollection ' , static function ($ collection ) {
75
+ Schema::table (self :: COLL_1 , static function ($ collection ) {
74
76
self ::assertInstanceOf (Blueprint::class, $ collection );
75
77
});
76
78
77
- Schema::table (' newcollection ' , static function ($ collection ) {
79
+ Schema::table (self :: COLL_1 , static function ($ collection ) {
78
80
self ::assertInstanceOf (Blueprint::class, $ collection );
79
81
});
80
82
}
81
83
82
84
public function testIndex (): void
83
85
{
84
- Schema::table (' newcollection ' , function ($ collection ) {
86
+ Schema::table (self :: COLL_1 , function ($ collection ) {
85
87
$ collection ->index ('mykey1 ' );
86
88
});
87
89
88
- $ index = $ this ->assertIndexExists (' newcollection ' , 'mykey1_1 ' );
90
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'mykey1_1 ' );
89
91
$ this ->assertEquals (1 , $ index ['key ' ]['mykey1 ' ]);
90
92
91
- Schema::table (' newcollection ' , function ($ collection ) {
93
+ Schema::table (self :: COLL_1 , function ($ collection ) {
92
94
$ collection ->index (['mykey2 ' ]);
93
95
});
94
96
95
- $ index = $ this ->assertIndexExists (' newcollection ' , 'mykey2_1 ' );
97
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'mykey2_1 ' );
96
98
$ this ->assertEquals (1 , $ index ['key ' ]['mykey2 ' ]);
97
99
98
- Schema::table (' newcollection ' , function ($ collection ) {
100
+ Schema::table (self :: COLL_1 , function ($ collection ) {
99
101
$ collection ->string ('mykey3 ' )->index ();
100
102
});
101
103
102
- $ index = $ this ->assertIndexExists (' newcollection ' , 'mykey3_1 ' );
104
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'mykey3_1 ' );
103
105
$ this ->assertEquals (1 , $ index ['key ' ]['mykey3 ' ]);
104
106
}
105
107
106
108
public function testPrimary (): void
107
109
{
108
- Schema::table (' newcollection ' , function ($ collection ) {
110
+ Schema::table (self :: COLL_1 , function ($ collection ) {
109
111
$ collection ->string ('mykey ' , 100 )->primary ();
110
112
});
111
113
112
- $ index = $ this ->assertIndexExists (' newcollection ' , 'mykey_1 ' );
114
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'mykey_1 ' );
113
115
$ this ->assertEquals (1 , $ index ['unique ' ]);
114
116
}
115
117
116
118
public function testUnique (): void
117
119
{
118
- Schema::table (' newcollection ' , function ($ collection ) {
120
+ Schema::table (self :: COLL_1 , function ($ collection ) {
119
121
$ collection ->unique ('uniquekey ' );
120
122
});
121
123
122
- $ index = $ this ->assertIndexExists (' newcollection ' , 'uniquekey_1 ' );
124
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'uniquekey_1 ' );
123
125
$ this ->assertEquals (1 , $ index ['unique ' ]);
124
126
}
125
127
126
128
public function testDropIndex (): void
127
129
{
128
- Schema::table (' newcollection ' , function ($ collection ) {
130
+ Schema::table (self :: COLL_1 , function ($ collection ) {
129
131
$ collection ->unique ('uniquekey ' );
130
132
$ collection ->dropIndex ('uniquekey_1 ' );
131
133
});
132
134
133
- $ this ->assertIndexNotExists (' newcollection ' , 'uniquekey_1 ' );
135
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'uniquekey_1 ' );
134
136
135
- Schema::table (' newcollection ' , function ($ collection ) {
137
+ Schema::table (self :: COLL_1 , function ($ collection ) {
136
138
$ collection ->unique ('uniquekey ' );
137
139
$ collection ->dropIndex (['uniquekey ' ]);
138
140
});
139
141
140
- $ this ->assertIndexNotExists (' newcollection ' , 'uniquekey_1 ' );
142
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'uniquekey_1 ' );
141
143
142
- Schema::table (' newcollection ' , function ($ collection ) {
144
+ Schema::table (self :: COLL_1 , function ($ collection ) {
143
145
$ collection ->index (['field_a ' , 'field_b ' ]);
144
146
});
145
147
146
- $ this ->assertIndexExists (' newcollection ' , 'field_a_1_field_b_1 ' );
148
+ $ this ->assertIndexExists (self :: COLL_1 , 'field_a_1_field_b_1 ' );
147
149
148
- Schema::table (' newcollection ' , function ($ collection ) {
150
+ Schema::table (self :: COLL_1 , function ($ collection ) {
149
151
$ collection ->dropIndex (['field_a ' , 'field_b ' ]);
150
152
});
151
153
152
- $ this ->assertIndexNotExists (' newcollection ' , 'field_a_1_field_b_1 ' );
154
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'field_a_1_field_b_1 ' );
153
155
154
156
$ indexName = 'field_a_-1_field_b_1 ' ;
155
- Schema::table (' newcollection ' , function ($ collection ) {
157
+ Schema::table (self :: COLL_1 , function ($ collection ) {
156
158
$ collection ->index (['field_a ' => -1 , 'field_b ' => 1 ]);
157
159
});
158
160
159
- $ this ->assertIndexExists (' newcollection ' , $ indexName );
161
+ $ this ->assertIndexExists (self :: COLL_1 , $ indexName );
160
162
161
- Schema::table (' newcollection ' , function ($ collection ) {
163
+ Schema::table (self :: COLL_1 , function ($ collection ) {
162
164
$ collection ->dropIndex (['field_a ' => -1 , 'field_b ' => 1 ]);
163
165
});
164
166
165
- $ this ->assertIndexNotExists (' newcollection ' , $ indexName );
167
+ $ this ->assertIndexNotExists (self :: COLL_1 , $ indexName );
166
168
167
169
$ indexName = 'custom_index_name ' ;
168
- Schema::table (' newcollection ' , function ($ collection ) use ($ indexName ) {
170
+ Schema::table (self :: COLL_1 , function ($ collection ) use ($ indexName ) {
169
171
$ collection ->index (['field_a ' , 'field_b ' ], $ indexName );
170
172
});
171
173
172
- $ this ->assertIndexExists (' newcollection ' , $ indexName );
174
+ $ this ->assertIndexExists (self :: COLL_1 , $ indexName );
173
175
174
- Schema::table (' newcollection ' , function ($ collection ) use ($ indexName ) {
176
+ Schema::table (self :: COLL_1 , function ($ collection ) use ($ indexName ) {
175
177
$ collection ->dropIndex ($ indexName );
176
178
});
177
179
178
- $ this ->assertIndexNotExists (' newcollection ' , $ indexName );
180
+ $ this ->assertIndexNotExists (self :: COLL_1 , $ indexName );
179
181
}
180
182
181
183
public function testDropIndexIfExists (): void
182
184
{
183
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
185
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
184
186
$ collection ->unique ('uniquekey ' );
185
187
$ collection ->dropIndexIfExists ('uniquekey_1 ' );
186
188
});
187
189
188
- $ this ->assertIndexNotExists (' newcollection ' , 'uniquekey ' );
190
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'uniquekey ' );
189
191
190
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
192
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
191
193
$ collection ->unique ('uniquekey ' );
192
194
$ collection ->dropIndexIfExists (['uniquekey ' ]);
193
195
});
194
196
195
- $ this ->assertIndexNotExists (' newcollection ' , 'uniquekey ' );
197
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'uniquekey ' );
196
198
197
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
199
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
198
200
$ collection ->index (['field_a ' , 'field_b ' ]);
199
201
});
200
202
201
- $ this ->assertIndexExists (' newcollection ' , 'field_a_1_field_b_1 ' );
203
+ $ this ->assertIndexExists (self :: COLL_1 , 'field_a_1_field_b_1 ' );
202
204
203
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
205
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
204
206
$ collection ->dropIndexIfExists (['field_a ' , 'field_b ' ]);
205
207
});
206
208
207
- $ this ->assertIndexNotExists (' newcollection ' , 'field_a_1_field_b_1 ' );
209
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'field_a_1_field_b_1 ' );
208
210
209
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
211
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
210
212
$ collection ->index (['field_a ' , 'field_b ' ], 'custom_index_name ' );
211
213
});
212
214
213
- $ this ->assertIndexExists (' newcollection ' , 'custom_index_name ' );
215
+ $ this ->assertIndexExists (self :: COLL_1 , 'custom_index_name ' );
214
216
215
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
217
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
216
218
$ collection ->dropIndexIfExists ('custom_index_name ' );
217
219
});
218
220
219
- $ this ->assertIndexNotExists (' newcollection ' , 'custom_index_name ' );
221
+ $ this ->assertIndexNotExists (self :: COLL_1 , 'custom_index_name ' );
220
222
}
221
223
222
224
public function testHasIndex (): void
223
225
{
224
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
226
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
225
227
$ collection ->index ('myhaskey1 ' );
226
228
$ this ->assertTrue ($ collection ->hasIndex ('myhaskey1_1 ' ));
227
229
$ this ->assertFalse ($ collection ->hasIndex ('myhaskey1 ' ));
228
230
});
229
231
230
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
232
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
231
233
$ collection ->index ('myhaskey2 ' );
232
234
$ this ->assertTrue ($ collection ->hasIndex (['myhaskey2 ' ]));
233
235
$ this ->assertFalse ($ collection ->hasIndex (['myhaskey2_1 ' ]));
234
236
});
235
237
236
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
238
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
237
239
$ collection ->index (['field_a ' , 'field_b ' ]);
238
240
$ this ->assertTrue ($ collection ->hasIndex (['field_a_1_field_b ' ]));
239
241
$ this ->assertFalse ($ collection ->hasIndex (['field_a_1_field_b_1 ' ]));
@@ -242,74 +244,74 @@ public function testHasIndex(): void
242
244
243
245
public function testSparse (): void
244
246
{
245
- Schema::table (' newcollection ' , function ($ collection ) {
247
+ Schema::table (self :: COLL_1 , function ($ collection ) {
246
248
$ collection ->sparse ('sparsekey ' );
247
249
});
248
250
249
- $ index = $ this ->assertIndexExists (' newcollection ' , 'sparsekey_1 ' );
251
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'sparsekey_1 ' );
250
252
$ this ->assertEquals (1 , $ index ['sparse ' ]);
251
253
}
252
254
253
255
public function testExpire (): void
254
256
{
255
- Schema::table (' newcollection ' , function ($ collection ) {
257
+ Schema::table (self :: COLL_1 , function ($ collection ) {
256
258
$ collection ->expire ('expirekey ' , 60 );
257
259
});
258
260
259
- $ index = $ this ->assertIndexExists (' newcollection ' , 'expirekey_1 ' );
261
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'expirekey_1 ' );
260
262
$ this ->assertEquals (60 , $ index ['expireAfterSeconds ' ]);
261
263
}
262
264
263
265
public function testSoftDeletes (): void
264
266
{
265
- Schema::table (' newcollection ' , function ($ collection ) {
267
+ Schema::table (self :: COLL_1 , function ($ collection ) {
266
268
$ collection ->softDeletes ();
267
269
});
268
270
269
- Schema::table (' newcollection ' , function ($ collection ) {
271
+ Schema::table (self :: COLL_1 , function ($ collection ) {
270
272
$ collection ->string ('email ' )->nullable ()->index ();
271
273
});
272
274
273
- $ index = $ this ->assertIndexExists (' newcollection ' , 'email_1 ' );
275
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'email_1 ' );
274
276
$ this ->assertEquals (1 , $ index ['key ' ]['email ' ]);
275
277
}
276
278
277
279
public function testFluent (): void
278
280
{
279
- Schema::table (' newcollection ' , function ($ collection ) {
281
+ Schema::table (self :: COLL_1 , function ($ collection ) {
280
282
$ collection ->string ('email ' )->index ();
281
283
$ collection ->string ('token ' )->index ();
282
284
$ collection ->timestamp ('created_at ' );
283
285
});
284
286
285
- $ index = $ this ->assertIndexExists (' newcollection ' , 'email_1 ' );
287
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'email_1 ' );
286
288
$ this ->assertEquals (1 , $ index ['key ' ]['email ' ]);
287
289
288
- $ index = $ this ->assertIndexExists (' newcollection ' , 'token_1 ' );
290
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'token_1 ' );
289
291
$ this ->assertEquals (1 , $ index ['key ' ]['token ' ]);
290
292
}
291
293
292
294
public function testGeospatial (): void
293
295
{
294
- Schema::table (' newcollection ' , function ($ collection ) {
296
+ Schema::table (self :: COLL_1 , function ($ collection ) {
295
297
$ collection ->geospatial ('point ' );
296
298
$ collection ->geospatial ('area ' , '2d ' );
297
299
$ collection ->geospatial ('continent ' , '2dsphere ' );
298
300
});
299
301
300
- $ index = $ this ->assertIndexExists (' newcollection ' , 'point_2d ' );
302
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'point_2d ' );
301
303
$ this ->assertEquals ('2d ' , $ index ['key ' ]['point ' ]);
302
304
303
- $ index = $ this ->assertIndexExists (' newcollection ' , 'area_2d ' );
305
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'area_2d ' );
304
306
$ this ->assertEquals ('2d ' , $ index ['key ' ]['area ' ]);
305
307
306
- $ index = $ this ->assertIndexExists (' newcollection ' , 'continent_2dsphere ' );
308
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'continent_2dsphere ' );
307
309
$ this ->assertEquals ('2dsphere ' , $ index ['key ' ]['continent ' ]);
308
310
}
309
311
310
312
public function testDummies (): void
311
313
{
312
- Schema::table (' newcollection ' , function ($ collection ) {
314
+ Schema::table (self :: COLL_1 , function ($ collection ) {
313
315
$ collection ->boolean ('activated ' )->default (0 );
314
316
$ collection ->integer ('user_id ' )->unsigned ();
315
317
});
@@ -318,22 +320,22 @@ public function testDummies(): void
318
320
319
321
public function testSparseUnique (): void
320
322
{
321
- Schema::table (' newcollection ' , function ($ collection ) {
323
+ Schema::table (self :: COLL_1 , function ($ collection ) {
322
324
$ collection ->sparse_and_unique ('sparseuniquekey ' );
323
325
});
324
326
325
- $ index = $ this ->assertIndexExists (' newcollection ' , 'sparseuniquekey_1 ' );
327
+ $ index = $ this ->assertIndexExists (self :: COLL_1 , 'sparseuniquekey_1 ' );
326
328
$ this ->assertEquals (1 , $ index ['sparse ' ]);
327
329
$ this ->assertEquals (1 , $ index ['unique ' ]);
328
330
}
329
331
330
332
public function testRenameColumn (): void
331
333
{
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 ' ]);
335
337
336
- $ check = DB ::connection ()->table (' newcollection ' )->get ();
338
+ $ check = DB ::connection ()->table (self :: COLL_1 )->get ();
337
339
$ this ->assertCount (3 , $ check );
338
340
339
341
$ this ->assertObjectHasProperty ('test ' , $ check [0 ]);
@@ -346,11 +348,11 @@ public function testRenameColumn(): void
346
348
$ this ->assertObjectNotHasProperty ('test ' , $ check [2 ]);
347
349
$ this ->assertObjectNotHasProperty ('newtest ' , $ check [2 ]);
348
350
349
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
351
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
350
352
$ collection ->renameColumn ('test ' , 'newtest ' );
351
353
});
352
354
353
- $ check2 = DB ::connection ()->table (' newcollection ' )->get ();
355
+ $ check2 = DB ::connection ()->table (self :: COLL_1 )->get ();
354
356
$ this ->assertCount (3 , $ check2 );
355
357
356
358
$ this ->assertObjectHasProperty ('newtest ' , $ check2 [0 ]);
@@ -369,30 +371,30 @@ public function testRenameColumn(): void
369
371
370
372
public function testHasColumn (): void
371
373
{
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 ' ));
374
376
375
- DB ::connection ()->table (' newcollection ' )->insert (['column1 ' => 'value ' , 'embed ' => ['_id ' => 1 ]]);
377
+ DB ::connection ()->table (self :: COLL_1 )->insert (['column1 ' => 'value ' , 'embed ' => ['_id ' => 1 ]]);
376
378
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 ' ));
381
383
}
382
384
383
385
public function testHasColumns (): void
384
386
{
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 ' ]));
387
389
388
390
// Insert documents with both column1 and column2
389
- DB ::connection ()->table (' newcollection ' )->insert ([
391
+ DB ::connection ()->table (self :: COLL_1 )->insert ([
390
392
['column1 ' => 'value1 ' , 'column2 ' => 'value2 ' ],
391
393
['column1 ' => 'value3 ' ],
392
394
]);
393
395
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 ' ]));
396
398
}
397
399
398
400
public function testGetTables ()
@@ -405,9 +407,9 @@ public function testGetTables()
405
407
],
406
408
]);
407
409
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 ]);
411
413
$ dbName = DB ::connection ('mongodb ' )->getDatabaseName ();
412
414
413
415
$ tables = Schema::getTables ();
@@ -422,10 +424,10 @@ public function testGetTables()
422
424
$ this ->assertArrayHasKey ('schema_qualified_name ' , $ table );
423
425
$ this ->assertNotEquals ('test_view ' , $ table ['name ' ], 'Standard views should not be included in the result of getTables. ' );
424
426
425
- if ($ table ['name ' ] === ' newcollection ' ) {
427
+ if ($ table ['name ' ] === self :: COLL_1 ) {
426
428
$ this ->assertEquals (8192 , $ table ['size ' ]);
427
429
$ 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 ' ]);
429
431
$ found = true ;
430
432
}
431
433
@@ -435,17 +437,17 @@ public function testGetTables()
435
437
}
436
438
437
439
if (! $ found ) {
438
- $ this ->fail ('Collection "newcollection " not found ' );
440
+ $ this ->fail ('Collection " ' . self :: COLL_1 . ' " not found ' );
439
441
}
440
442
}
441
443
442
444
public function testGetViews ()
443
445
{
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 ' ]);
446
448
$ dbName = DB ::connection ('mongodb ' )->getDatabaseName ();
447
449
448
- DB ::connection ('mongodb ' )->getDatabase ()->createCollection ('test_view ' , ['viewOn ' => ' newcollection ' ]);
450
+ DB ::connection ('mongodb ' )->getDatabase ()->createCollection ('test_view ' , ['viewOn ' => self :: COLL_1 ]);
449
451
450
452
$ tables = Schema::getViews ();
451
453
@@ -459,7 +461,7 @@ public function testGetViews()
459
461
$ this ->assertArrayHasKey ('schema_qualified_name ' , $ table );
460
462
461
463
// 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. ' );
463
465
464
466
if ($ table ['name ' ] === 'test_view ' ) {
465
467
$ this ->assertEquals ($ dbName , $ table ['schema ' ]);
@@ -475,45 +477,45 @@ public function testGetViews()
475
477
476
478
public function testGetTableListing ()
477
479
{
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 ' ]);
480
482
481
483
$ tables = Schema::getTableListing ();
482
484
483
485
$ this ->assertIsArray ($ tables );
484
486
$ 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 );
487
489
}
488
490
489
491
public function testGetTableListingBySchema ()
490
492
{
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 ' ]);
493
495
$ dbName = DB ::connection ('mongodb ' )->getDatabaseName ();
494
496
495
497
$ tables = Schema::getTableListing ([$ dbName , 'database__that_does_not_exists ' ], schemaQualified: true );
496
498
497
499
$ this ->assertIsArray ($ tables );
498
500
$ 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 );
501
503
502
504
$ tables = Schema::getTableListing ([$ dbName , 'database__that_does_not_exists ' ], schemaQualified: false );
503
505
504
506
$ this ->assertIsArray ($ tables );
505
507
$ 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 );
508
510
}
509
511
510
512
public function testGetColumns ()
511
513
{
512
- $ collection = DB ::connection ('mongodb ' )->table (' newcollection ' );
514
+ $ collection = DB ::connection ('mongodb ' )->table (self :: COLL_1 );
513
515
$ collection ->insert (['text ' => 'value ' , 'mixed ' => ['key ' => 'value ' ]]);
514
516
$ collection ->insert (['date ' => new UTCDateTime (), 'binary ' => new Binary ('binary ' ), 'mixed ' => true ]);
515
517
516
- $ columns = Schema::getColumns (' newcollection ' );
518
+ $ columns = Schema::getColumns (self :: COLL_1 );
517
519
$ this ->assertIsArray ($ columns );
518
520
$ this ->assertCount (5 , $ columns );
519
521
@@ -544,20 +546,20 @@ public function testGetColumns()
544
546
$ this ->assertSame ([], $ columns );
545
547
546
548
// Qualified table name
547
- $ columns = Schema::getColumns (DB ::getDatabaseName () . '.newcollection ' );
549
+ $ columns = Schema::getColumns (DB ::getDatabaseName () . '. ' . self :: COLL_1 );
548
550
$ this ->assertIsArray ($ columns );
549
551
$ this ->assertCount (5 , $ columns );
550
552
}
551
553
552
554
/** @see AtlasSearchTest::testGetIndexes() */
553
555
public function testGetIndexes ()
554
556
{
555
- Schema::create (' newcollection ' , function (Blueprint $ collection ) {
557
+ Schema::create (self :: COLL_1 , function (Blueprint $ collection ) {
556
558
$ collection ->index ('mykey1 ' );
557
559
$ collection ->string ('mykey2 ' )->unique ('unique_index ' );
558
560
$ collection ->string ('mykey3 ' )->index ();
559
561
});
560
- $ indexes = Schema::getIndexes (' newcollection ' );
562
+ $ indexes = Schema::getIndexes (self :: COLL_1 );
561
563
self ::assertIsArray ($ indexes );
562
564
self ::assertCount (4 , $ indexes );
563
565
@@ -603,7 +605,7 @@ public function testSearchIndex(): void
603
605
{
604
606
$ this ->skipIfSearchIndexManagementIsNotSupported ();
605
607
606
- Schema::create (' newcollection ' , function (Blueprint $ collection ) {
608
+ Schema::create (self :: COLL_1 , function (Blueprint $ collection ) {
607
609
$ collection ->searchIndex ([
608
610
'mappings ' => [
609
611
'dynamic ' => false ,
@@ -614,47 +616,47 @@ public function testSearchIndex(): void
614
616
]);
615
617
});
616
618
617
- $ index = $ this ->getSearchIndex (' newcollection ' , 'default ' );
619
+ $ index = $ this ->getSearchIndex (self :: COLL_1 , 'default ' );
618
620
self ::assertNotNull ($ index );
619
621
620
622
self ::assertSame ('default ' , $ index ['name ' ]);
621
623
self ::assertSame ('search ' , $ index ['type ' ]);
622
624
self ::assertFalse ($ index ['latestDefinition ' ]['mappings ' ]['dynamic ' ]);
623
625
self ::assertSame ('lucene.whitespace ' , $ index ['latestDefinition ' ]['mappings ' ]['fields ' ]['foo ' ]['analyzer ' ]);
624
626
625
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
627
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
626
628
$ collection ->dropSearchIndex ('default ' );
627
629
});
628
630
629
- $ index = $ this ->getSearchIndex (' newcollection ' , 'default ' );
631
+ $ index = $ this ->getSearchIndex (self :: COLL_1 , 'default ' );
630
632
self ::assertNull ($ index );
631
633
}
632
634
633
635
public function testVectorSearchIndex ()
634
636
{
635
637
$ this ->skipIfSearchIndexManagementIsNotSupported ();
636
638
637
- Schema::create (' newcollection ' , function (Blueprint $ collection ) {
639
+ Schema::create (self :: COLL_1 , function (Blueprint $ collection ) {
638
640
$ collection ->vectorSearchIndex ([
639
641
'fields ' => [
640
642
['type ' => 'vector ' , 'path ' => 'foo ' , 'numDimensions ' => 128 , 'similarity ' => 'euclidean ' , 'quantization ' => 'none ' ],
641
643
],
642
644
], 'vector ' );
643
645
});
644
646
645
- $ index = $ this ->getSearchIndex (' newcollection ' , 'vector ' );
647
+ $ index = $ this ->getSearchIndex (self :: COLL_1 , 'vector ' );
646
648
self ::assertNotNull ($ index );
647
649
648
650
self ::assertSame ('vector ' , $ index ['name ' ]);
649
651
self ::assertSame ('vectorSearch ' , $ index ['type ' ]);
650
652
self ::assertSame ('vector ' , $ index ['latestDefinition ' ]['fields ' ][0 ]['type ' ]);
651
653
652
654
// Drop the index
653
- Schema::table (' newcollection ' , function (Blueprint $ collection ) {
655
+ Schema::table (self :: COLL_1 , function (Blueprint $ collection ) {
654
656
$ collection ->dropSearchIndex ('vector ' );
655
657
});
656
658
657
- $ index = $ this ->getSearchIndex (' newcollection ' , 'vector ' );
659
+ $ index = $ this ->getSearchIndex (self :: COLL_1 , 'vector ' );
658
660
self ::assertNull ($ index );
659
661
}
660
662
0 commit comments