Skip to content

Commit 774d9cf

Browse files
committed
add a test to make sure the search config is getting used
1 parent 2138d4a commit 774d9cf

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

tests/PostgresEngineTest.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,33 @@ public function test_search()
8484
{
8585
list($engine, $db) = $this->getEngine();
8686

87-
$table = $this->setDbExpectations($db);
87+
$skip = 0;
88+
$limit = 5;
89+
$table = $this->setDbExpectations($db, $skip, $limit);
8890

89-
$table->shouldReceive('skip')->with(0)->andReturnSelf()
90-
->shouldReceive('limit')->with(5)->andReturnSelf()
91+
$table->shouldReceive('skip')->with($skip)->andReturnSelf()
92+
->shouldReceive('limit')->with($limit)->andReturnSelf()
93+
->shouldReceive('where')->with('bar', 1);
94+
95+
$db->shouldReceive('select')->with(null, ['foo', 1]);
96+
97+
$builder = new Builder(new TestModel(), 'foo');
98+
$builder->where('bar', 1)->take(5);
99+
100+
$engine->search($builder);
101+
}
102+
103+
public function test_search_configuration()
104+
{
105+
$searchConfig = 'simple';
106+
list($engine, $db) = $this->getEngine(['search_configuration' => $searchConfig]);
107+
108+
$skip = 0;
109+
$limit = 5;
110+
$table = $this->setDbExpectations($db, $skip, $limit, "'".$searchConfig."'");
111+
112+
$table->shouldReceive('skip')->with($skip)->andReturnSelf()
113+
->shouldReceive('limit')->with($limit)->andReturnSelf()
91114
->shouldReceive('where')->with('bar', 1);
92115

93116
$db->shouldReceive('select')->with(null, ['foo', 1]);
@@ -152,15 +175,15 @@ protected function getEngine($config = [])
152175
return [new PostgresEngine($resolver, $config), $db];
153176
}
154177

155-
protected function setDbExpectations($db, $skip = 0, $limit = 5)
178+
protected function setDbExpectations($db, $skip = 0, $limit = 5, $searchConfiguration = '')
156179
{
157180
$db->shouldReceive('table')
158181
->andReturn($table = Mockery::mock('stdClass'));
159182
$db->shouldReceive('raw')
160-
->with('plainto_tsquery( ?) query')
161-
->andReturn('plainto_tsquery( ?) query');
183+
->with("plainto_tsquery($searchConfiguration ?) query")
184+
->andReturn("plainto_tsquery($searchConfiguration ?) query");
162185

163-
$table->shouldReceive('crossJoin')->with('plainto_tsquery( ?) query')->andReturnSelf()
186+
$table->shouldReceive('crossJoin')->with("plainto_tsquery($searchConfiguration ?) query")->andReturnSelf()
164187
->shouldReceive('select')->with('id')->andReturnSelf()
165188
->shouldReceive('selectRaw')->with('ts_rank(searchable,query) AS rank')->andReturnSelf()
166189
->shouldReceive('selectRaw')->with('COUNT(*) OVER () AS total_count')->andReturnSelf()

0 commit comments

Comments
 (0)