From e4ae5c65da25425056b1b1f798607a8fe7ee281e Mon Sep 17 00:00:00 2001 From: Ivan Babenko Date: Mon, 27 May 2024 19:46:41 +0200 Subject: [PATCH] Merge master --- src/Factories/SearchParametersFactory.php | 44 +++++++++---------- tests/Integration/Engine/EngineSearchTest.php | 8 ---- .../Factories/SearchParametersFactoryTest.php | 8 ---- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/Factories/SearchParametersFactory.php b/src/Factories/SearchParametersFactory.php index 11affb1..d6cee11 100644 --- a/src/Factories/SearchParametersFactory.php +++ b/src/Factories/SearchParametersFactory.php @@ -69,32 +69,28 @@ protected function makeFilter(Builder $builder): ?array 'term' => [$field => $value], ])->values(); - if (property_exists($builder, 'whereIns')) { - $whereIns = collect($builder->whereIns)->map(static fn (array $values, string $field) => [ - 'terms' => [$field => $values], - ])->values(); - - if ($whereIns->isNotEmpty()) { - $filter->push([ - 'bool' => [ - 'must' => $whereIns->all(), - ], - ]); - } + $whereIns = collect($builder->whereIns)->map(static fn (array $values, string $field) => [ + 'terms' => [$field => $values], + ])->values(); + + if ($whereIns->isNotEmpty()) { + $filter->push([ + 'bool' => [ + 'must' => $whereIns->all(), + ], + ]); } - if (property_exists($builder, 'whereNotIns')) { - $whereNotIns = collect($builder->whereNotIns)->map(static fn (array $values, string $field) => [ - 'terms' => [$field => $values], - ])->values(); - - if ($whereNotIns->isNotEmpty()) { - $filter->push([ - 'bool' => [ - 'must_not' => $whereNotIns->all(), - ], - ]); - } + $whereNotIns = collect($builder->whereNotIns)->map(static fn (array $values, string $field) => [ + 'terms' => [$field => $values], + ])->values(); + + if ($whereNotIns->isNotEmpty()) { + $filter->push([ + 'bool' => [ + 'must_not' => $whereNotIns->all(), + ], + ]); } return $filter->isEmpty() ? null : $filter->all(); diff --git a/tests/Integration/Engine/EngineSearchTest.php b/tests/Integration/Engine/EngineSearchTest.php index 17330f9..6b4587c 100644 --- a/tests/Integration/Engine/EngineSearchTest.php +++ b/tests/Integration/Engine/EngineSearchTest.php @@ -66,10 +66,6 @@ public function test_search_result_can_be_filtered_with_where_clause(): void public function test_search_result_can_be_filtered_with_where_in_clause(): void { - if (!method_exists(Builder::class, 'whereIn')) { - $this->markTestSkipped('Method "whereIn" is not supported by current Scout version'); - } - // add some mixins factory(Client::class, rand(2, 10))->create(); @@ -82,10 +78,6 @@ public function test_search_result_can_be_filtered_with_where_in_clause(): void public function test_search_result_can_be_filtered_with_where_not_in_clause(): void { - if (!method_exists(Builder::class, 'whereNotIn')) { - $this->markTestSkipped('Method "whereNotIn" is not supported by current Scout version'); - } - // add some mixins factory(Client::class, rand(2, 10))->create(['email' => 'foo@test.com']); diff --git a/tests/Integration/Factories/SearchParametersFactoryTest.php b/tests/Integration/Factories/SearchParametersFactoryTest.php index a8eb4a8..8d4d603 100644 --- a/tests/Integration/Factories/SearchParametersFactoryTest.php +++ b/tests/Integration/Factories/SearchParametersFactoryTest.php @@ -86,10 +86,6 @@ public function test_search_parameters_can_be_made_from_builder_with_where_filte public function test_search_parameters_can_be_made_from_builder_with_where_in_filter(): void { - if (!method_exists(Builder::class, 'whereIn')) { - $this->markTestSkipped('Method "whereIn" is not supported by current Scout version'); - } - $model = new Client(); $builder = (new Builder($model, 'book'))->whereIn('author_id', [1, 2]); $searchParameters = $this->searchParametersFactory->makeFromBuilder($builder); @@ -119,10 +115,6 @@ public function test_search_parameters_can_be_made_from_builder_with_where_in_fi public function test_search_parameters_can_be_made_from_builder_with_where_not_in_filter(): void { - if (!method_exists(Builder::class, 'whereNotIn')) { - $this->markTestSkipped('Method "whereNotIn" is not supported by current Scout version'); - } - $model = new Client(); $builder = (new Builder($model, 'book'))->whereNotIn('author_id', [1, 2]); $searchParameters = $this->searchParametersFactory->makeFromBuilder($builder);