Skip to content

Commit

Permalink
Merge pull request #237 from hkulekci/laravel-v10-support
Browse files Browse the repository at this point in the history
laravel version 10 support
  • Loading branch information
matchish authored Feb 24, 2023
2 parents 0d306e4 + cf74377 commit 23ad700
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^6.17|^7.0|^8.0",
"php-http/guzzle7-adapter": "^1.0",
"phpunit/phpunit": "~9.4.0"
"phpunit/phpunit": "^9.4.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/Engines/ElasticSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 14 additions & 8 deletions tests/Integration/Engines/ElasticSearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand 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) {
Expand All @@ -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' => [
Expand Down

0 comments on commit 23ad700

Please sign in to comment.