@@ -92,7 +92,8 @@ public function test_search()
92
92
93
93
$ table ->shouldReceive ('crossJoin ' )->with ('plainto_tsquery(?) query ' )->andReturnSelf ()
94
94
->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 ()
96
97
->shouldReceive ('whereRaw ' )->andReturnSelf ()
97
98
->shouldReceive ('orderBy ' )->with ('rank ' , 'desc ' )->andReturnSelf ()
98
99
->shouldReceive ('orderBy ' )->with ('id ' )->andReturnSelf ()
@@ -119,11 +120,22 @@ public function test_map_correctly_maps_results_to_models()
119
120
$ model ->shouldReceive ('get ' )->once ()->andReturn (Collection::make ([new TestModel ()]));
120
121
121
122
$ results = $ engine ->map (
122
- json_decode ('[{"id": 1, "rank": 0.33}] ' ), $ model );
123
+ json_decode ('[{"id": 1, "rank": 0.33, "total_count": 1 }] ' ), $ model );
123
124
124
125
$ this ->assertCount (1 , $ results );
125
126
}
126
127
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
+
127
139
protected function getEngine ($ config = [])
128
140
{
129
141
$ resolver = Mockery::mock (ConnectionResolverInterface::class);
0 commit comments