diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 0a6b589..e617b29 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -26,7 +26,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 id: composer-cache with: path: ${{ steps.composer-cache-dir.outputs.dir }} @@ -38,14 +38,14 @@ jobs: run: composer install --no-interaction --prefer-dist - name: Check code style - run: vendor/bin/ecs + run: vendor/bin/php-cs-fixer fix --dry-run phpstan: runs-on: ubuntu-latest steps: - name: Checkout project - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -58,7 +58,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 id: composer-cache with: path: ${{ steps.composer-cache-dir.outputs.dir }} @@ -79,11 +79,11 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '8.1', '8.2', '8.3', '8.4' ] + php-version: ['8.3', '8.4', '8.5' ] steps: - name: Checkout project - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -96,7 +96,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 id: composer-cache with: path: ${{ steps.composer-cache-dir.outputs.dir }} @@ -120,14 +120,14 @@ jobs: fail-fast: false matrix: include: - - opensearch-version: '1' - opensearch-composer-version: '^1' - opensearch-version: '2' opensearch-composer-version: '^2' + - opensearch-version: '3' + opensearch-composer-version: '^2' steps: - name: Checkout project - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -140,7 +140,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 id: composer-cache with: path: ${{ steps.composer-cache-dir.outputs.dir }} diff --git a/composer.json b/composer.json index 69984ff..9bb5dcf 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,10 @@ "name": "smoench/opensearch-dsl", "description": "OpenSearch DSL library", "type": "library", - "homepage": "http://ongr.io", "license": "MIT", "authors": [ { - "name": "ONGR team", - "homepage": "http://www.ongr.io" + "name": "ONGR team" }, { "name": "Handcrafted in the Alps Team", @@ -19,15 +17,15 @@ } ], "require": { - "php": "8.1.* || 8.2.* || 8.3.* || 8.4.*", - "opensearch-project/opensearch-php": "^1.0 || ^2.3.1" + "php": "8.3.* || 8.4.* || 8.5.*", + "opensearch-project/opensearch-php": "^2.3.1" }, "require-dev": { - "phpunit/phpunit": "^10.5.40", - "phpstan/phpstan": "1.12.14", - "phpstan/phpstan-phpunit": "1.4.2", - "rector/rector": "^1.2.10", - "symplify/easy-coding-standard": "^12.5.5" + "phpunit/phpunit": "^12.5.2", + "phpstan/phpstan": "2.1.33", + "phpstan/phpstan-phpunit": "2.0.10", + "rector/rector": "2.2.14", + "friendsofphp/php-cs-fixer": "3.91.3" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php deleted file mode 100644 index b5f8fb5..0000000 --- a/ecs.php +++ /dev/null @@ -1,30 +0,0 @@ -parallel(); - - $ecsConfig->paths([ - __DIR__ . '/src', - __DIR__ . '/tests' - ]); - - $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [ - 'syntax' => 'short', - ]); - - $ecsConfig->sets([ - SetList::ARRAY, - SetList::DOCBLOCK, - SetList::NAMESPACES, - SetList::PHPUNIT, - SetList::PSR_12, - SetList::SPACES, - SetList::STRICT, - ]); -}; diff --git a/rector.php b/rector.php index e2264b7..6b53b6f 100644 --- a/rector.php +++ b/rector.php @@ -12,7 +12,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests' + __DIR__ . '/tests', ]); // register a single rule @@ -24,8 +24,8 @@ ]); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, - PHPUnitSetList::PHPUNIT_100, + LevelSetList::UP_TO_PHP_83, + PHPUnitSetList::PHPUNIT_120, SetList::CODE_QUALITY, ]); }; diff --git a/src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php b/src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php index e1e3107..93c2879 100644 --- a/src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php +++ b/src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php @@ -26,7 +26,7 @@ class AdjacencyMatrixAggregation extends AbstractAggregation { use BucketingTrait; - final public const FILTERS = 'filters'; + final public const string FILTERS = 'filters'; /** * @var array> diff --git a/src/Aggregation/Bucketing/DateRangeAggregation.php b/src/Aggregation/Bucketing/DateRangeAggregation.php index 3a581c9..95039e6 100644 --- a/src/Aggregation/Bucketing/DateRangeAggregation.php +++ b/src/Aggregation/Bucketing/DateRangeAggregation.php @@ -101,7 +101,7 @@ public function addRange($from = null, $to = null, $key = null) 'to' => $to, 'key' => $key, ], - fn ($v) => null !== $v + fn($v) => null !== $v ); if ($range === []) { diff --git a/src/Aggregation/Bucketing/FilterAggregation.php b/src/Aggregation/Bucketing/FilterAggregation.php index 084753b..5cc24b8 100644 --- a/src/Aggregation/Bucketing/FilterAggregation.php +++ b/src/Aggregation/Bucketing/FilterAggregation.php @@ -50,6 +50,7 @@ public function getFilter(): ?BuilderInterface return $this->filter; } + #[\Override] public function setField($field): static { throw new LogicException("Filter aggregation, doesn't support `field` parameter"); diff --git a/src/Aggregation/Bucketing/GlobalAggregation.php b/src/Aggregation/Bucketing/GlobalAggregation.php index d5fdf9b..e8faefc 100644 --- a/src/Aggregation/Bucketing/GlobalAggregation.php +++ b/src/Aggregation/Bucketing/GlobalAggregation.php @@ -27,6 +27,7 @@ class GlobalAggregation extends AbstractAggregation { use BucketingTrait; + #[\Override] public function setField($field): static { throw new LogicException("Global aggregation, doesn't support `field` parameter"); diff --git a/src/Aggregation/Bucketing/HistogramAggregation.php b/src/Aggregation/Bucketing/HistogramAggregation.php index ef0b029..9ce0957 100644 --- a/src/Aggregation/Bucketing/HistogramAggregation.php +++ b/src/Aggregation/Bucketing/HistogramAggregation.php @@ -26,9 +26,9 @@ class HistogramAggregation extends AbstractAggregation { use BucketingTrait; - final public const DIRECTION_ASC = 'asc'; + final public const string DIRECTION_ASC = 'asc'; - final public const DIRECTION_DESC = 'desc'; + final public const string DIRECTION_DESC = 'desc'; private ?int $interval = null; @@ -161,7 +161,7 @@ public function getArray(): array 'keyed' => $this->isKeyed(), 'order' => $this->getOrder(), ], - fn ($val) => $val || is_numeric($val) + fn($val) => $val || is_numeric($val) ); $this->checkRequiredParameters($out, ['field', 'interval']); diff --git a/src/Aggregation/Bucketing/SignificantTermsAggregation.php b/src/Aggregation/Bucketing/SignificantTermsAggregation.php index 1b32d76..7a49282 100644 --- a/src/Aggregation/Bucketing/SignificantTermsAggregation.php +++ b/src/Aggregation/Bucketing/SignificantTermsAggregation.php @@ -20,6 +20,7 @@ */ class SignificantTermsAggregation extends TermsAggregation { + #[\Override] public function getType(): string { return 'significant_terms'; diff --git a/src/Aggregation/Bucketing/SignificantTextAggregation.php b/src/Aggregation/Bucketing/SignificantTextAggregation.php index b955977..2ebdb09 100644 --- a/src/Aggregation/Bucketing/SignificantTextAggregation.php +++ b/src/Aggregation/Bucketing/SignificantTextAggregation.php @@ -20,6 +20,7 @@ */ class SignificantTextAggregation extends TermsAggregation { + #[\Override] public function getType(): string { return 'significant_text'; diff --git a/src/Aggregation/Metric/AvgAggregation.php b/src/Aggregation/Metric/AvgAggregation.php index 6d31401..62655bd 100644 --- a/src/Aggregation/Metric/AvgAggregation.php +++ b/src/Aggregation/Metric/AvgAggregation.php @@ -20,6 +20,7 @@ */ class AvgAggregation extends StatsAggregation { + #[\Override] public function getType(): string { return 'avg'; diff --git a/src/Aggregation/Metric/CardinalityAggregation.php b/src/Aggregation/Metric/CardinalityAggregation.php index f37c922..5ee9bd4 100644 --- a/src/Aggregation/Metric/CardinalityAggregation.php +++ b/src/Aggregation/Metric/CardinalityAggregation.php @@ -41,7 +41,7 @@ public function getArray(): array 'precision_threshold' => $this->getPrecisionThreshold(), 'rehash' => $this->isRehash(), ], - fn ($val) => $val || is_bool($val) + fn($val) => $val || is_bool($val) ); $this->checkRequiredFields($out); diff --git a/src/Aggregation/Metric/ExtendedStatsAggregation.php b/src/Aggregation/Metric/ExtendedStatsAggregation.php index 1b81b29..806bedf 100644 --- a/src/Aggregation/Metric/ExtendedStatsAggregation.php +++ b/src/Aggregation/Metric/ExtendedStatsAggregation.php @@ -79,7 +79,7 @@ public function getArray(): array 'script' => $this->getScript(), 'sigma' => $this->getSigma(), ], - fn ($val) => $val || is_numeric($val) + fn($val) => $val || is_numeric($val) ); } } diff --git a/src/Aggregation/Metric/MaxAggregation.php b/src/Aggregation/Metric/MaxAggregation.php index 4dbb0b1..a69635e 100644 --- a/src/Aggregation/Metric/MaxAggregation.php +++ b/src/Aggregation/Metric/MaxAggregation.php @@ -20,6 +20,7 @@ */ class MaxAggregation extends StatsAggregation { + #[\Override] public function getType(): string { return 'max'; diff --git a/src/Aggregation/Metric/MinAggregation.php b/src/Aggregation/Metric/MinAggregation.php index e58e714..f1144fc 100644 --- a/src/Aggregation/Metric/MinAggregation.php +++ b/src/Aggregation/Metric/MinAggregation.php @@ -20,6 +20,7 @@ */ class MinAggregation extends StatsAggregation { + #[\Override] public function getType(): string { return 'min'; diff --git a/src/Aggregation/Metric/PercentileRanksAggregation.php b/src/Aggregation/Metric/PercentileRanksAggregation.php index 9305002..a1f749c 100644 --- a/src/Aggregation/Metric/PercentileRanksAggregation.php +++ b/src/Aggregation/Metric/PercentileRanksAggregation.php @@ -88,7 +88,7 @@ public function getArray(): array 'values' => $this->getValues(), 'compression' => $this->getCompression(), ], - fn ($val) => $val || is_numeric($val) + fn($val) => $val || is_numeric($val) ); $this->isRequiredParametersSet($out); diff --git a/src/Aggregation/Metric/PercentilesAggregation.php b/src/Aggregation/Metric/PercentilesAggregation.php index dcbeda2..0868ad7 100644 --- a/src/Aggregation/Metric/PercentilesAggregation.php +++ b/src/Aggregation/Metric/PercentilesAggregation.php @@ -85,7 +85,7 @@ public function getArray(): array 'field' => $this->getField(), 'script' => $this->getScript(), ], - fn ($val) => $val || is_numeric($val) + fn($val) => $val || is_numeric($val) ); $this->isRequiredParametersSet($out); diff --git a/src/Aggregation/Metric/SumAggregation.php b/src/Aggregation/Metric/SumAggregation.php index 6b7a771..b0501cf 100644 --- a/src/Aggregation/Metric/SumAggregation.php +++ b/src/Aggregation/Metric/SumAggregation.php @@ -20,6 +20,7 @@ */ class SumAggregation extends StatsAggregation { + #[\Override] public function getType(): string { return 'sum'; diff --git a/src/Aggregation/Metric/TopHitsAggregation.php b/src/Aggregation/Metric/TopHitsAggregation.php index 6f883b7..2a5b421 100644 --- a/src/Aggregation/Metric/TopHitsAggregation.php +++ b/src/Aggregation/Metric/TopHitsAggregation.php @@ -132,7 +132,7 @@ public function getArray(): array|stdClass 'size' => $this->getSize(), 'from' => $this->getFrom(), ], - static fn ($value) => $value !== null + static fn($value) => $value !== null ); return $output === [] ? new stdClass() : $output; diff --git a/src/Aggregation/Metric/ValueCountAggregation.php b/src/Aggregation/Metric/ValueCountAggregation.php index 44767a9..6aebd43 100644 --- a/src/Aggregation/Metric/ValueCountAggregation.php +++ b/src/Aggregation/Metric/ValueCountAggregation.php @@ -20,6 +20,7 @@ */ class ValueCountAggregation extends StatsAggregation { + #[\Override] public function getType(): string { return 'value_count'; diff --git a/src/Aggregation/Pipeline/BucketScriptAggregation.php b/src/Aggregation/Pipeline/BucketScriptAggregation.php index 195cfcd..8a351d0 100644 --- a/src/Aggregation/Pipeline/BucketScriptAggregation.php +++ b/src/Aggregation/Pipeline/BucketScriptAggregation.php @@ -47,6 +47,7 @@ public function getType(): string return 'bucket_script'; } + #[\Override] public function getArray(): array { if ($this->getScript() === null) { diff --git a/src/Aggregation/Pipeline/BucketSelectorAggregation.php b/src/Aggregation/Pipeline/BucketSelectorAggregation.php index 49ecdb8..dcbfd18 100644 --- a/src/Aggregation/Pipeline/BucketSelectorAggregation.php +++ b/src/Aggregation/Pipeline/BucketSelectorAggregation.php @@ -20,6 +20,7 @@ */ class BucketSelectorAggregation extends BucketScriptAggregation { + #[\Override] public function getType(): string { return 'bucket_selector'; diff --git a/src/Aggregation/Pipeline/BucketSortAggregation.php b/src/Aggregation/Pipeline/BucketSortAggregation.php index 6e4aaf4..e04e6c0 100644 --- a/src/Aggregation/Pipeline/BucketSortAggregation.php +++ b/src/Aggregation/Pipeline/BucketSortAggregation.php @@ -46,6 +46,7 @@ public function getType(): string return 'bucket_sort'; } + #[\Override] public function getArray(): array { return array_filter( diff --git a/src/Aggregation/Pipeline/PercentilesBucketAggregation.php b/src/Aggregation/Pipeline/PercentilesBucketAggregation.php index da4aef4..63ab893 100644 --- a/src/Aggregation/Pipeline/PercentilesBucketAggregation.php +++ b/src/Aggregation/Pipeline/PercentilesBucketAggregation.php @@ -45,6 +45,7 @@ public function setPercents(array $percents) return $this; } + #[\Override] public function getArray(): array { $data = [ diff --git a/src/BuilderBag.php b/src/BuilderBag.php index fc77a73..e1c9d19 100644 --- a/src/BuilderBag.php +++ b/src/BuilderBag.php @@ -85,7 +85,7 @@ public function all(?string $type = null): array { return array_filter( $this->bag, - static fn (BuilderInterface $builder) => $type === null || $builder->getType() === $type + static fn(BuilderInterface $builder) => $type === null || $builder->getType() === $type ); } diff --git a/src/FieldCollapse/FieldCollapse.php b/src/FieldCollapse/FieldCollapse.php index b615bf3..5b186fb 100644 --- a/src/FieldCollapse/FieldCollapse.php +++ b/src/FieldCollapse/FieldCollapse.php @@ -19,8 +19,7 @@ class FieldCollapse implements BuilderInterface public function __construct( private readonly string $field - ) { - } + ) {} public function addInnerHits(InnerHits $innerHits): self { @@ -42,7 +41,7 @@ public function toArray(): array|stdClass if ($this->innerHits !== []) { $array['inner_hits'] = array_map( - static fn (InnerHits $innerHits) => $innerHits->toArray(), + static fn(InnerHits $innerHits) => $innerHits->toArray(), $this->innerHits ); } diff --git a/src/FieldCollapse/InnerHits.php b/src/FieldCollapse/InnerHits.php index 3fc6dec..15357f1 100644 --- a/src/FieldCollapse/InnerHits.php +++ b/src/FieldCollapse/InnerHits.php @@ -15,8 +15,7 @@ class InnerHits implements BuilderInterface public function __construct( private readonly string $name, - ) { - } + ) {} public function setFieldCollapse(FieldCollapse $collapse): self { diff --git a/src/InnerHit/ParentInnerHit.php b/src/InnerHit/ParentInnerHit.php index 0f82da0..5ff30c4 100644 --- a/src/InnerHit/ParentInnerHit.php +++ b/src/InnerHit/ParentInnerHit.php @@ -6,6 +6,7 @@ class ParentInnerHit extends NestedInnerHit { + #[\Override] public function getType(): string { return 'parent'; diff --git a/src/ParametersTrait.php b/src/ParametersTrait.php index ea7e404..d67d486 100644 --- a/src/ParametersTrait.php +++ b/src/ParametersTrait.php @@ -13,15 +13,13 @@ namespace OpenSearchDSL; -use stdClass; - /** * A trait which handles the behavior of parameters in queries, filters, etc. */ trait ParametersTrait { /** - * @var array + * @var array */ private array $parameters = []; @@ -39,20 +37,20 @@ public function removeParameter(string $name): static return $this; } - public function getParameter(string $name): array|string|int|float|bool|stdClass + public function getParameter(string $name): array|string|int|float|bool|object { return $this->parameters[$name]; } /** - * @return array + * @return array */ public function getParameters(): array { return $this->parameters; } - public function addParameter(string $name, array|string|int|float|bool|stdClass $value): static + public function addParameter(string $name, array|string|int|float|bool|object $value): static { $this->parameters[$name] = $value; diff --git a/src/Query/Compound/BoolQuery.php b/src/Query/Compound/BoolQuery.php index 1cb537c..ec1ac76 100644 --- a/src/Query/Compound/BoolQuery.php +++ b/src/Query/Compound/BoolQuery.php @@ -27,13 +27,13 @@ class BoolQuery implements BuilderInterface { use ParametersTrait; - final public const MUST = 'must'; + final public const string MUST = 'must'; - final public const MUST_NOT = 'must_not'; + final public const string MUST_NOT = 'must_not'; - final public const SHOULD = 'should'; + final public const string SHOULD = 'should'; - final public const FILTER = 'filter'; + final public const string FILTER = 'filter'; /** * @var array> diff --git a/src/Query/Compound/BoostingQuery.php b/src/Query/Compound/BoostingQuery.php index 4c9ba48..da3a547 100644 --- a/src/Query/Compound/BoostingQuery.php +++ b/src/Query/Compound/BoostingQuery.php @@ -26,8 +26,7 @@ public function __construct( private readonly BuilderInterface $positive, private readonly BuilderInterface $negative, private readonly float|int $negativeBoost - ) { - } + ) {} public function getType(): string { diff --git a/src/Query/Compound/FunctionScoreQuery.php b/src/Query/Compound/FunctionScoreQuery.php index feeb76d..afc8ca8 100644 --- a/src/Query/Compound/FunctionScoreQuery.php +++ b/src/Query/Compound/FunctionScoreQuery.php @@ -168,8 +168,8 @@ public function addScriptScoreFunction( ) { $function = [ 'script_score' => [ - 'script' => - array_filter( + 'script' + => array_filter( array_merge( [ 'lang' => 'painless', diff --git a/src/Query/FullText/MatchPhrasePrefixQuery.php b/src/Query/FullText/MatchPhrasePrefixQuery.php index 50b8376..af7336a 100644 --- a/src/Query/FullText/MatchPhrasePrefixQuery.php +++ b/src/Query/FullText/MatchPhrasePrefixQuery.php @@ -21,6 +21,7 @@ */ class MatchPhrasePrefixQuery extends MatchQuery { + #[\Override] public function getType(): string { return 'match_phrase_prefix'; diff --git a/src/Query/FullText/MatchPhraseQuery.php b/src/Query/FullText/MatchPhraseQuery.php index b39c1e7..0cbf7b6 100644 --- a/src/Query/FullText/MatchPhraseQuery.php +++ b/src/Query/FullText/MatchPhraseQuery.php @@ -21,6 +21,7 @@ */ class MatchPhraseQuery extends MatchQuery { + #[\Override] public function getType(): string { return 'match_phrase'; diff --git a/src/Query/Geo/GeoShapeQuery.php b/src/Query/Geo/GeoShapeQuery.php index 6bf2f21..8a8f792 100644 --- a/src/Query/Geo/GeoShapeQuery.php +++ b/src/Query/Geo/GeoShapeQuery.php @@ -25,13 +25,13 @@ class GeoShapeQuery implements BuilderInterface { use ParametersTrait; - final public const INTERSECTS = 'intersects'; + final public const string INTERSECTS = 'intersects'; - final public const DISJOINT = 'disjoint'; + final public const string DISJOINT = 'disjoint'; - final public const WITHIN = 'within'; + final public const string WITHIN = 'within'; - final public const CONTAINS = 'contains'; + final public const string CONTAINS = 'contains'; private array $fields = []; diff --git a/src/Query/Span/SpanContainingQuery.php b/src/Query/Span/SpanContainingQuery.php index e6ab488..1725ffa 100644 --- a/src/Query/Span/SpanContainingQuery.php +++ b/src/Query/Span/SpanContainingQuery.php @@ -27,8 +27,7 @@ class SpanContainingQuery implements SpanQueryInterface public function __construct( private readonly SpanQueryInterface $little, private readonly SpanQueryInterface $big - ) { - } + ) {} public function getLittle(): SpanQueryInterface { diff --git a/src/Query/Span/SpanNearQuery.php b/src/Query/Span/SpanNearQuery.php index 15ccd13..4c0edd1 100644 --- a/src/Query/Span/SpanNearQuery.php +++ b/src/Query/Span/SpanNearQuery.php @@ -42,11 +42,13 @@ public function setSlop($slop) return $this; } + #[\Override] public function getType(): string { return 'span_near'; } + #[\Override] public function toArray(): array { $query = []; diff --git a/src/Query/Span/SpanQueryInterface.php b/src/Query/Span/SpanQueryInterface.php index 3080c35..2ff0101 100644 --- a/src/Query/Span/SpanQueryInterface.php +++ b/src/Query/Span/SpanQueryInterface.php @@ -18,6 +18,4 @@ /** * Interface SpanQueryInterface to recognise span queries. */ -interface SpanQueryInterface extends BuilderInterface -{ -} +interface SpanQueryInterface extends BuilderInterface {} diff --git a/src/Query/Span/SpanTermQuery.php b/src/Query/Span/SpanTermQuery.php index 5c0a310..b0fe92c 100644 --- a/src/Query/Span/SpanTermQuery.php +++ b/src/Query/Span/SpanTermQuery.php @@ -22,6 +22,7 @@ */ class SpanTermQuery extends TermQuery implements SpanQueryInterface { + #[\Override] public function getType(): string { return 'span_term'; diff --git a/src/Query/Span/SpanWithinQuery.php b/src/Query/Span/SpanWithinQuery.php index 287e91f..0e91c9d 100644 --- a/src/Query/Span/SpanWithinQuery.php +++ b/src/Query/Span/SpanWithinQuery.php @@ -20,6 +20,7 @@ */ class SpanWithinQuery extends SpanContainingQuery { + #[\Override] public function getType(): string { return 'span_within'; diff --git a/src/Query/TermLevel/ExistsQuery.php b/src/Query/TermLevel/ExistsQuery.php index acd3417..f7d1805 100644 --- a/src/Query/TermLevel/ExistsQuery.php +++ b/src/Query/TermLevel/ExistsQuery.php @@ -27,8 +27,7 @@ class ExistsQuery implements BuilderInterface */ public function __construct( private $field - ) { - } + ) {} public function getType(): string { diff --git a/src/Query/TermLevel/RangeQuery.php b/src/Query/TermLevel/RangeQuery.php index 3356e40..7288a36 100644 --- a/src/Query/TermLevel/RangeQuery.php +++ b/src/Query/TermLevel/RangeQuery.php @@ -28,13 +28,13 @@ class RangeQuery implements BuilderInterface /** * Range control names. */ - final public const LT = 'lt'; + final public const string LT = 'lt'; - final public const GT = 'gt'; + final public const string GT = 'gt'; - final public const LTE = 'lte'; + final public const string LTE = 'lte'; - final public const GTE = 'gte'; + final public const string GTE = 'gte'; /** * @param string $field diff --git a/src/Query/TermLevel/TermsSetQuery.php b/src/Query/TermLevel/TermsSetQuery.php index 16868f1..df3c882 100644 --- a/src/Query/TermLevel/TermsSetQuery.php +++ b/src/Query/TermLevel/TermsSetQuery.php @@ -26,9 +26,9 @@ class TermsSetQuery implements BuilderInterface { use ParametersTrait; - final public const MINIMUM_SHOULD_MATCH_TYPE_FIELD = 'minimum_should_match_field'; + final public const string MINIMUM_SHOULD_MATCH_TYPE_FIELD = 'minimum_should_match_field'; - final public const MINIMUM_SHOULD_MATCH_TYPE_SCRIPT = 'minimum_should_match_script'; + final public const string MINIMUM_SHOULD_MATCH_TYPE_SCRIPT = 'minimum_should_match_script'; /** * @param string $field Field name @@ -65,8 +65,8 @@ public function toArray(): array private function validateParameters(array $parameters) { if ( - ! isset($parameters[self::MINIMUM_SHOULD_MATCH_TYPE_FIELD]) && - ! isset($parameters[self::MINIMUM_SHOULD_MATCH_TYPE_SCRIPT]) + ! isset($parameters[self::MINIMUM_SHOULD_MATCH_TYPE_FIELD]) + && ! isset($parameters[self::MINIMUM_SHOULD_MATCH_TYPE_SCRIPT]) ) { $message = "Either minimum_should_match_field or minimum_should_match_script must be set."; throw new InvalidArgumentException($message); diff --git a/src/Query/TermLevel/TypeQuery.php b/src/Query/TermLevel/TypeQuery.php index 4407b22..ff83ff9 100644 --- a/src/Query/TermLevel/TypeQuery.php +++ b/src/Query/TermLevel/TypeQuery.php @@ -27,8 +27,7 @@ class TypeQuery implements BuilderInterface */ public function __construct( private $type - ) { - } + ) {} public function getType(): string { diff --git a/src/SearchEndpoint/AbstractSearchEndpoint.php b/src/SearchEndpoint/AbstractSearchEndpoint.php index 5c40bcd..2b534d1 100644 --- a/src/SearchEndpoint/AbstractSearchEndpoint.php +++ b/src/SearchEndpoint/AbstractSearchEndpoint.php @@ -36,12 +36,10 @@ abstract class AbstractSearchEndpoint extends AbstractNormalizable implements Se public function add(BuilderInterface $builder, ?string $key = null): string { - if (array_key_exists($key, $this->container)) { - throw new OverflowException(sprintf('Builder with %s name for endpoint has already been added!', $key)); - } - if (! $key) { $key = bin2hex(random_bytes(30)); + } elseif (array_key_exists($key, $this->container)) { + throw new OverflowException(sprintf('Builder with %s name for endpoint has already been added!', $key)); } $this->container[$key] = $builder; diff --git a/src/SearchEndpoint/CollapseEndpoint.php b/src/SearchEndpoint/CollapseEndpoint.php index 1eb7264..8656b52 100644 --- a/src/SearchEndpoint/CollapseEndpoint.php +++ b/src/SearchEndpoint/CollapseEndpoint.php @@ -26,6 +26,7 @@ public function normalize(): ?array return null; } + #[\Override] public function add(BuilderInterface $builder, ?string $key = null): string { if (! $builder instanceof FieldCollapse) { @@ -45,6 +46,7 @@ public function add(BuilderInterface $builder, ?string $key = null): string return $this->key; } + #[\Override] public function getAll(?string $boolType = null): array { return [ diff --git a/src/SearchEndpoint/HighlightEndpoint.php b/src/SearchEndpoint/HighlightEndpoint.php index c4f49d8..2f9cf51 100644 --- a/src/SearchEndpoint/HighlightEndpoint.php +++ b/src/SearchEndpoint/HighlightEndpoint.php @@ -38,6 +38,7 @@ public function normalize(): ?array return null; } + #[\Override] public function add(BuilderInterface $builder, ?string $key = null): string { if (! $builder instanceof Highlight) { @@ -57,6 +58,7 @@ public function add(BuilderInterface $builder, ?string $key = null): string return $this->key; } + #[\Override] public function getAll(?string $boolType = null): array { return [ diff --git a/src/SearchEndpoint/PostFilterEndpoint.php b/src/SearchEndpoint/PostFilterEndpoint.php index 479b6a7..01bd95f 100644 --- a/src/SearchEndpoint/PostFilterEndpoint.php +++ b/src/SearchEndpoint/PostFilterEndpoint.php @@ -23,11 +23,13 @@ class PostFilterEndpoint extends QueryEndpoint */ final public const NAME = 'post_filter'; + #[\Override] public function normalize(): ?array { return $this->getBool()?->toArray(); } + #[\Override] public function getOrder(): int { return 1; diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php index d1e61fb..7abf9a7 100644 --- a/src/SearchEndpoint/QueryEndpoint.php +++ b/src/SearchEndpoint/QueryEndpoint.php @@ -43,6 +43,7 @@ public function normalize(): ?array return $this->bool?->toArray(); } + #[\Override] public function add(BuilderInterface $builder, ?string $key = null): string { return $this->addToBool($builder, BoolQuery::MUST, $key); @@ -53,7 +54,7 @@ public function addToBool( string $boolType = BoolQuery::MUST, ?string $key = null ): string { - if (! $this->bool instanceof \OpenSearchDSL\Query\Compound\BoolQuery) { + if (! $this->bool instanceof BoolQuery) { $this->bool = new BoolQuery(); } @@ -70,6 +71,7 @@ public function getBool(): ?BoolQuery return $this->bool; } + #[\Override] public function getAll(?string $boolType = null): array { return $this->bool->getQueries($boolType); diff --git a/src/Serializer/OrderedSerializer.php b/src/Serializer/OrderedSerializer.php index 3cfdbcf..7142655 100644 --- a/src/Serializer/OrderedSerializer.php +++ b/src/Serializer/OrderedSerializer.php @@ -56,7 +56,7 @@ private function order(array $data) if (! empty($filteredData)) { uasort( $filteredData, - fn (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) => $a->getOrder() <=> $b->getOrder() + fn(OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) => $a->getOrder() <=> $b->getOrder() ); return array_merge($filteredData, array_diff_key($data, $filteredData)); @@ -76,7 +76,7 @@ private function filterOrderable($array) { return array_filter( $array, - fn ($value) => $value instanceof OrderedNormalizerInterface + fn($value) => $value instanceof OrderedNormalizerInterface ); } } diff --git a/src/Sort/FieldSort.php b/src/Sort/FieldSort.php index a20de4c..784a520 100644 --- a/src/Sort/FieldSort.php +++ b/src/Sort/FieldSort.php @@ -24,9 +24,9 @@ class FieldSort implements BuilderInterface { use ParametersTrait; - final public const ASC = 'asc'; + final public const string ASC = 'asc'; - final public const DESC = 'desc'; + final public const string DESC = 'desc'; private ?BuilderInterface $nestedFilter = null; diff --git a/tests/Functional/Query/FunctionScoreQueryTest.php b/tests/Functional/Query/FunctionScoreQueryTest.php index 8823be6..74edf75 100644 --- a/tests/Functional/Query/FunctionScoreQueryTest.php +++ b/tests/Functional/Query/FunctionScoreQueryTest.php @@ -20,6 +20,7 @@ class FunctionScoreQueryTest extends AbstractOpenSearchTestCase { + #[\Override] protected function getDataArray() { return [ diff --git a/tests/Functional/Query/MatchAllQueryTest.php b/tests/Functional/Query/MatchAllQueryTest.php index 22f94b6..daa3447 100644 --- a/tests/Functional/Query/MatchAllQueryTest.php +++ b/tests/Functional/Query/MatchAllQueryTest.php @@ -19,6 +19,7 @@ class MatchAllQueryTest extends AbstractOpenSearchTestCase { + #[\Override] protected function getDataArray() { return [ diff --git a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php index 4d39afc..793f494 100644 --- a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php @@ -15,7 +15,6 @@ use OpenSearchDSL\Aggregation\Bucketing\AdjacencyMatrixAggregation; use OpenSearchDSL\BuilderInterface; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -40,7 +39,7 @@ class AdjacencyMatrixAggregationTest extends TestCase */ public function testFiltersAggregationGetArray() { - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $aggregation = new AdjacencyMatrixAggregation('test_agg'); $aggregation->addFilter('name', $mock); $result = $aggregation->getArray(); @@ -63,10 +62,8 @@ public function testFiltersAggregationGetType() public function testToArray() { $aggregation = new AdjacencyMatrixAggregation('test_agg'); - $filter = $this->getMockBuilder(BuilderInterface::class) - ->onlyMethods(['toArray', 'getType']) - ->getMockForAbstractClass(); - $filter->expects($this->any()) + $filter = $this->createStub(BuilderInterface::class); + $filter ->method('toArray') ->willReturn([ 'test_field' => [ @@ -102,10 +99,8 @@ public function testToArray() */ public function testFilterConstructor() { - /** @var BuilderInterface|MockObject $builderInterface1 */ - $builderInterface1 = $this->getMockForAbstractClass(BuilderInterface::class); - /** @var BuilderInterface|MockObject $builderInterface2 */ - $builderInterface2 = $this->getMockForAbstractClass(BuilderInterface::class); + $builderInterface1 = $this->createStub(BuilderInterface::class); + $builderInterface2 = $this->createStub(BuilderInterface::class); $aggregation = new AdjacencyMatrixAggregation( 'test', diff --git a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php index 1ef9451..5367b2d 100644 --- a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php @@ -48,7 +48,7 @@ public function testChildrenAggregationGetType() */ public function testChildrenAggregationGetArray() { - $mock = $this->createMock(AbstractAggregation::class); + $mock = $this->createStub(AbstractAggregation::class); $mock->method('getName')->willReturn('abstract'); $aggregation = new ChildrenAggregation('foo'); diff --git a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php index 56a465b..c1acc51 100644 --- a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php @@ -48,7 +48,7 @@ public function testDateHistogramAggregationGetType() */ public function testChildrenAggregationGetArray() { - $mock = $this->createMock(AbstractAggregation::class); + $mock = $this->createStub(AbstractAggregation::class); $mock->method('getName')->willReturn('abstract'); $aggregation = new DateHistogramAggregation('foo'); diff --git a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php index 8007130..8ea0c07 100644 --- a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php @@ -16,7 +16,6 @@ use LogicException; use OpenSearchDSL\Aggregation\Bucketing\FiltersAggregation; use OpenSearchDSL\BuilderInterface; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -31,7 +30,7 @@ public function testIfExceptionIsThrown() { $this->expectException(LogicException::class); $this->expectExceptionMessage("In not anonymous filters filter name must be set."); - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $aggregation = new FiltersAggregation('test_agg'); $aggregation->addFilter($mock); } @@ -41,7 +40,7 @@ public function testIfExceptionIsThrown() */ public function testFiltersAggregationGetArray() { - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $aggregation = new FiltersAggregation('test_agg'); $aggregation->setAnonymous(true); $aggregation->addFilter($mock, 'name'); @@ -65,10 +64,8 @@ public function testFiltersAggregationGetType() public function testToArray() { $aggregation = new FiltersAggregation('test_agg'); - $filter = $this->getMockBuilder(BuilderInterface::class) - ->onlyMethods(['toArray', 'getType']) - ->getMockForAbstractClass(); - $filter->expects($this->any()) + $filter = $this->createStub(BuilderInterface::class); + $filter ->method('toArray') ->willReturn([ 'test_field' => [ @@ -103,10 +100,8 @@ public function testToArray() */ public function testConstructorFilter() { - /** @var BuilderInterface|MockObject $builderInterface1 */ - $builderInterface1 = $this->getMockForAbstractClass(BuilderInterface::class); - /** @var BuilderInterface|MockObject $builderInterface2 */ - $builderInterface2 = $this->getMockForAbstractClass(BuilderInterface::class); + $builderInterface1 = $this->createStub(BuilderInterface::class); + $builderInterface2 = $this->createStub(BuilderInterface::class); $aggregation = new FiltersAggregation( 'test', diff --git a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php index aaee698..468a670 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php @@ -15,6 +15,7 @@ use LogicException; use OpenSearchDSL\Aggregation\Bucketing\GeoDistanceAggregation; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class GeoDistanceAggregationTest extends TestCase @@ -84,10 +85,10 @@ public static function getGeoDistanceAggregationGetArrayDataProvider(): iterable * Tests getArray method. * * @param array $filterData - * @param array $expected + * @param array $expectedResults */ - #[\PHPUnit\Framework\Attributes\DataProvider('getGeoDistanceAggregationGetArrayDataProvider')] - public function testGeoDistanceAggregationGetArray($filterData, $expected) + #[DataProvider('getGeoDistanceAggregationGetArrayDataProvider')] + public function testGeoDistanceAggregationGetArray($filterData, $expectedResults) { $aggregation = new GeoDistanceAggregation('foo'); $aggregation->setOrigin($filterData['origin']); @@ -97,7 +98,7 @@ public function testGeoDistanceAggregationGetArray($filterData, $expected) $aggregation->addRange($filterData['ranges'][0], $filterData['ranges'][1]); $result = $aggregation->getArray(); - $this->assertEquals($result, $expected); + $this->assertEquals($result, $expectedResults); } /** diff --git a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php index 4dd02a7..c94927f 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php @@ -15,6 +15,7 @@ use LogicException; use OpenSearchDSL\Aggregation\Bucketing\GeoHashGridAggregation; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -57,10 +58,10 @@ public static function getArrayDataProvider(): iterable * Tests getArray method. * * @param array $filterData - * @param array $expected + * @param array $expectedResults */ - #[\PHPUnit\Framework\Attributes\DataProvider('getArrayDataProvider')] - public function testGeoHashGridAggregationGetArray($filterData, $expected) + #[DataProvider('getArrayDataProvider')] + public function testGeoHashGridAggregationGetArray($filterData, $expectedResults) { $aggregation = new GeoHashGridAggregation('foo'); $aggregation->setPrecision($filterData['precision']); @@ -69,7 +70,7 @@ public function testGeoHashGridAggregationGetArray($filterData, $expected) $aggregation->setField($filterData['field']); $result = $aggregation->getArray(); - $this->assertEquals($result, $expected); + $this->assertEquals($result, $expectedResults); } /** diff --git a/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php index 18853ca..820fb48 100644 --- a/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php @@ -37,7 +37,7 @@ public function testSignificantTermsAggregationGetType() */ public function testSignificantTermsAggregationGetArray() { - $mock = $this->createMock(AbstractAggregation::class); + $mock = $this->createStub(AbstractAggregation::class); $mock->method('getName')->willReturn('abstract'); $aggregation = new SignificantTermsAggregation('foo', 'title'); diff --git a/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php index 65e03a1..6631ab8 100644 --- a/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php @@ -37,7 +37,7 @@ public function testSignificantTextAggregationGetType() */ public function testSignificantTermsAggregationGetArray() { - $mock = $this->createMock(AbstractAggregation::class); + $mock = $this->createStub(AbstractAggregation::class); $mock->method('getName')->willReturn('abstract'); $aggregation = new SignificantTextAggregation('foo', 'title'); diff --git a/tests/Unit/BuilderBagTest.php b/tests/Unit/BuilderBagTest.php index 861d29f..fec82dd 100644 --- a/tests/Unit/BuilderBagTest.php +++ b/tests/Unit/BuilderBagTest.php @@ -15,7 +15,7 @@ use OpenSearchDSL\BuilderBag; use OpenSearchDSL\NamedBuilderInterface; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; class BuilderBagTest extends TestCase @@ -78,12 +78,9 @@ public function testGet() $this->assertNotEmpty($bag->get($builderName)); } - private function getBuilder(string $name): MockObject&NamedBuilderInterface + private function getBuilder(string $name): Stub&NamedBuilderInterface { - $friendlyBuilderMock = $this->getMockBuilder(NamedBuilderInterface::class) - ->onlyMethods(['getName', 'toArray', 'getType']) - ->disableOriginalConstructor() - ->getMock(); + $friendlyBuilderMock = $this->createStub(NamedBuilderInterface::class); $friendlyBuilderMock ->method('getName') diff --git a/tests/Unit/ParametersTraitTest.php b/tests/Unit/ParametersTraitTest.php index 573220f..6d5fad5 100644 --- a/tests/Unit/ParametersTraitTest.php +++ b/tests/Unit/ParametersTraitTest.php @@ -22,7 +22,7 @@ class ParametersTraitTest extends TestCase protected function setUp(): void { - $this->parametersTraitMock = new class() { + $this->parametersTraitMock = new class { use ParametersTrait; }; } diff --git a/tests/Unit/Query/Compound/BoostingQueryTest.php b/tests/Unit/Query/Compound/BoostingQueryTest.php index bbfeb72..5064ae6 100644 --- a/tests/Unit/Query/Compound/BoostingQueryTest.php +++ b/tests/Unit/Query/Compound/BoostingQueryTest.php @@ -24,9 +24,8 @@ class BoostingQueryTest extends TestCase */ public function testToArray() { - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $mock - ->expects($this->any()) ->method('toArray') ->willReturn([ 'term' => [ diff --git a/tests/Unit/Query/Compound/ConstantScoreQueryTest.php b/tests/Unit/Query/Compound/ConstantScoreQueryTest.php index c7829af..6dd7569 100644 --- a/tests/Unit/Query/Compound/ConstantScoreQueryTest.php +++ b/tests/Unit/Query/Compound/ConstantScoreQueryTest.php @@ -24,9 +24,8 @@ class ConstantScoreQueryTest extends TestCase */ public function testToArray() { - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $mock - ->expects($this->any()) ->method('toArray') ->willReturn([ 'term' => [ diff --git a/tests/Unit/Query/Compound/DisMaxQueryTest.php b/tests/Unit/Query/Compound/DisMaxQueryTest.php index 1eac31e..ec8cec4 100644 --- a/tests/Unit/Query/Compound/DisMaxQueryTest.php +++ b/tests/Unit/Query/Compound/DisMaxQueryTest.php @@ -24,9 +24,8 @@ class DisMaxQueryTest extends TestCase */ public function testToArray() { - $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $mock = $this->createStub(BuilderInterface::class); $mock - ->expects($this->any()) ->method('toArray') ->willReturn([ 'term' => [ diff --git a/tests/Unit/Query/Compound/FunctionScoreQueryTest.php b/tests/Unit/Query/Compound/FunctionScoreQueryTest.php index c935ae1..062987c 100644 --- a/tests/Unit/Query/Compound/FunctionScoreQueryTest.php +++ b/tests/Unit/Query/Compound/FunctionScoreQueryTest.php @@ -16,7 +16,7 @@ use OpenSearchDSL\BuilderInterface; use OpenSearchDSL\Query\Compound\FunctionScoreQuery; use OpenSearchDSL\Query\MatchAllQuery; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -62,16 +62,10 @@ public static function addRandomFunctionProvider() ]; } - /** - * Tests addRandomFunction method. - * - * @param array $expectedArray - */ - #[\PHPUnit\Framework\Attributes\DataProvider('addRandomFunctionProvider')] - public function testAddRandomFunction(mixed $seed, $expectedArray) + #[DataProvider('addRandomFunctionProvider')] + public function testAddRandomFunction(mixed $seed, array $expectedArray) { - /** @var MatchAllQuery|MockObject $matchAllQuery */ - $matchAllQuery = $this->getMockBuilder(MatchAllQuery::class)->getMock(); + $matchAllQuery = $this->createStub(MatchAllQuery::class); $functionScoreQuery = new FunctionScoreQuery($matchAllQuery); $functionScoreQuery->addRandomFunction($seed); @@ -86,8 +80,7 @@ public function testAddRandomFunction(mixed $seed, $expectedArray) */ public function testAddFieldValueFactorFunction() { - /** @var BuilderInterface|MockObject $builderInterface */ - $builderInterface = $this->getMockForAbstractClass(BuilderInterface::class); + $builderInterface = $this->createStub(BuilderInterface::class); $functionScoreQuery = new FunctionScoreQuery($builderInterface); $functionScoreQuery->addFieldValueFactorFunction('field1', 2); $functionScoreQuery->addFieldValueFactorFunction('field2', 1.5, 'ln'); diff --git a/tests/Unit/Query/Joining/HasChildQueryTest.php b/tests/Unit/Query/Joining/HasChildQueryTest.php index 70dbbcf..300daca 100644 --- a/tests/Unit/Query/Joining/HasChildQueryTest.php +++ b/tests/Unit/Query/Joining/HasChildQueryTest.php @@ -24,7 +24,7 @@ class HasChildQueryTest extends TestCase */ public function testConstructor() { - $parentQuery = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $parentQuery = $this->createStub(BuilderInterface::class); $query = new HasChildQuery('test_type', $parentQuery, ['test_parameter1']); $this->assertEquals(['test_parameter1'], $query->getParameters()); } diff --git a/tests/Unit/Query/Joining/HasParentQueryTest.php b/tests/Unit/Query/Joining/HasParentQueryTest.php index 098f38b..1544ec0 100644 --- a/tests/Unit/Query/Joining/HasParentQueryTest.php +++ b/tests/Unit/Query/Joining/HasParentQueryTest.php @@ -24,7 +24,7 @@ class HasParentQueryTest extends TestCase */ public function testConstructor() { - $parentQuery = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $parentQuery = $this->createStub(BuilderInterface::class); $query = new HasParentQuery('test_type', $parentQuery, ['test_parameter1']); $this->assertEquals(['test_parameter1'], $query->getParameters()); } diff --git a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php index 23bbbc4..471fa1c 100644 --- a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php +++ b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php @@ -34,7 +34,7 @@ public function testItCanBeInstantiated() public function testEndpointGetter() { $hitName = 'foo'; - $innerHit = $this->getMockBuilder(BuilderInterface::class)->getMock(); + $innerHit = $this->createStub(BuilderInterface::class); $endpoint = new InnerHitsEndpoint(); $endpoint->add($innerHit, $hitName); $builders = $endpoint->getAll(); @@ -48,12 +48,9 @@ public function testEndpointGetter() */ public function testNormalization() { - $innerHit = $this - ->getMockBuilder(NamedBuilderInterface::class) - ->onlyMethods(['getName', 'toArray', 'getType']) - ->getMock(); - $innerHit->expects($this->any())->method('getName')->willReturn('foo'); - $innerHit->expects($this->any())->method('toArray')->willReturn([ + $innerHit = $this->createStub(NamedBuilderInterface::class); + $innerHit->method('getName')->willReturn('foo'); + $innerHit->method('toArray')->willReturn([ 'foo' => 'bar', ]); diff --git a/tests/Unit/SearchEndpoint/QueryEndpointTest.php b/tests/Unit/SearchEndpoint/QueryEndpointTest.php index 0b5e985..9d2e497 100644 --- a/tests/Unit/SearchEndpoint/QueryEndpointTest.php +++ b/tests/Unit/SearchEndpoint/QueryEndpointTest.php @@ -14,6 +14,7 @@ namespace OpenSearchDSL\Tests\Unit\SearchEndpoint; use OpenSearchDSL\Query\MatchAllQuery; +use OpenSearchDSL\Query\TermLevel\TermsQuery; use OpenSearchDSL\SearchEndpoint\QueryEndpoint; use PHPUnit\Framework\TestCase; @@ -68,4 +69,62 @@ public function testEndpointGetter() $this->assertCount(1, $builders); $this->assertSame($query, $builders[$queryName]); } + + public function testSearchForFilterQueryReference(): void + { + $instance = new QueryEndpoint(); + $instance->add(new TermsQuery('foo', ['bla'])); + + $instance->addReference('filter_query', new TermsQuery('foo', ['bar'])); + + self::assertSame( + [ + 'bool' => [ + 'must' => [[ + 'terms' => [ + 'foo' => [ + 'bla', + ], + ], + ], + ], + 'filter' => [ + [ + 'terms' => [ + 'foo' => [ + 'bar', + ], + ], + ], + ], + ], + ], + $instance->normalize() + ); + + self::assertSame( + [ + 'bool' => [ + 'must' => [[ + 'terms' => [ + 'foo' => [ + 'bla', + ], + ], + ], + ], + 'filter' => [ + [ + 'terms' => [ + 'foo' => [ + 'bar', + ], + ], + ], + ], + ], + ], + $instance->normalize() + ); + } }