@@ -84,23 +84,11 @@ public function test_search()
8484 {
8585 list ($ engine , $ db ) = $ this ->getEngine ();
8686
87- $ db ->shouldReceive ('table ' )
88- ->andReturn ($ table = Mockery::mock ('stdClass ' ));
89- $ db ->shouldReceive ('raw ' )
90- ->with ('plainto_tsquery(?) query ' )
91- ->andReturn ('plainto_tsquery(?) query ' );
87+ $ table = $ this ->setDbExpectations ($ db );
9288
93- $ table ->shouldReceive ('crossJoin ' )->with ('plainto_tsquery(?) query ' )->andReturnSelf ()
94- ->shouldReceive ('select ' )->with ('id ' )->andReturnSelf ()
95- ->shouldReceive ('selectRaw ' )->with ('ts_rank(searchable,query) AS rank ' )->andReturnSelf ()
96- ->shouldReceive ('selectRaw ' )->with ('COUNT(*) OVER () AS total_count ' )->andReturnSelf ()
97- ->shouldReceive ('whereRaw ' )->andReturnSelf ()
98- ->shouldReceive ('orderBy ' )->with ('rank ' , 'desc ' )->andReturnSelf ()
99- ->shouldReceive ('orderBy ' )->with ('id ' )->andReturnSelf ()
100- ->shouldReceive ('skip ' )->with (0 )->andReturnSelf ()
89+ $ table ->shouldReceive ('skip ' )->with (0 )->andReturnSelf ()
10190 ->shouldReceive ('limit ' )->with (5 )->andReturnSelf ()
102- ->shouldReceive ('where ' )->with ('bar ' , 1 )->andReturnSelf ()
103- ->shouldReceive ('toSql ' );
91+ ->shouldReceive ('where ' )->with ('bar ' , 1 );
10492
10593 $ db ->shouldReceive ('select ' )->with (null , ['foo ' , 1 ]);
10694
@@ -138,9 +126,19 @@ public function test_it_returns_total_count()
138126
139127 public function test_map_ids_returns_right_key ()
140128 {
141- list ($ engine ) = $ this ->getEngine ();
142- $ results = [new TestModel ()];
143- $ this ->assertEquals ([1 ], $ engine ->mapIds ($ results ));
129+ list ($ engine , $ db ) = $ this ->getEngine ();
130+
131+ $ this ->setDbExpectations ($ db );
132+
133+ $ db ->shouldReceive ('select ' )
134+ ->andReturn (json_decode ('[{"id": 1}, {"id": 2}] ' ));
135+
136+ $ builder = new Builder (new TestModel , 'foo ' );
137+ $ results = $ engine ->search ($ builder );
138+ $ ids = $ engine ->mapIds ($ results );
139+
140+ $ this ->assertInstanceOf (\Illuminate \Support \Collection::class, $ ids );
141+ $ this ->assertEquals ([1 , 2 ], $ ids ->all ());
144142 }
145143
146144 protected function getEngine ($ config = [])
@@ -153,6 +151,26 @@ protected function getEngine($config = [])
153151
154152 return [new PostgresEngine ($ resolver , $ config ), $ db ];
155153 }
154+
155+ protected function setDbExpectations ($ db , $ skip = 0 , $ limit = 5 )
156+ {
157+ $ db ->shouldReceive ('table ' )
158+ ->andReturn ($ table = Mockery::mock ('stdClass ' ));
159+ $ db ->shouldReceive ('raw ' )
160+ ->with ('plainto_tsquery(?) query ' )
161+ ->andReturn ('plainto_tsquery(?) query ' );
162+
163+ $ table ->shouldReceive ('crossJoin ' )->with ('plainto_tsquery(?) query ' )->andReturnSelf ()
164+ ->shouldReceive ('select ' )->with ('id ' )->andReturnSelf ()
165+ ->shouldReceive ('selectRaw ' )->with ('ts_rank(searchable,query) AS rank ' )->andReturnSelf ()
166+ ->shouldReceive ('selectRaw ' )->with ('COUNT(*) OVER () AS total_count ' )->andReturnSelf ()
167+ ->shouldReceive ('whereRaw ' )->andReturnSelf ()
168+ ->shouldReceive ('orderBy ' )->with ('rank ' , 'desc ' )->andReturnSelf ()
169+ ->shouldReceive ('orderBy ' )->with ('id ' )->andReturnSelf ()
170+ ->shouldReceive ('toSql ' );
171+
172+ return $ table ;
173+ }
156174}
157175
158176class TestModel extends Model
0 commit comments