Skip to content

Commit bcc92fc

Browse files
authored
Laravel 11 Support (#17)
* Add Laravel 11 Support Drop support for Laravel 9 Updates workflow * trigger tests * migrate phpunit configuration * Lint * Move fixtures out of tests due to class cannot be found * restore github workflow * Add Laravel Pint * fix: Relocate fixtures back into tests and resolve PHPUnit error chore: updatw GitHub Actions Workflow fix: resolve feedback on composer.json * cleanup * chore: remove source from phpunit config fix: add phpunit 9 to composer * Use orchestra/testbench * fix failing test * fix tests
1 parent cea7ecf commit bcc92fc

12 files changed

+207
-169
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.{yml,yaml}]
18+
indent_size = 2

.github/workflows/tests.yml

+20-13
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,31 @@ on:
88

99
jobs:
1010
tests:
11-
runs-on: ubuntu-latest
12-
11+
runs-on: ${{ matrix.os }}
1312
strategy:
1413
fail-fast: true
1514
matrix:
16-
php: ["8.0", 8.1, 8.2]
17-
laravel: [9, 10]
15+
os: [ubuntu-latest]
16+
php: [8.3, 8.2, 8.1, 8.0]
17+
laravel: [11.*, 10.*, 9.*]
18+
dependency-version: [prefer-lowest, prefer-stable]
1819
exclude:
19-
- php: "8.0"
20-
laravel: 9
21-
- php: "8.0"
22-
laravel: 10
20+
- laravel: 11.*
21+
php: 8.1
22+
- laravel: 11.*
23+
php: 8.0
24+
- laravel: 10.*
25+
php: 8.0
26+
- laravel: 9.*
27+
php: 8.3
28+
- laravel: 9.*
29+
php: 8.2
2330

24-
name: P${{ matrix.php }} - L${{ matrix.laravel }}
31+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
2532

2633
steps:
2734
- name: Checkout code
28-
uses: actions/checkout@v2
35+
uses: actions/checkout@v4
2936

3037
- name: Setup PHP
3138
uses: shivammathur/setup-php@v2
@@ -37,7 +44,7 @@ jobs:
3744

3845
- name: Install dependencies
3946
run: |
40-
composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update
41-
composer update --prefer-dist --no-interaction --no-progress
47+
composer require "illuminate/bus:${{ matrix.laravel }}" "illuminate/contracts:${{ matrix.laravel }}" "illuminate/database:${{ matrix.laravel }}" "illuminate/http:${{ matrix.laravel }}" "illuminate/pagination:${{ matrix.laravel }}" "illuminate/queue:${{ matrix.laravel }}" "illuminate/support:${{ matrix.laravel }}" --no-interaction --no-update
48+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress
4249
- name: Execute tests
43-
run: vendor/bin/phpunit --verbose
50+
run: vendor/bin/phpunit

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
composer.phar
44
composer.lock
55
.DS_Store
6-
Thumbs.db
6+
Thumbs.db
7+
.phpunit.result.cache
8+
.phpunit.cache/

composer.json

