Skip to content

Commit accd8f8

Browse files
Scout 9 Support
Update the test Matrix. Added Laravel 9 and Scout 9 packages. Implemented new abstract methods needed for Scout 9. Added tests for 2 of the 3 new methods. The lazyMap method returns a lazyCollection but not completely implemeted yet.
1 parent 4f99820 commit accd8f8

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

.github/workflows/tests.yml

100644100755
+23-11
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@ jobs:
1111

1212
runs-on: ubuntu-latest
1313
strategy:
14-
fail-fast: true
14+
fail-fast: false
1515
matrix:
16-
php: [7.2, 7.3, 7.4]
17-
laravel: [^6.0, ^7.0, ^8.0]
18-
scout: [^7.0, ^8.0]
16+
php: [7.3, 7.4, 8.0, 8.1]
17+
laravel: [^6.0, ^7.0, ^8.0, ^9.0]
18+
scout: [^7.0, ^8.0, ^9.0]
1919
exclude:
20-
- php: 7.2
21-
laravel: ^8.0
20+
- php: 7.3
21+
laravel: ^9.0
22+
- php: 7.4
23+
laravel: ^9.0
24+
- php: 8.0
25+
scout: ^7.0
26+
- php: 8.1
27+
scout: ^7.0
28+
- php: 8.1
29+
scout: ^8.0
30+
- laravel: ^6.0
31+
scout: ^9.0
32+
- laravel: ^7.0
33+
scout: ^9.0
2234
- laravel: ^8.0
2335
scout: ^7.0
24-
include:
25-
- php: 8.0
26-
laravel: ^8.0
36+
- laravel: ^9.0
37+
scout: ^7.0
38+
- laravel: ^9.0
2739
scout: ^8.0
28-
40+
2941
name: Test PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Scout ${{ matrix.scout }}
3042

3143
steps:
@@ -49,4 +61,4 @@ jobs:
4961
composer update --prefer-dist --no-interaction --no-progress
5062
5163
- name: Run tests
52-
run: vendor/bin/phpunit --verbose
64+
run: vendor/bin/phpunit --verbose

composer.json

100644100755
+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.2|^8.0",
27-
"illuminate/contracts": "~6.0|~7.0|~8.0",
28-
"illuminate/database": "~6.0|~7.0|~8.0",
29-
"illuminate/support": "~6.0|~7.0|~8.0",
30-
"laravel/scout": "~7.0|~8.0"
26+
"php": "^7.3|^8.0",
27+
"illuminate/contracts": "~6.0|~7.0|~8.0|~9.0",
28+
"illuminate/database": "~6.0|~7.0|~8.0|~9.0",
29+
"illuminate/support": "~6.0|~7.0|~8.0|~9.0",
30+
"laravel/scout": "~7.0|~8.0|~9.0"
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "^8.3",

src/PostgresEngine.php

100644100755
+37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ScoutEngines\Postgres;
44

5+
use Exception;
56
use Illuminate\Database\ConnectionResolverInterface;
67
use Illuminate\Database\Eloquent\Collection;
78
use Illuminate\Database\Eloquent\Model;
@@ -339,6 +340,42 @@ public function map(Builder $builder, $results, $model)
339340
});
340341
}
341342

343+
/**
344+
* Map the given results to instances of the given model via a lazy collection.
345+
*
346+
* @param \Laravel\Scout\Builder $builder
347+
* @param mixed $results
348+
* @param \Illuminate\Database\Eloquent\Model $model
349+
* @return \Illuminate\Support\LazyCollection
350+
*/
351+
public function lazyMap(Builder $builder, $results, $model)
352+
{
353+
return LazyCollection::make($model->newCollection());
354+
}
355+
356+
/**
357+
* Create a search index.
358+
*
359+
* @param string $name
360+
* @param array $options
361+
* @return mixed
362+
*/
363+
public function createIndex($name, array $options = [])
364+
{
365+
throw new Exception('PostgreSQL indexes should be created through Laravel database migrations.');
366+
}
367+
368+
/**
369+
* Delete a search index.
370+
*
371+
* @param string $name
372+
* @return mixed
373+
*/
374+
public function deleteIndex($name)
375+
{
376+
throw new Exception('PostgreSQL indexes should be deleted through Laravel database migrations.');
377+
}
378+
342379
/**
343380
* Connect to the database.
344381
*/

tests/PostgresEngineTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,26 @@ public function test_map_ids_returns_right_key()
282282
$this->assertEquals([1, 2], $ids->all());
283283
}
284284

285+
public function test_create_index()
286+
{
287+
[$engine, $db] = $this->getEngine();
288+
289+
$this->expectException(\Exception::class);
290+
$this->expectExceptionMessage('PostgreSQL indexes should be created through Laravel database migrations.');
291+
292+
$engine->createIndex('bad_index');
293+
}
294+
295+
public function test_delete_index()
296+
{
297+
[$engine, $db] = $this->getEngine();
298+
299+
$this->expectException(\Exception::class);
300+
$this->expectExceptionMessage('PostgreSQL indexes should be deleted through Laravel database migrations.');
301+
302+
$engine->deleteIndex('bad_index');
303+
}
304+
285305
protected function getEngine($config = [])
286306
{
287307
$resolver = Mockery::mock(ConnectionResolverInterface::class);

0 commit comments

Comments
 (0)