@@ -42,18 +42,6 @@ protected function getEnvironmentSetUp($app): void
42
42
$ app ['config ' ]->set ('scout.prefix ' , 'prefix_ ' );
43
43
}
44
44
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
-
57
45
public function setUp (): void
58
46
{
59
47
parent ::setUp ();
@@ -144,100 +132,79 @@ public function testItCanCreateTheCollection()
144
132
#[Depends('testItCanCreateTheCollection ' )]
145
133
public function testItCanUseBasicSearch ()
146
134
{
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 ();
148
137
149
138
self ::assertSame ([
150
- 42 => 'Dax Larkin ' ,
139
+ 1 => 'Laravel Framework ' ,
151
140
11 => 'Larry Casper ' ,
141
+ 12 => 'Reta Larkin ' ,
152
142
20 => 'Prof. Larry Prosacco DVM ' ,
153
- 44 => 'Amos Larson Sr. ' ,
154
- 43 => 'Dana Larson Sr. ' ,
155
- 41 => 'Gudrun Larkin ' ,
156
- 40 => 'Otis Larson MD ' ,
157
143
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. ' ,
160
149
], $ results ->pluck ('name ' , 'id ' )->all ());
161
150
}
162
151
163
152
#[Depends('testItCanCreateTheCollection ' )]
164
153
public function testItCanUseBasicSearchWithQueryCallback ()
165
154
{
166
- $ results = ScoutUser::search ('lar ' )->take (10 )->query (function ($ query ) {
155
+ $ results = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' )-> query (function ($ query ) {
167
156
return $ query ->whereNotNull ('email_verified_at ' );
168
157
})->get ();
169
158
170
159
self ::assertSame ([
160
+ 1 => 'Laravel Framework ' ,
161
+ 12 => 'Reta Larkin ' ,
162
+ 40 => 'Otis Larson MD ' ,
163
+ 41 => 'Gudrun Larkin ' ,
171
164
42 => 'Dax Larkin ' ,
172
- 44 => 'Amos Larson Sr. ' ,
173
165
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. ' ,
178
167
], $ results ->pluck ('name ' , 'id ' )->all ());
179
168
}
180
169
181
170
#[Depends('testItCanCreateTheCollection ' )]
182
171
public function testItCanUseBasicSearchToFetchKeys ()
183
172
{
184
- $ results = ScoutUser::search ('lar ' )->take (10 )->keys ();
173
+ $ results = ScoutUser::search ('lar ' )->orderBy ( ' id ' )-> take (10 )->keys ();
185
174
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 ());
198
176
}
199
177
200
178
#[Depends('testItCanCreateTheCollection ' )]
201
179
public function testItCanUseBasicSearchWithQueryCallbackToFetchKeys ()
202
180
{
203
- $ results = ScoutUser::search ('lar ' )->take (10 )->query (function ($ query ) {
181
+ $ results = ScoutUser::search ('lar ' )->take (10 )->orderBy ( ' id ' , ' desc ' )-> query (function ($ query ) {
204
182
return $ query ->whereNotNull ('email_verified_at ' );
205
183
})->keys ();
206
184
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 ());
219
186
}
220
187
221
188
#[Depends('testItCanCreateTheCollection ' )]
222
189
public function testItCanUsePaginatedSearch ()
223
190
{
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 );
226
193
227
194
self ::assertSame ([
228
- 42 => 'Dax Larkin ' ,
195
+ 1 => 'Laravel Framework ' ,
229
196
11 => 'Larry Casper ' ,
197
+ 12 => 'Reta Larkin ' ,
230
198
20 => 'Prof. Larry Prosacco DVM ' ,
231
- 44 => 'Amos Larson Sr. ' ,
232
- 43 => 'Dana Larson Sr. ' ,
199
+ 39 => 'Linkwood Larkin ' ,
233
200
], $ page1 ->pluck ('name ' , 'id ' )->all ());
234
201
235
202
self ::assertSame ([
236
- 41 => 'Gudrun Larkin ' ,
237
203
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. ' ,
241
208
], $ page2 ->pluck ('name ' , 'id ' )->all ());
242
209
}
243
210
@@ -248,20 +215,32 @@ public function testItCanUsePaginatedSearchWithQueryCallback()
248
215
return $ query ->whereNotNull ('email_verified_at ' );
249
216
};
250
217
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 );
253
220
254
221
self ::assertSame ([
255
- 42 => 'Dax Larkin ' ,
256
- 44 => 'Amos Larson Sr. ' ,
257
- 43 => 'Dana Larson Sr. ' ,
222
+ 1 => 'Laravel Framework ' ,
223
+ 12 => 'Reta Larkin ' ,
258
224
], $ page1 ->pluck ('name ' , 'id ' )->all ());
259
225
260
226
self ::assertSame ([
261
- 41 => 'Gudrun Larkin ' ,
262
227
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. ' ,
265
232
], $ page2 ->pluck ('name ' , 'id ' )->all ());
266
233
}
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
+ }
267
246
}
0 commit comments