@@ -19,6 +19,9 @@ public function tearDown(): void
19
19
{
20
20
Schema::drop ('newcollection ' );
21
21
Schema::drop ('newcollection_two ' );
22
+ // View type
23
+ Schema::drop ('test_view ' );
24
+
22
25
}
23
26
24
27
public function testCreate (): void
@@ -397,6 +400,13 @@ public function testGetTables()
397
400
DB ::connection ('mongodb ' )->table ('newcollection ' )->insert (['test ' => 'value ' ]);
398
401
DB ::connection ('mongodb ' )->table ('newcollection_two ' )->insert (['test ' => 'value ' ]);
399
402
403
+ // Create a view (this creates system.views)
404
+ DB ::connection ('mongodb ' )->getDatabase ()->command ([
405
+ 'create ' => 'test_view ' ,
406
+ 'viewOn ' => 'newcollection ' ,
407
+ 'pipeline ' => []
408
+ ]);
409
+
400
410
$ tables = Schema::getTables ();
401
411
$ this ->assertIsArray ($ tables );
402
412
$ this ->assertGreaterThanOrEqual (2 , count ($ tables ));
@@ -409,6 +419,8 @@ public function testGetTables()
409
419
$ this ->assertEquals (8192 , $ table ['size ' ]);
410
420
$ found = true ;
411
421
}
422
+ // Ensure system collections are excluded
423
+ $ this ->assertFalse (str_starts_with ($ table ['name ' ], 'system. ' ));
412
424
}
413
425
414
426
if (! $ found ) {
@@ -421,12 +433,74 @@ public function testGetTableListing()
421
433
DB ::connection ('mongodb ' )->table ('newcollection ' )->insert (['test ' => 'value ' ]);
422
434
DB ::connection ('mongodb ' )->table ('newcollection_two ' )->insert (['test ' => 'value ' ]);
423
435
436
+ // Create a view (this creates system.views)
437
+ DB ::connection ('mongodb ' )->getDatabase ()->command ([
438
+ 'create ' => 'test_view ' ,
439
+ 'viewOn ' => 'newcollection ' ,
440
+ 'pipeline ' => []
441
+ ]);
442
+
424
443
$ tables = Schema::getTableListing ();
425
444
426
445
$ this ->assertIsArray ($ tables );
427
446
$ this ->assertGreaterThanOrEqual (2 , count ($ tables ));
428
447
$ this ->assertContains ('newcollection ' , $ tables );
429
448
$ this ->assertContains ('newcollection_two ' , $ tables );
449
+
450
+ // Ensure system collections are excluded
451
+ $ this ->assertNotContains ('system.views ' , $ tables );
452
+ }
453
+ public function testGetAllCollections ()
454
+ {
455
+
456
+ DB ::connection ('mongodb ' )->table ('newcollection ' )->insert (['test ' => 'value ' ]);
457
+ DB ::connection ('mongodb ' )->table ('newcollection_two ' )->insert (['test ' => 'value ' ]);
458
+
459
+ // Create a view (this creates system.views)
460
+ DB ::connection ('mongodb ' )->getDatabase ()->command ([
461
+ 'create ' => 'test_view ' ,
462
+ 'viewOn ' => 'newcollection ' ,
463
+ 'pipeline ' => []
464
+ ]);
465
+
466
+ $ collections = Schema::getAllCollections ();
467
+
468
+ $ this ->assertIsArray ($ collections );
469
+ $ this ->assertGreaterThanOrEqual (2 , count ($ collections ));
470
+
471
+
472
+ $ this ->assertContains ('newcollection ' , $ collections );
473
+ $ this ->assertContains ('newcollection_two ' , $ collections );
474
+
475
+ // Ensure system collections are excluded
476
+ $ this ->assertNotContains ('system.views ' , $ collections );
477
+ }
478
+
479
+ public function testSystemCollectionsArePresentButFiltered ()
480
+ {
481
+
482
+ // Create a view to trigger system.views collection
483
+ DB ::connection ('mongodb ' )->getDatabase ()->command ([
484
+ 'create ' => 'test_view ' ,
485
+ 'viewOn ' => 'newcollection ' ,
486
+ 'pipeline ' => []
487
+ ]);
488
+
489
+ // Get all collections directly from MongoDB
490
+ $ allCollections = $ db ->getDatabase ()->listCollectionNames ();
491
+
492
+ // Ensure the system.views collection exists in MongoDB
493
+ $ this ->assertContains ('system.views ' , $ allCollections );
494
+
495
+ // Ensure Schema::getTables does NOT include system collections
496
+ $ tables = Schema::getTables ();
497
+ foreach ($ tables as $ table ) {
498
+ $ this ->assertFalse (str_starts_with ($ table ['name ' ], 'system. ' ));
499
+ }
500
+
501
+ // Ensure Schema::getTableListing does NOT include system collections
502
+ $ tableListing = Schema::getTableListing ();
503
+ $ this ->assertNotContains ('system.views ' , $ tableListing );
430
504
}
431
505
432
506
public function testGetColumns ()
0 commit comments