Skip to content

Commit e71dbbd

Browse files
Fixing Testing
Making changes so test matches how the code works. Changed code so that the test passes. Not sure that the map_filters_out_no_longer_existing_models is really a valid test.
1 parent d6fea0d commit e71dbbd

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/PostgresEngine.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ public function map(Builder $builder, $results, $model)
335335
// The models didn't come out of the database in the correct order.
336336
// This will map the models into the resultsModel based on the results order.
337337
foreach ($keys as $key) {
338-
$resultModels->push($models[$key]);
338+
if ($models->has($key)) {
339+
$resultModels->push($models[$key]);
340+
}
339341
}
340342

341343
return $resultModels;

tests/PostgresEngineTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace ScoutEngines\Postgres\Test;
44

55
use Exception;
6-
use Illuminate\Database\Connection;
76
use Illuminate\Database\ConnectionResolverInterface;
87
use Illuminate\Database\Eloquent\Collection;
98
use Illuminate\Database\Eloquent\Model;
109
use Illuminate\Database\Eloquent\SoftDeletes;
10+
use Illuminate\Database\PostgresConnection;
1111
use Laravel\Scout\Builder;
1212
use Mockery;
1313
use ScoutEngines\Postgres\PostgresEngine;
@@ -36,7 +36,7 @@ public function update_adds_object_to_index()
3636
$query->shouldReceive('selectRaw')
3737
->with(
3838
'to_tsvector(COALESCE(?, get_current_ts_config()), ?) || setweight(to_tsvector(COALESCE(?, get_current_ts_config()), ?), ?) AS tsvector',
39-
[null, 'Foo', null, '', 'B']
39+
['simple', 'Foo', 'simple', '', 'B']
4040
)
4141
->andReturnSelf();
4242
$query->shouldReceive('value')
@@ -361,7 +361,7 @@ protected function getEngine($config = [])
361361
{
362362
$resolver = Mockery::mock(ConnectionResolverInterface::class);
363363
$resolver->shouldReceive('connection')
364-
->andReturn($db = Mockery::mock(Connection::class));
364+
->andReturn($db = Mockery::mock(PostgresConnection::class));
365365

366366
$db->shouldReceive('getDriverName')->andReturn('pgsql');
367367

@@ -377,30 +377,30 @@ protected function setDbExpectations($db, $withDefaultOrderBy = true)
377377
->andReturn('plainto_tsquery(COALESCE(?, get_current_ts_config()), ?) AS "tsquery"');
378378

379379
$table->shouldReceive('crossJoin')
380-
->with('plainto_tsquery(COALESCE(?, get_current_ts_config()), ?) AS "tsquery"')
381-
->andReturnSelf()
380+
->with('plainto_tsquery(COALESCE(?, get_current_ts_config()), ?) AS "tsquery"')
381+
->andReturnSelf()
382382
->shouldReceive('addBinding')
383-
->with(Mockery::type('array'), 'join')
384-
->andReturnSelf()
383+
->with(Mockery::type('array'), 'join')
384+
->andReturnSelf()
385385
->shouldReceive('select')
386-
->with('id')
387-
->andReturnSelf()
386+
->with('id')
387+
->andReturnSelf()
388388
->shouldReceive('selectRaw')
389-
->with('ts_rank(searchable,"tsquery") AS rank')
390-
->andReturnSelf()
389+
->with('ts_rank(searchable,"tsquery") AS rank')
390+
->andReturnSelf()
391391
->shouldReceive('selectRaw')
392-
->with('COUNT(*) OVER () AS total_count')
393-
->andReturnSelf()
392+
->with('COUNT(*) OVER () AS total_count')
393+
->andReturnSelf()
394394
->shouldReceive('whereRaw')
395-
->andReturnSelf();
395+
->andReturnSelf();
396396

397397
if ($withDefaultOrderBy) {
398398
$table->shouldReceive('orderBy')
399-
->with('rank', 'desc')
400-
->andReturnSelf()
399+
->with('rank', 'desc')
400+
->andReturnSelf()
401401
->shouldReceive('orderBy')
402-
->with('id')
403-
->andReturnSelf();
402+
->with('id')
403+
->andReturnSelf();
404404
}
405405

406406
$table->shouldReceive('toSql');

0 commit comments

Comments
 (0)