@@ -19,6 +19,9 @@ public function tearDown(): void
1919 {
2020 Schema::drop ('newcollection ' );
2121 Schema::drop ('newcollection_two ' );
22+ // View type
23+ Schema::drop ('test_view ' );
24+
2225 }
2326
2427 public function testCreate (): void
@@ -397,6 +400,13 @@ public function testGetTables()
397400 DB ::connection ('mongodb ' )->table ('newcollection ' )->insert (['test ' => 'value ' ]);
398401 DB ::connection ('mongodb ' )->table ('newcollection_two ' )->insert (['test ' => 'value ' ]);
399402
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+
400410 $ tables = Schema::getTables ();
401411 $ this ->assertIsArray ($ tables );
402412 $ this ->assertGreaterThanOrEqual (2 , count ($ tables ));
@@ -409,6 +419,8 @@ public function testGetTables()
409419 $ this ->assertEquals (8192 , $ table ['size ' ]);
410420 $ found = true ;
411421 }
422+ // Ensure system collections are excluded
423+ $ this ->assertFalse (str_starts_with ($ table ['name ' ], 'system. ' ));
412424 }
413425
414426 if (! $ found ) {
@@ -421,12 +433,74 @@ public function testGetTableListing()
421433 DB ::connection ('mongodb ' )->table ('newcollection ' )->insert (['test ' => 'value ' ]);
422434 DB ::connection ('mongodb ' )->table ('newcollection_two ' )->insert (['test ' => 'value ' ]);
423435
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+
424443 $ tables = Schema::getTableListing ();
425444
426445 $ this ->assertIsArray ($ tables );
427446 $ this ->assertGreaterThanOrEqual (2 , count ($ tables ));
428447 $ this ->assertContains ('newcollection ' , $ tables );
429448 $ 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 );
430504 }
431505
432506 public function testGetColumns ()
0 commit comments