@@ -29,12 +29,12 @@ class AtlasSearchTest extends TestCase
2929
3030 public function setUp (): void
3131 {
32- // Use a unique prefix per test to avoid collisions when the search index is
33- // deleted asynchronously while we try to create it in setup of the next test
34- $ _SERVER ['DB_PREFIX ' ] = 'AtlasSearchTest_ ' . $ this ->name () . '_ ' ;
35-
3632 parent ::setUp ();
3733
34+ $ collection = $ this ->getConnection ('mongodb ' )->getCollection ('books ' );
35+ assert ($ collection instanceof MongoDBCollection);
36+ $ collection ->drop ();
37+
3838 Book::insert ($ this ->addVector ([
3939 ['title ' => 'Introduction to Algorithms ' ],
4040 ['title ' => 'Clean Code: A Handbook of Agile Software Craftsmanship ' ],
@@ -58,10 +58,12 @@ public function setUp(): void
5858 ['title ' => 'Pattern Recognition and Machine Learning ' ],
5959 ]));
6060
61- $ collection = $ this ->getConnection ('mongodb ' )->getCollection ($ this ->getBookCollectionName ());
62- assert ($ collection instanceof MongoDBCollection);
63-
6461 try {
62+ // Waits for the search index created in the previous test to be deleted
63+ while ($ collection ->listSearchIndexes ()->count ()) {
64+ usleep (1000 );
65+ }
66+
6567 $ collection ->createSearchIndex ([
6668 'mappings ' => [
6769 'fields ' => [
@@ -96,7 +98,7 @@ public function setUp(): void
9698 // Wait for the index to be ready
9799 do {
98100 $ ready = true ;
99- usleep (100 );
101+ usleep (1000 );
100102 foreach ($ collection ->listSearchIndexes () as $ index ) {
101103 $ ready = $ ready && $ index ['queryable ' ];
102104 }
@@ -105,15 +107,14 @@ public function setUp(): void
105107
106108 public function tearDown (): void
107109 {
108- $ this ->getConnection ('mongodb ' )->getCollection ($ this ->getBookCollectionName ())->drop ();
109- unset($ _SERVER ['DB_PREFIX ' ]);
110+ $ this ->getConnection ('mongodb ' )->getCollection ('books ' )->drop ();
110111
111112 parent ::tearDown ();
112113 }
113114
114115 public function testGetIndexes ()
115116 {
116- $ indexes = Schema::getIndexes ($ this -> getBookCollectionName () );
117+ $ indexes = Schema::getIndexes (' books ' );
117118
118119 self ::assertIsArray ($ indexes );
119120 self ::assertCount (4 , $ indexes );
@@ -174,7 +175,7 @@ public function testEloquentBuilderSearch()
174175
175176 public function testDatabaseBuilderSearch ()
176177 {
177- $ results = $ this ->getConnection ('mongodb ' )->table ($ this -> getBookCollectionName () )
178+ $ results = $ this ->getConnection ('mongodb ' )->table (' books ' )
178179 ->search (Search::text ('title ' , 'systems ' ), sort: ['title ' => 1 ]);
179180
180181 self ::assertInstanceOf (LaravelCollection::class, $ results );
@@ -202,7 +203,7 @@ public function testEloquentBuilderAutocomplete()
202203
203204 public function testDatabaseBuilderAutocomplete ()
204205 {
205- $ results = $ this ->getConnection ('mongodb ' )->table ($ this -> getBookCollectionName () )
206+ $ results = $ this ->getConnection ('mongodb ' )->table (' books ' )
206207 ->autocomplete ('title ' , 'system ' );
207208
208209 self ::assertInstanceOf (LaravelCollection::class, $ results );
@@ -216,7 +217,7 @@ public function testDatabaseBuilderAutocomplete()
216217
217218 public function testDatabaseBuilderVectorSearch ()
218219 {
219- $ results = $ this ->getConnection ('mongodb ' )->table ($ this -> getBookCollectionName () )
220+ $ results = $ this ->getConnection ('mongodb ' )->table (' books ' )
220221 ->vectorSearch (
221222 index: 'vector ' ,
222223 path: 'vector4 ' ,
@@ -256,15 +257,6 @@ public function testEloquentBuilderVectorSearch()
256257 );
257258 }
258259
259- private function getBookCollectionName (): string
260- {
261- $ name = (new Book ())->getTable ();
262-
263- self ::assertStringStartsWith ('AtlasSearchTest_ ' , $ name );
264-
265- return $ name ;
266- }
267-
268260 /** Generate random vectors using fixed seed to make tests deterministic */
269261 private function addVector (array $ items ): array
270262 {
0 commit comments