+57-43
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
{
2-
"name": "sti3bas/laravel-scout-array-driver",
3-
"description": "Array driver for Laravel Scout",
4-
"keywords": [
5-
"array",
6-
"testing",
7-
"driver",
8-
"scout",
9-
"laravel"
10-
],
11-
"license": "MIT",
12-
"authors": [
13-
{
14-
"name": "Laurynas Geigalas",
15-
"email": "[email protected]"
2+
"name": "sti3bas/laravel-scout-array-driver",
3+
"description": "Array driver for Laravel Scout",
4+
"license": "MIT",
5+
"keywords": [
6+
"array",
7+
"testing",
8+
"driver",
9+
"scout",
10+
"laravel"
11+
],
12+
"authors": [
13+
{
14+
"name": "Laurynas Geigalas",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"php": "^8.0 || ^8.1 || ^8.2",
20+
"illuminate/bus": "^9.0 || ^10.0 || ^11.0",
21+
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
22+
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
23+
"illuminate/http": "^9.0 || ^10.0 || ^11.0",
24+
"illuminate/pagination": "^9.0 || ^10.0 || ^11.0",
25+
"illuminate/queue": "^9.0 || ^10.0 || ^11.0",
26+
"illuminate/support": "^9.0 || ^10.0 || ^11.0",
27+
"laravel/scout": "^10.0"
28+
},
29+
"require-dev": {
30+
"laravel/pint": "^1.0",
31+
"mockery/mockery": "^1.5.1",
32+
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",
33+
"phpunit/phpunit": "^9.0 || ^10.5"
34+
},
35+
"minimum-stability": "dev",
36+
"prefer-stable": true,
37+
"autoload": {
38+
"psr-4": {
39+
"Sti3bas\\ScoutArray\\": "src/"
40+
}
41+
},
42+
"autoload-dev": {
43+
"psr-4": {
44+
"Sti3bas\\ScoutArray\\Tests\\": "tests/"
45+
}
46+
},
47+
"config": {
48+
"sort-packages": true
49+
},
50+
"extra": {
51+
"branch-alias": {
52+
"dev-master": "11.x-dev"
53+
},
54+
"laravel": {
55+
"providers": [
56+
"Sti3bas\\ScoutArray\\ScoutArrayEngineServiceProvider"
57+
]
58+
}
1659
}
17-
],
18-
"require": {
19-
"php": "^8.0",
20-
"laravel/scout": "^10.0",
21-
"illuminate/database": "^8.0|^9.0|^10.0",
22-
"illuminate/support": "^8.0|^9.0|^10.0"
23-
},
24-
"require-dev": {
25-
"phpunit/phpunit": "^9.3",
26-
"mockery/mockery": "~1.0"
27-
},
28-
"autoload": {
29-
"psr-4": {
30-
"Sti3bas\\ScoutArray\\": "src/"
31-
}
32-
},
33-
"autoload-dev": {
34-
"psr-4": {
35-
"Sti3bas\\ScoutArray\\Tests\\": "tests/"
36-
}
37-
},
38-
"extra": {
39-
"laravel": {
40-
"providers": [
41-
"Sti3bas\\ScoutArray\\ScoutArrayEngineServiceProvider"
42-
]
43-
}
44-
},
45-
"prefer-stable": true
4660
}

phpunit.xml.dist

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
backupGlobals="false"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
executionOrder="random"
11+
failOnWarning="true"
12+
failOnRisky="true"
13+
failOnEmptyTestSuite="true"
14+
beStrictAboutOutputDuringTests="true"
15+
cacheDirectory=".phpunit.cache"
16+
backupStaticProperties="false"
1117
>
12-
<testsuites>
13-
<testsuite name="Package Test Suite">
14-
<directory suffix=".php">./tests/</directory>
15-
</testsuite>
16-
</testsuites>
17-
</phpunit>
18+
<testsuites>
19+
<testsuite name="tests">
20+
<directory>tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

src/ArrayStore.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function createIndex(string $index): void
3838

3939
public function deleteIndex(string $index): void
4040
{
41-
$this->storage = Arr::except($this->storage, 'current.' . $index);
41+
$this->storage = Arr::except($this->storage, 'current.'.$index);
4242
}
4343

4444
public function indexExists(string $index): bool
@@ -66,12 +66,12 @@ public function findInHistory(string $index, Closure $callback): array
6666
return $this->findInArray(Arr::get($this->storage['history'], $index, []), $callback);
6767
}
6868

69-
public function count(string $index = null, string $type = 'current'): int
69+
public function count(?string $index = null, string $type = 'current'): int
7070
{
7171
return count($index ? Arr::get($this->storage[$type], $index, []) : Arr::flatten($this->storage[$type], 1));
7272
}
7373

74-
public function countInHistory(string $index = null): int
74+
public function countInHistory(?string $index = null): int
7575
{
7676
return $this->count($index, 'history');
7777
}
@@ -126,7 +126,7 @@ private function replaceRecordsWithMocks(string $index): array
126126
if ($mock = $this->getMock($index, $record['objectID'])) {
127127
return $mock;
128128
}
129-
129+
130130
return $record;
131131
}, Arr::get($this->storage['current'], $index, []));
132132
}

src/Engines/ArrayEngine.php

