@@ -91,22 +91,39 @@ public function test_search()
91
91
92
92
$ skip = 0 ;
93
93
$ limit = 5 ;
94
- $ table = $ this ->setDbExpectations ($ db, $ skip , $ limit );
94
+ $ table = $ this ->setDbExpectations ($ db );
95
95
96
- $ table ->shouldReceive ('skip ' )
97
- ->with ($ skip )
98
- ->andReturnSelf ()
99
- ->shouldReceive ('limit ' )
100
- ->with ($ limit )
101
- ->andReturnSelf ()
102
- ->shouldReceive ('where ' )
103
- ->with ('bar ' , 1 );
96
+ $ table ->shouldReceive ('skip ' )->with ($ skip )->andReturnSelf ()
97
+ ->shouldReceive ('limit ' )->with ($ limit )->andReturnSelf ()
98
+ ->shouldReceive ('where ' )->with ('bar ' , 1 )->andReturnSelf ()
99
+ ->shouldReceive ('where ' )->with ('baz ' , 'qux ' );
104
100
105
101
$ db ->shouldReceive ('select ' )
106
- ->with (null , [null , 'foo ' , 1 ]);
102
+ ->with (null , [null , 'foo ' , 1 , ' qux ' ]);
107
103
108
104
$ builder = new Builder (new TestModel (), 'foo ' );
109
- $ builder ->where ('bar ' , 1 )->take (5 );
105
+ $ builder ->where ('bar ' , 1 )
106
+ ->where ('baz ' , 'qux ' )
107
+ ->take (5 );
108
+
109
+ $ engine ->search ($ builder );
110
+ }
111
+
112
+ public function test_search_with_order_by ()
113
+ {
114
+ list ($ engine , $ db ) = $ this ->getEngine ();
115
+
116
+ $ table = $ this ->setDbExpectations ($ db , false );
117
+
118
+ $ table ->shouldReceive ('orderBy ' )->with ('bar ' , 'desc ' )->andReturnSelf ()
119
+ ->shouldReceive ('orderBy ' )->with ('baz ' , 'asc ' )->andReturnSelf ();
120
+
121
+ $ db ->shouldReceive ('select ' )
122
+ ->with (null , [null , 'foo ' ]);
123
+
124
+ $ builder = new Builder (new TestModel (), 'foo ' );
125
+ $ builder ->orderBy ('bar ' , 'desc ' )
126
+ ->orderBy ('baz ' , 'asc ' );
110
127
111
128
$ engine ->search ($ builder );
112
129
}
@@ -247,7 +264,7 @@ protected function getEngine($config = [])
247
264
return [new PostgresEngine ($ resolver , $ config ), $ db ];
248
265
}
249
266
250
- protected function setDbExpectations ($ db )
267
+ protected function setDbExpectations ($ db, $ withDefaultOrderBy = true )
251
268
{
252
269
$ db ->shouldReceive ('table ' )
253
270
->andReturn ($ table = Mockery::mock ('stdClass ' ));
@@ -268,14 +285,18 @@ protected function setDbExpectations($db)
268
285
->with ('COUNT(*) OVER () AS total_count ' )
269
286
->andReturnSelf ()
270
287
->shouldReceive ('whereRaw ' )
271
- ->andReturnSelf ()
272
- ->shouldReceive ('orderBy ' )
273
- ->with ('rank ' , 'desc ' )
274
- ->andReturnSelf ()
275
- ->shouldReceive ('orderBy ' )
276
- ->with ('id ' )
277
- ->andReturnSelf ()
278
- ->shouldReceive ('toSql ' );
288
+ ->andReturnSelf ();
289
+
290
+ if ($ withDefaultOrderBy ) {
291
+ $ table ->shouldReceive ('orderBy ' )
292
+ ->with ('rank ' , 'desc ' )
293
+ ->andReturnSelf ()
294
+ ->shouldReceive ('orderBy ' )
295
+ ->with ('id ' )
296
+ ->andReturnSelf ();
297
+ }
298
+
299
+ $ table ->shouldReceive ('toSql ' );
279
300
280
301
return $ table ;
281
302
}
0 commit comments