@@ -42,18 +42,6 @@ protected function getEnvironmentSetUp($app): void
4242 $ app ['config ' ]->set ('scout.prefix ' , 'prefix_ ' );
4343 }
4444
45- public function testItCannotIndexInTheSameNamespace ()
46- {
47- self ::expectException (LogicException::class);
48- self ::expectExceptionMessage (sprintf (
49- 'The MongoDB Scout collection "%s.searchable_in_same_namespaces" must use a different collection from the collection name of the model "%s". Set the "scout.prefix" configuration or use a distinct MongoDB database ' ,
50- env ('MONGODB_DATABASE ' , 'unittest ' ),
51- SearchableInSameNamespace::class,
52- ),);
53- 54- SearchableInSameNamespace::create (['name ' => 'test ' ]);
55- }
56- 5745 public function setUp (): void
5846 {
5947 parent ::setUp ();
@@ -144,100 +132,79 @@ public function testItCanCreateTheCollection()
144132 #[Depends('testItCanCreateTheCollection ' )]
145133 public function testItCanUseBasicSearch ()
146134 {
147- $ results = ScoutUser::search ('lar ' )->take (10 )->get ();
135+ // All the search queries use "sort" option to ensure the results are deterministic
136+ $ results = ScoutUser::search ('lar ' )->take (10 )->orderBy ('id ' )->get ();
148137
149138 self ::assertSame ([
150- 42 => 'Dax Larkin ' ,
139+ 1 => 'Laravel Framework ' ,
151140 11 => 'Larry Casper ' ,
141+ 12 => 'Reta Larkin ' ,
152142 20 => 'Prof. Larry Prosacco DVM ' ,
153- 44 => 'Amos Larson Sr. ' ,
154- 43 => 'Dana Larson Sr. ' ,
155- 41 => 'Gudrun Larkin ' ,
156- 40 => 'Otis Larson MD ' ,
157143 39 => 'Linkwood Larkin ' ,
158- 12 => 'Reta Larkin ' ,
159- 1 => 'Laravel Framework ' ,
144+ 40 => 'Otis Larson MD ' ,
145+ 41 => 'Gudrun Larkin ' ,
146+ 42 => 'Dax Larkin ' ,
147+ 43 => 'Dana Larson Sr. ' ,
148+ 44 => 'Amos Larson Sr. ' ,
160149 ], $ results ->pluck ('name ' , 'id ' )->all ());
161150 }
162151
163152 #[Depends('testItCanCreateTheCollection ' )]
164153 public function testItCanUseBasicSearchWithQueryCallback ()
165154 {
166- $ results = ScoutUser::search ('lar ' )->take (10 )->query (function ($ query ) {
155+ $ results = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> query (function ($ query ) {
167156 return $ query ->whereNotNull ('email_verified_at ' );
168157 })->get ();
169158
170159 self ::assertSame ([
160+ 1 => 'Laravel Framework ' ,
161+ 12 => 'Reta Larkin ' ,
162+ 40 => 'Otis Larson MD ' ,
163+ 41 => 'Gudrun Larkin ' ,
171164 42 => 'Dax Larkin ' ,
172- 44 => 'Amos Larson Sr. ' ,
173165 43 => 'Dana Larson Sr. ' ,
174- 41 => 'Gudrun Larkin ' ,
175- 40 => 'Otis Larson MD ' ,
176- 12 => 'Reta Larkin ' ,
177- 1 => 'Laravel Framework ' ,
166+ 44 => 'Amos Larson Sr. ' ,
178167 ], $ results ->pluck ('name ' , 'id ' )->all ());
179168 }
180169
181170 #[Depends('testItCanCreateTheCollection ' )]
182171 public function testItCanUseBasicSearchToFetchKeys ()
183172 {
184- $ results = ScoutUser::search ('lar ' )->take (10 )->keys ();
173+ $ results = ScoutUser::search ('lar ' )->orderBy ( ' id ' )-> take (10 )->keys ();
185174
186- self ::assertSame ([
187- 42 ,
188- 11 ,
189- 20 ,
190- 44 ,
191- 43 ,
192- 41 ,
193- 40 ,
194- 39 ,
195- 12 ,
196- 1 ,
197- ], $ results ->all ());
175+ self ::assertSame ([1 , 11 , 12 , 20 , 39 , 40 , 41 , 42 , 43 , 44 ], $ results ->all ());
198176 }
199177
200178 #[Depends('testItCanCreateTheCollection ' )]
201179 public function testItCanUseBasicSearchWithQueryCallbackToFetchKeys ()
202180 {
203- $ results = ScoutUser::search ('lar ' )->take (10 )->query (function ($ query ) {
181+ $ results = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' , ' desc ' )-> query (function ($ query ) {
204182 return $ query ->whereNotNull ('email_verified_at ' );
205183 })->keys ();
206184
207- self ::assertSame ([
208- 42 ,
209- 11 ,
210- 20 ,
211- 44 ,
212- 43 ,
213- 41 ,
214- 40 ,
215- 39 ,
216- 12 ,
217- 1 ,
218- ], $ results ->all ());
185+ self ::assertSame ([44 , 43 , 42 , 41 , 40 , 39 , 20 , 12 , 11 , 1 ], $ results ->all ());
219186 }
220187
221188 #[Depends('testItCanCreateTheCollection ' )]
222189 public function testItCanUsePaginatedSearch ()
223190 {
224- $ page1 = ScoutUser::search ('lar ' )->take (10 )->paginate (5 , 'page ' , 1 );
225- $ page2 = ScoutUser::search ('lar ' )->take (10 )->paginate (5 , 'page ' , 2 );
191+ $ page1 = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> paginate (5 , 'page ' , 1 );
192+ $ page2 = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> paginate (5 , 'page ' , 2 );
226193
227194 self ::assertSame ([
228- 42 => 'Dax Larkin ' ,
195+ 1 => 'Laravel Framework ' ,
229196 11 => 'Larry Casper ' ,
197+ 12 => 'Reta Larkin ' ,
230198 20 => 'Prof. Larry Prosacco DVM ' ,
231- 44 => 'Amos Larson Sr. ' ,
232- 43 => 'Dana Larson Sr. ' ,
199+ 39 => 'Linkwood Larkin ' ,
233200 ], $ page1 ->pluck ('name ' , 'id ' )->all ());
234201
235202 self ::assertSame ([
236- 41 => 'Gudrun Larkin ' ,
237203 40 => 'Otis Larson MD ' ,
238- 39 => 'Linkwood Larkin ' ,
239- 12 => 'Reta Larkin ' ,
240- 1 => 'Laravel Framework ' ,
204+ 41 => 'Gudrun Larkin ' ,
205+ 42 => 'Dax Larkin ' ,
206+ 43 => 'Dana Larson Sr. ' ,
207+ 44 => 'Amos Larson Sr. ' ,
241208 ], $ page2 ->pluck ('name ' , 'id ' )->all ());
242209 }
243210
@@ -248,20 +215,32 @@ public function testItCanUsePaginatedSearchWithQueryCallback()
248215 return $ query ->whereNotNull ('email_verified_at ' );
249216 };
250217
251- $ page1 = ScoutUser::search ('lar ' )->take (10 )->query ($ queryCallback )->paginate (5 , 'page ' , 1 );
252- $ page2 = ScoutUser::search ('lar ' )->take (10 )->query ($ queryCallback )->paginate (5 , 'page ' , 2 );
218+ $ page1 = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> query ($ queryCallback )->paginate (5 , 'page ' , 1 );
219+ $ page2 = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> query ($ queryCallback )->paginate (5 , 'page ' , 2 );
253220
254221 self ::assertSame ([
255- 42 => 'Dax Larkin ' ,
256- 44 => 'Amos Larson Sr. ' ,
257- 43 => 'Dana Larson Sr. ' ,
222+ 1 => 'Laravel Framework ' ,
223+ 12 => 'Reta Larkin ' ,
258224 ], $ page1 ->pluck ('name ' , 'id ' )->all ());
259225
260226 self ::assertSame ([
261- 41 => 'Gudrun Larkin ' ,
262227 40 => 'Otis Larson MD ' ,
263- 12 => 'Reta Larkin ' ,
264- 1 => 'Laravel Framework ' ,
228+ 41 => 'Gudrun Larkin ' ,
229+ 42 => 'Dax Larkin ' ,
230+ 43 => 'Dana Larson Sr. ' ,
231+ 44 => 'Amos Larson Sr. ' ,
265232 ], $ page2 ->pluck ('name ' , 'id ' )->all ());
266233 }
234+ 235+ public function testItCannotIndexInTheSameNamespace ()
236+ {
237+ self ::expectException (LogicException::class);
238+ self ::expectExceptionMessage (sprintf (
239+ 'The MongoDB Scout collection "%s.searchable_in_same_namespaces" must use a different collection from the collection name of the model "%s". Set the "scout.prefix" configuration or use a distinct MongoDB database ' ,
240+ env ('MONGODB_DATABASE ' , 'unittest ' ),
241+ SearchableInSameNamespace::class,
242+ ),);
243+ 244+ SearchableInSameNamespace::create (['name ' => 'test ' ]);
245+ }
267246}
0 commit comments