+10-21
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public function __construct($store, $softDelete = false)
3434
/**
3535
* Update the given model in the index.
3636
*
37-
* @param Collection $models
38-
*
37+
* @param Collection $models
3938
* @return void
4039
*/
4140
public function update($models)
@@ -59,8 +58,7 @@ public function update($models)
5958
/**
6059
* Remove the given model from the index.
6160
*
62-
* @param Collection $models
63-
*
61+
* @param Collection $models
6462
* @return void
6563
*/
6664
public function delete($models)
@@ -73,7 +71,6 @@ public function delete($models)
7371
/**
7472
* Perform the given search on the engine.
7573
*
76-
* @param Builder $builder
7774
*
7875
* @return mixed
7976
*/
@@ -87,7 +84,6 @@ public function search(Builder $builder)
8784
/**
8885
* Perform the given search on the engine.
8986
*
90-
* @param \Laravel\Scout\Builder $builder
9187
* @param int $perPage
9288
* @param int $page
9389
* @return mixed
@@ -103,8 +99,6 @@ public function paginate(Builder $builder, $perPage, $page)
10399
/**
104100
* Perform the given search on the engine.
105101
*
106-
* @param \Laravel\Scout\Builder $builder
107-
* @param array $options
108102
* @return mixed
109103
*/
110104
protected function performSearch(Builder $builder, array $options = [])
@@ -114,8 +108,8 @@ protected function performSearch(Builder $builder, array $options = [])
114108
$matches = $this->store->find($index, function ($record) use ($builder) {
115109
$values = new RecursiveIteratorIterator(new RecursiveArrayIterator($record));
116110

117-
return $this->matchesFilters($record, $builder->wheres) && !empty(array_filter(iterator_to_array($values, false), function ($value) use ($builder) {
118-
return !$builder->query || stripos($value, $builder->query) !== false;
111+
return $this->matchesFilters($record, $builder->wheres) && ! empty(array_filter(iterator_to_array($values, false), function ($value) use ($builder) {
112+
return ! $builder->query || stripos($value, $builder->query) !== false;
119113
}));
120114
}, true);
121115

@@ -130,8 +124,8 @@ protected function performSearch(Builder $builder, array $options = [])
130124
/**
131125
* Determine if the given record matches given filters.
132126
*
133-
* @param array $record
134-
* @param array $filters
127+
* @param array $record
128+
* @param array $filters
135129
* @return bool
136130
*/
137131
private function matchesFilters($record, $filters)
@@ -148,7 +142,7 @@ private function matchesFilters($record, $filters)
148142
/**
149143
* Pluck and return the primary keys of the given results.
150144
*
151-
* @param mixed $results
145+
* @param mixed $results
152146
* @return \Illuminate\Support\Collection
153147
*/
154148
public function mapIds($results)
@@ -159,9 +153,8 @@ public function mapIds($results)
159153
/**
160154
* Map the given results to instances of the given model.
161155
*
162-
* @param mixed $results
163-
* @param \Illuminate\Database\Eloquent\Model $model
164-
*
156+
* @param mixed $results
157+
* @param \Illuminate\Database\Eloquent\Model $model
165158
* @return Collection
166159
*/
167160
public function map(Builder $builder, $results, $model)
@@ -184,7 +177,6 @@ public function map(Builder $builder, $results, $model)
184177
/**
185178
* Map the given results to instances of the given model via a lazy collection.
186179
*
187-
* @param \Laravel\Scout\Builder $builder
188180
* @param mixed $results
189181
* @param \Illuminate\Database\Eloquent\Model $model
190182
* @return \Illuminate\Support\LazyCollection
@@ -211,8 +203,7 @@ public function lazyMap(Builder $builder, $results, $model)
211203
/**
212204
* Get the total count from a raw result returned by the engine.
213205
*
214-
* @param mixed $results
215-
*
206+
* @param mixed $results
216207
* @return int
217208
*/
218209
public function getTotalCount($results)
@@ -235,7 +226,6 @@ public function flush($model)
235226
* Create a search index.
236227
*
237228
* @param string $name
238-
* @param array $options
239229
* @return mixed
240230
*/
241231
public function createIndex($name, array $options = [])
@@ -249,7 +239,6 @@ public function createIndex($name, array $options = [])
249239
* @param string $name
250240
* @return mixed
251241
*/
252-
253242
public function deleteIndex($name)
254243
{
255244
$this->store->deleteIndex($name);

0 commit comments

Comments
 (0)