@@ -92,7 +92,8 @@ public function test_search()
9292
9393 $ table ->shouldReceive ('crossJoin ' )->with ('plainto_tsquery(?) query ' )->andReturnSelf ()
9494 ->shouldReceive ('select ' )->with ('id ' )->andReturnSelf ()
95- ->shouldReceive ('selectRaw ' )->andReturnSelf ()
95+ ->shouldReceive ('selectRaw ' )->with ('ts_rank(searchable,query) AS rank ' )->andReturnSelf ()
96+ ->shouldReceive ('selectRaw ' )->with ('COUNT(*) OVER () AS total_count ' )->andReturnSelf ()
9697 ->shouldReceive ('whereRaw ' )->andReturnSelf ()
9798 ->shouldReceive ('orderBy ' )->with ('rank ' , 'desc ' )->andReturnSelf ()
9899 ->shouldReceive ('orderBy ' )->with ('id ' )->andReturnSelf ()
@@ -119,11 +120,22 @@ public function test_map_correctly_maps_results_to_models()
119120 $ model ->shouldReceive ('get ' )->once ()->andReturn (Collection::make ([new TestModel ()]));
120121
121122 $ results = $ engine ->map (
122- json_decode ('[{"id": 1, "rank": 0.33}] ' ), $ model );
123+ json_decode ('[{"id": 1, "rank": 0.33, "total_count": 1 }] ' ), $ model );
123124
124125 $ this ->assertCount (1 , $ results );
125126 }
126127
128+ public function test_it_returns_total_count ()
129+ {
130+ list ($ engine ) = $ this ->getEngine ();
131+
132+ $ count = $ engine ->getTotalCount (
133+ json_decode ('[{"id": 1, "rank": 0.33, "total_count": 100}] ' )
134+ );
135+
136+ $ this ->assertEquals (100 , $ count );
137+ }
138+
127139 protected function getEngine ($ config = [])
128140 {
129141 $ resolver = Mockery::mock (ConnectionResolverInterface::class);
0 commit comments