Skip to content

Commit

Permalink
Fixing Testing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devNoiseConsulting committed Apr 25, 2023
1 parent d6fea0d commit e71dbbd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/PostgresEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ public function map(Builder $builder, $results, $model)
// The models didn't come out of the database in the correct order.
// This will map the models into the resultsModel based on the results order.
foreach ($keys as $key) {
$resultModels->push($models[$key]);
if ($models->has($key)) {
$resultModels->push($models[$key]);
}
}

return $resultModels;
Expand Down
36 changes: 18 additions & 18 deletions tests/PostgresEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace ScoutEngines\Postgres\Test;

use Exception;
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\PostgresConnection;
use Laravel\Scout\Builder;
use Mockery;
use ScoutEngines\Postgres\PostgresEngine;
Expand Down Expand Up @@ -36,7 +36,7 @@ public function update_adds_object_to_index()
$query->shouldReceive('selectRaw')
->with(
'to_tsvector(COALESCE(?, get_current_ts_config()), ?) || setweight(to_tsvector(COALESCE(?, get_current_ts_config()), ?), ?) AS tsvector',
[null, 'Foo', null, '', 'B']
['simple', 'Foo', 'simple', '', 'B']
)
->andReturnSelf();
$query->shouldReceive('value')
Expand Down Expand Up @@ -361,7 +361,7 @@ protected function getEngine($config = [])
{
$resolver = Mockery::mock(ConnectionResolverInterface::class);
$resolver->shouldReceive('connection')
->andReturn($db = Mockery::mock(Connection::class));
->andReturn($db = Mockery::mock(PostgresConnection::class));

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

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

$table->shouldReceive('crossJoin')
->with('plainto_tsquery(COALESCE(?, get_current_ts_config()), ?) AS "tsquery"')
->andReturnSelf()
->with('plainto_tsquery(COALESCE(?, get_current_ts_config()), ?) AS "tsquery"')
->andReturnSelf()
->shouldReceive('addBinding')
->with(Mockery::type('array'), 'join')
->andReturnSelf()
->with(Mockery::type('array'), 'join')
->andReturnSelf()
->shouldReceive('select')
->with('id')
->andReturnSelf()
->with('id')
->andReturnSelf()
->shouldReceive('selectRaw')
->with('ts_rank(searchable,"tsquery") AS rank')
->andReturnSelf()
->with('ts_rank(searchable,"tsquery") AS rank')
->andReturnSelf()
->shouldReceive('selectRaw')
->with('COUNT(*) OVER () AS total_count')
->andReturnSelf()
->with('COUNT(*) OVER () AS total_count')
->andReturnSelf()
->shouldReceive('whereRaw')
->andReturnSelf();
->andReturnSelf();

if ($withDefaultOrderBy) {
$table->shouldReceive('orderBy')
->with('rank', 'desc')
->andReturnSelf()
->with('rank', 'desc')
->andReturnSelf()
->shouldReceive('orderBy')
->with('id')
->andReturnSelf();
->with('id')
->andReturnSelf();
}

$table->shouldReceive('toSql');
Expand Down

0 comments on commit e71dbbd

Please sign in to comment.