@@ -32,25 +32,25 @@ public function update_adds_object_to_index()
32
32
[$ engine , $ db ] = $ this ->getEngine ();
33
33
34
34
$ db ->shouldReceive ('query ' )
35
- ->andReturn ($ query = Mockery::mock ('stdClass ' ));
35
+ ->andReturn ($ query = Mockery::mock ('stdClass ' ))-> once () ;
36
36
$ query ->shouldReceive ('selectRaw ' )
37
37
->with (
38
38
'to_tsvector(COALESCE(?, get_current_ts_config()), ?) || setweight(to_tsvector(COALESCE(?, get_current_ts_config()), ?), ?) AS tsvector ' ,
39
39
[null , 'Foo ' , null , '' , 'B ' ]
40
40
)
41
- ->andReturnSelf ();
41
+ ->andReturnSelf ()-> once () ;
42
42
$ query ->shouldReceive ('value ' )
43
43
->with ('tsvector ' )
44
- ->andReturn ('foo ' );
44
+ ->andReturn ('foo ' )-> once () ;
45
45
46
46
$ db ->shouldReceive ('table ' )
47
47
->andReturn ($ table = Mockery::mock ('stdClass ' ));
48
48
$ table ->shouldReceive ('where ' )
49
49
->with ('id ' , '= ' , 1 )
50
- ->andReturnSelf ();
50
+ ->andReturnSelf ()-> once () ;
51
51
52
52
$ table ->shouldReceive ('update ' )
53
- ->with (['searchable ' => 'foo ' ]);
53
+ ->with (['searchable ' => 'foo ' ])-> once () ;
54
54
55
55
$ engine ->update (Collection::make ([new TestModel ]));
56
56
}
@@ -62,7 +62,7 @@ public function update_do_nothing_if_index_maintenance_turned_off_globally()
62
62
{
63
63
[$ engine ] = $ this ->getEngine (['maintain_index ' => false ]);
64
64
65
- $ engine ->update (Collection::make ([new TestModel ]));
65
+ $ this -> assertNull ( $ engine ->update (Collection::make ([new TestModel ]) ));
66
66
}
67
67
68
68
/**
@@ -73,12 +73,15 @@ public function delete_removes_object_from_index()
73
73
[$ engine , $ db ] = $ this ->getEngine ();
74
74
75
75
$ db ->shouldReceive ('table ' )
76
- ->andReturn ($ table = Mockery::mock ('stdClass ' ));
76
+ ->andReturn ($ table = Mockery::mock ('stdClass ' ))
77
+ ->once ();
77
78
$ table ->shouldReceive ('whereIn ' )
78
79
->with ('id ' , [1 ])
79
- ->andReturnSelf ();
80
+ ->andReturnSelf ()
81
+ ->once ();
80
82
$ table ->shouldReceive ('update ' )
81
- ->with (['searchable ' => null ]);
83
+ ->with (['searchable ' => null ])
84
+ ->once ();
82
85
83
86
$ engine ->delete (Collection::make ([new TestModel ]));
84
87
}
@@ -142,7 +145,8 @@ public function search()
142
145
->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' , 1 , 'qux ' ]);
143
146
144
147
$ db ->shouldReceive ('select ' )
145
- ->with (null , $ table ->getBindings ());
148
+ ->with (null , $ table ->getBindings ())
149
+ ->once ();
146
150
147
151
$ builder = new Builder (new TestModel , 'foo ' );
148
152
$ builder ->where ('bar ' , 1 )
@@ -166,7 +170,8 @@ public function search_with_order_by()
166
170
->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' ]);
167
171
168
172
$ db ->shouldReceive ('select ' )
169
- ->with (null , $ table ->getBindings ());
173
+ ->with (null , $ table ->getBindings ())
174
+ ->once ();
170
175
171
176
$ builder = new Builder (new TestModel , 'foo ' );
172
177
$ builder ->orderBy ('bar ' , 'desc ' )
@@ -175,6 +180,85 @@ public function search_with_order_by()
175
180
$ engine ->search ($ builder );
176
181
}
177
182
183
+ /**
184
+ * @test
185
+ */
186
+ public function search_with_queryCallback ()
187
+ {
188
+ [$ engine , $ db ] = $ this ->getEngine ();
189
+
190
+ $ skip = 0 ;
191
+ $ limit = 5 ;
192
+ $ table = $ this ->setDbExpectations ($ db );
193
+
194
+ $ table ->shouldReceive ('skip ' )->with ($ skip )->andReturnSelf ()
195
+ ->shouldReceive ('limit ' )->with ($ limit )->andReturnSelf ()
196
+ ->shouldReceive ('where ' )->with ('bar ' , 1 )->andReturnSelf ()
197
+ ->shouldReceive ('where ' )->with ('baz ' , 'qux ' )
198
+ ->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' , 1 , 'qux ' ]);
199
+
200
+ $ db ->shouldReceive ('select ' )
201
+ ->with (null , $ table ->getBindings ())
202
+ ->once ();
203
+
204
+ $ builder = new Builder (new TestModel , 'foo ' );
205
+ $ builder ->query (function ($ q ) {
206
+ $ q ->where ('bar ' , 1 )
207
+ ->where ('baz ' , 'qux ' )
208
+ ->take (5 );
209
+ });
210
+
211
+ $ engine ->search ($ builder );
212
+ }
213
+
214
+ /**
215
+ * @test
216
+ */
217
+ public function search_with_whereIn ()
218
+ {
219
+ [$ engine , $ db ] = $ this ->getEngine ();
220
+
221
+ $ skip = 0 ;
222
+ $ limit = 5 ;
223
+ $ table = $ this ->setDbExpectations ($ db );
224
+
225
+ $ table ->shouldReceive ('whereIn ' )->with ('bar ' , [1 ])->andReturnSelf ()
226
+ ->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' , [1 ]]);
227
+
228
+ $ db ->shouldReceive ('select ' )
229
+ ->with (null , $ table ->getBindings ())
230
+ ->once ();
231
+
232
+ $ builder = new Builder (new TestModel , 'foo ' );
233
+ $ builder ->whereIn ('bar ' , [1 ]);
234
+
235
+ $ engine ->search ($ builder );
236
+ }
237
+
238
+ /**
239
+ * @test
240
+ */
241
+ public function search_with_whereNotIn ()
242
+ {
243
+ [$ engine , $ db ] = $ this ->getEngine ();
244
+
245
+ $ skip = 0 ;
246
+ $ limit = 5 ;
247
+ $ table = $ this ->setDbExpectations ($ db );
248
+
249
+ $ table ->shouldReceive ('whereNotIn ' )->with ('bar ' , [1 ])->andReturnSelf ()
250
+ ->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' , [1 ]]);
251
+
252
+ $ db ->shouldReceive ('select ' )
253
+ ->with (null , $ table ->getBindings ())
254
+ ->once ();
255
+
256
+ $ builder = new Builder (new TestModel , 'foo ' );
257
+ $ builder ->whereNotIn ('bar ' , [1 ]);
258
+
259
+ $ engine ->search ($ builder );
260
+ }
261
+
178
262
/**
179
263
* @test
180
264
*/
@@ -191,7 +275,7 @@ public function search_with_global_config()
191
275
->shouldReceive ('where ' )->with ('bar ' , 1 )
192
276
->shouldReceive ('getBindings ' )->andReturn (['simple ' , 'foo ' , 1 ]);
193
277
194
- $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ());
278
+ $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ())-> once () ;
195
279
196
280
$ builder = new Builder (new TestModel , 'foo ' );
197
281
$ builder ->where ('bar ' , 1 )->take (5 );
@@ -215,7 +299,7 @@ public function search_with_model_config()
215
299
->shouldReceive ('where ' )->with ('bar ' , 1 )
216
300
->shouldReceive ('getBindings ' )->andReturn (['english ' , 'foo ' , 1 ]);
217
301
218
- $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ());
302
+ $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ())-> once () ;
219
303
220
304
$ model = new TestModel ;
221
305
$ model ->searchableOptions ['config ' ] = 'english ' ;
@@ -241,7 +325,7 @@ public function search_with_soft_deletes()
241
325
->shouldReceive ('whereNull ' )->with ('deleted_at ' )
242
326
->shouldReceive ('getBindings ' )->andReturn ([null , 'foo ' , 1 ]);
243
327
244
- $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ());
328
+ $ db ->shouldReceive ('select ' )->with (null , $ table ->getBindings ())-> once () ;
245
329
246
330
$ builder = new Builder (new SoftDeletableTestModel , 'foo ' );
247
331
$ builder ->where ('bar ' , 1 )->take (5 );
0 commit comments