From 36bd2f327c8285fe2cbb110dfff9b6ebe17b009d Mon Sep 17 00:00:00 2001 From: Haydar Kulekci Date: Mon, 20 Feb 2023 19:19:26 +0300 Subject: [PATCH 1/3] laravel version 10 support --- composer.json | 8 ++++---- src/Engines/ElasticSearchEngine.php | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index fc4abd96..b22ec21f 100644 --- a/composer.json +++ b/composer.json @@ -19,15 +19,15 @@ "php": "^8.0.12|^8.1", "elasticsearch/elasticsearch": "^8.0", "handcraftedinthealps/elasticsearch-dsl": "^8.0", - "laravel/scout": "^8.0|^9.0", + "laravel/scout": "^8.0|^9.0|^10.x-dev", "roave/better-reflection": "^4.3|^5.0" }, "require-dev": { "laravel/legacy-factories": "^1.0", - "nunomaduro/larastan": "~0.6", - "orchestra/testbench": "^6.18", + "nunomaduro/larastan": "^2.4", + "orchestra/testbench": "^8.0", "php-http/guzzle7-adapter": "^1.0", - "phpunit/phpunit": "~9.4.0" + "phpunit/phpunit": "^9.4.0" }, "autoload-dev": { "psr-4": { diff --git a/src/Engines/ElasticSearchEngine.php b/src/Engines/ElasticSearchEngine.php index d2bdca14..96942538 100644 --- a/src/Engines/ElasticSearchEngine.php +++ b/src/Engines/ElasticSearchEngine.php @@ -2,6 +2,7 @@ namespace Matchish\ScoutElasticSearch\Engines; +use Elastic\Elasticsearch\Client; use Elastic\Elasticsearch\Exception\ServerResponseException; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\LazyCollection; @@ -22,17 +23,17 @@ final class ElasticSearchEngine extends Engine /** * The ElasticSearch client. * - * @var \Elastic\Elasticsearch\Client + * @var Client */ protected $elasticsearch; /** * Create a new engine instance. * - * @param \Elastic\Elasticsearch\Client $elasticsearch + * @param Client $elasticsearch * @return void */ - public function __construct(\Elastic\Elasticsearch\Client $elasticsearch) + public function __construct(Client $elasticsearch) { $this->elasticsearch = $elasticsearch; } From e3890ee504a4dba7bcffe253c05944066c2d6127 Mon Sep 17 00:00:00 2001 From: Haydar Kulekci Date: Fri, 24 Feb 2023 02:16:51 +0300 Subject: [PATCH 2/3] orchestra/testbench version change --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b22ec21f..3e5f0f20 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require-dev": { "laravel/legacy-factories": "^1.0", "nunomaduro/larastan": "^2.4", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^6.17|^7.0|^8.0", "php-http/guzzle7-adapter": "^1.0", "phpunit/phpunit": "^9.4.0" }, From cf7437759532f874f53da21c251b8854fea78b41 Mon Sep 17 00:00:00 2001 From: Haydar Kulekci Date: Fri, 24 Feb 2023 16:24:32 +0300 Subject: [PATCH 3/3] phpunit deprecation changes made on tests according to https://github.com/sebastianbergmann/phpunit/issues/5062 issue. And also, some changes for warning of code structure --- tests/Feature/SearchTest.php | 2 +- .../Engines/ElasticSearchEngineTest.php | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/Feature/SearchTest.php b/tests/Feature/SearchTest.php index cd21b549..6f0a57ac 100644 --- a/tests/Feature/SearchTest.php +++ b/tests/Feature/SearchTest.php @@ -143,7 +143,7 @@ public function test_mixed_no_results() public function test_mixed_cursor() { $this->expectException(\Error::class); - $this->expectErrorMessage('Not implemented for MixedSearch'); + $this->expectExceptionMessage('Not implemented for MixedSearch'); Artisan::call('scout:import'); $mixed = MixedSearch::search('*')->within( diff --git a/tests/Integration/Engines/ElasticSearchEngineTest.php b/tests/Integration/Engines/ElasticSearchEngineTest.php index fad4af78..f208e7f5 100644 --- a/tests/Integration/Engines/ElasticSearchEngineTest.php +++ b/tests/Integration/Engines/ElasticSearchEngineTest.php @@ -78,7 +78,7 @@ public function test_update_throw_exception_on_elasticsearch_error() $this->engine->update($models); } - public function test_delete() + public function test_delete(): void { $models = Product::all(); $this->engine->update($models); @@ -94,14 +94,17 @@ public function test_delete() ], ], ]; - $response = $this->elasticsearch->search($params); + $response = $this->elasticsearch->search($params)->asArray(); + $this->assertArrayHasKey('hits', $response); + $this->assertArrayHasKey('total', $response['hits']); + $this->assertArrayHasKey('value', $response['hits']['total']); $this->assertEquals(1, $response['hits']['total']['value']); foreach ($response['hits']['hits'] as $doc) { $this->assertEquals($shouldBeNotDeleted->getScoutKey(), $doc['_id']); } } - public function test_flush() + public function test_flush(): void { $models = Product::all(); $this->engine->update($models); @@ -116,11 +119,14 @@ public function test_flush() ], ], ]; - $response = $this->elasticsearch->search($params); + $response = $this->elasticsearch->search($params)->asArray(); + $this->assertArrayHasKey('hits', $response); + $this->assertArrayHasKey('total', $response['hits']); + $this->assertArrayHasKey('value', $response['hits']['total']); $this->assertEquals(0, $response['hits']['total']['value']); } - public function test_map_with_custom_key_name() + public function test_map_with_custom_key_name(): void { $this->app['config']['scout.key'] = 'custom_key'; $models = Product::all(); @@ -134,7 +140,7 @@ public function test_map_with_custom_key_name() $this->assertEquals($models->map->id->all(), $mappedModels->map->id->all()); } - public function test_lazy_map() + public function test_lazy_map(): void { $models = Product::all(); $keys = $models->map(function ($product) { @@ -147,10 +153,10 @@ public function test_lazy_map() $this->assertEquals($models->map->id->all(), $mappedModels->map->id->all()); } - public function test_lazy_map_for_mixed_search() + public function test_lazy_map_for_mixed_search(): void { - $this->expectErrorMessage('Not implemented for MixedSearch'); $this->expectException(\Error::class); + $this->expectExceptionMessage('Not implemented for MixedSearch'); $models = Product::all(); $keys = $models->map(function ($product) { return ['_id' => $product->getScoutKey(), '_source' => [