From c5e6d8c4cd3bf9510773765f2c13534145f82024 Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 24 Mar 2024 17:33:38 +0300 Subject: [PATCH 1/8] Add strict types to Aggregation namespace --- src/Aggregation/AbstractAggregation.php | 2 ++ src/Aggregation/AbstractSimpleAggregation.php | 2 ++ src/Aggregation/AbstractTermsAggregation.php | 2 ++ src/Aggregation/AdjacencyMatrix.php | 2 ++ src/Aggregation/AutoDateHistogram.php | 2 ++ src/Aggregation/Avg.php | 2 ++ src/Aggregation/AvgBucket.php | 2 ++ src/Aggregation/BucketScript.php | 2 ++ src/Aggregation/BucketSelector.php | 2 ++ src/Aggregation/Cardinality.php | 2 ++ src/Aggregation/Children.php | 2 ++ src/Aggregation/Composite.php | 2 ++ src/Aggregation/CumulativeSum.php | 2 ++ src/Aggregation/DateHistogram.php | 2 ++ src/Aggregation/DateRange.php | 2 ++ src/Aggregation/Derivative.php | 2 ++ src/Aggregation/DiversifiedSampler.php | 2 ++ src/Aggregation/ExtendedStats.php | 2 ++ src/Aggregation/ExtendedStatsBucket.php | 2 ++ src/Aggregation/Filter.php | 2 ++ src/Aggregation/Filters.php | 2 ++ src/Aggregation/GapPolicyInterface.php | 2 ++ src/Aggregation/GeoBounds.php | 2 ++ src/Aggregation/GeoCentroid.php | 2 ++ src/Aggregation/GeoDistance.php | 2 ++ src/Aggregation/GeohashGrid.php | 4 +++- src/Aggregation/GeotileGridAggregation.php | 2 ++ src/Aggregation/GlobalAggregation.php | 2 ++ src/Aggregation/Histogram.php | 2 ++ src/Aggregation/IpRange.php | 2 ++ src/Aggregation/Max.php | 2 ++ src/Aggregation/Min.php | 2 ++ src/Aggregation/Missing.php | 2 ++ src/Aggregation/Nested.php | 2 ++ src/Aggregation/NormalizeAggregation.php | 2 ++ src/Aggregation/ParentAggregation.php | 2 ++ src/Aggregation/Percentiles.php | 2 ++ src/Aggregation/PercentilesBucket.php | 2 ++ src/Aggregation/Range.php | 2 ++ src/Aggregation/ReverseNested.php | 2 ++ src/Aggregation/Sampler.php | 2 ++ src/Aggregation/ScriptedMetric.php | 2 ++ src/Aggregation/SerialDiff.php | 2 ++ src/Aggregation/SignificantTerms.php | 2 ++ src/Aggregation/Stats.php | 2 ++ src/Aggregation/StatsBucket.php | 2 ++ src/Aggregation/Sum.php | 2 ++ src/Aggregation/SumBucket.php | 2 ++ src/Aggregation/Terms.php | 2 ++ src/Aggregation/TopHits.php | 2 ++ src/Aggregation/Traits/BucketsPathTrait.php | 2 ++ src/Aggregation/Traits/GapPolicyTrait.php | 2 ++ src/Aggregation/Traits/KeyedTrait.php | 2 ++ src/Aggregation/Traits/MissingTrait.php | 2 ++ src/Aggregation/Traits/ShardSizeTrait.php | 2 ++ src/Aggregation/ValueCount.php | 2 ++ src/Aggregation/WeightedAvg.php | 2 ++ 57 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/Aggregation/AbstractAggregation.php b/src/Aggregation/AbstractAggregation.php index 0f06504016..914274396f 100644 --- a/src/Aggregation/AbstractAggregation.php +++ b/src/Aggregation/AbstractAggregation.php @@ -1,5 +1,7 @@ setParam('precision', $precision); diff --git a/src/Aggregation/GeotileGridAggregation.php b/src/Aggregation/GeotileGridAggregation.php index aa41687313..aa2b6ec2cc 100644 --- a/src/Aggregation/GeotileGridAggregation.php +++ b/src/Aggregation/GeotileGridAggregation.php @@ -1,5 +1,7 @@ Date: Sun, 24 Mar 2024 17:59:00 +0300 Subject: [PATCH 2/8] Add strict types to Query namespace --- src/Query/AbstractGeoDistance.php | 2 ++ src/Query/AbstractGeoShape.php | 2 ++ src/Query/AbstractQuery.php | 2 ++ src/Query/AbstractSpanQuery.php | 2 ++ src/Query/BoolQuery.php | 2 ++ src/Query/Boosting.php | 2 ++ src/Query/CombinedFields.php | 2 ++ src/Query/ConstantScore.php | 2 ++ src/Query/DisMax.php | 2 ++ src/Query/DistanceFeature.php | 2 ++ src/Query/Exists.php | 2 ++ src/Query/FunctionScore.php | 2 ++ src/Query/Fuzzy.php | 2 ++ src/Query/GeoBoundingBox.php | 2 ++ src/Query/GeoDistance.php | 2 ++ src/Query/GeoPolygon.php | 2 ++ src/Query/GeoShapePreIndexed.php | 2 ++ src/Query/GeoShapeProvided.php | 2 ++ src/Query/HasChild.php | 2 ++ src/Query/HasParent.php | 2 ++ src/Query/Ids.php | 2 ++ src/Query/InnerHits.php | 2 ++ src/Query/Limit.php | 2 ++ src/Query/MatchAll.php | 2 ++ src/Query/MatchNone.php | 2 ++ src/Query/MatchPhrase.php | 2 ++ src/Query/MatchPhrasePrefix.php | 2 ++ src/Query/MatchQuery.php | 2 ++ src/Query/MoreLikeThis.php | 2 ++ src/Query/MultiMatch.php | 2 ++ src/Query/Nested.php | 2 ++ src/Query/ParentId.php | 2 ++ src/Query/Percolate.php | 2 ++ src/Query/Prefix.php | 2 ++ src/Query/QueryString.php | 2 ++ src/Query/Range.php | 2 ++ src/Query/Regexp.php | 2 ++ src/Query/Script.php | 2 ++ src/Query/Simple.php | 2 ++ src/Query/SimpleQueryString.php | 2 ++ src/Query/SpanContaining.php | 2 ++ src/Query/SpanFirst.php | 2 ++ src/Query/SpanMulti.php | 2 ++ src/Query/SpanNear.php | 2 ++ src/Query/SpanNot.php | 2 ++ src/Query/SpanOr.php | 2 ++ src/Query/SpanTerm.php | 2 ++ src/Query/SpanWithin.php | 2 ++ src/Query/Term.php | 2 ++ src/Query/Terms.php | 4 +++- src/Query/TermsSet.php | 4 +++- src/Query/Wildcard.php | 2 ++ 52 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/Query/AbstractGeoDistance.php b/src/Query/AbstractGeoDistance.php index d2665743e3..627610c5d2 100644 --- a/src/Query/AbstractGeoDistance.php +++ b/src/Query/AbstractGeoDistance.php @@ -1,5 +1,7 @@ getParam($this->field); diff --git a/src/Query/TermsSet.php b/src/Query/TermsSet.php index ab52d42db0..68032be1ce 100644 --- a/src/Query/TermsSet.php +++ b/src/Query/TermsSet.php @@ -1,5 +1,7 @@ setMinimumShouldMatchScript($minimumShouldMatch); } else { - throw new \TypeError(\sprintf('Argument 3 passed to "%s()" must be of type %s|string, %s given.', __METHOD__, AbstractScript::class, \is_object($minimumShouldMatch) ? \get_class($minimumShouldMatch) : \gettype($minimumShouldMatch))); + throw new \TypeError(\sprintf('Argument 3 passed to "%s()" must be of type %s|string, %s given.', __METHOD__, AbstractScript::class, \is_object($minimumShouldMatch) ? $minimumShouldMatch::class : \gettype($minimumShouldMatch))); } } diff --git a/src/Query/Wildcard.php b/src/Query/Wildcard.php index 1bc20e13d9..e62f4180b2 100644 --- a/src/Query/Wildcard.php +++ b/src/Query/Wildcard.php @@ -1,5 +1,7 @@ Date: Sun, 24 Mar 2024 18:17:03 +0300 Subject: [PATCH 3/8] Add strict types to other namespace --- src/Bulk/Action.php | 2 ++ src/Bulk/Action/AbstractDocument.php | 2 ++ src/Bulk/Action/CreateDocument.php | 2 ++ src/Bulk/Action/DeleteDocument.php | 2 ++ src/Bulk/Action/IndexDocument.php | 2 ++ src/Bulk/Action/UpdateDocument.php | 2 ++ src/Bulk/Response.php | 2 ++ src/Bulk/ResponseSet.php | 2 ++ src/Client.php | 2 ++ src/Cluster/Health.php | 2 ++ src/Cluster/Health/Index.php | 2 ++ src/Cluster/Health/Shard.php | 2 ++ src/Cluster/Settings.php | 4 +++- src/Collapse/InnerHits.php | 2 ++ src/Exception/Bulk/Response/ActionException.php | 2 ++ src/Exception/Bulk/ResponseException.php | 2 ++ src/Exception/BulkException.php | 2 ++ src/Exception/ClientException.php | 2 ++ src/Exception/DeprecatedException.php | 2 ++ src/Exception/ExceptionInterface.php | 2 ++ src/Exception/InvalidException.php | 2 ++ src/Exception/NotFoundException.php | 2 ++ src/Exception/NotImplementedException.php | 2 ++ src/Exception/QueryBuilderException.php | 2 ++ src/Exception/RequestEntityTooLargeException.php | 2 ++ src/Exception/RuntimeException.php | 2 ++ src/Index/Recovery.php | 2 ++ src/Index/Settings.php | 8 +++++--- src/Index/Stats.php | 2 ++ src/Multi/MultiBuilder.php | 2 ++ src/Multi/MultiBuilderInterface.php | 2 ++ src/Multi/ResultSet.php | 2 ++ src/Multi/Search.php | 2 ++ src/Node/Info.php | 2 ++ src/Node/Stats.php | 2 ++ src/Processor/AbstractProcessor.php | 2 ++ src/Processor/AppendProcessor.php | 2 ++ src/Processor/AttachmentProcessor.php | 2 ++ src/Processor/BytesProcessor.php | 2 ++ src/Processor/ConvertProcessor.php | 2 ++ src/Processor/DateIndexNameProcessor.php | 2 ++ src/Processor/DateProcessor.php | 2 ++ src/Processor/DotExpanderProcessor.php | 2 ++ src/Processor/FailProcessor.php | 2 ++ src/Processor/ForeachProcessor.php | 4 +++- src/Processor/JoinProcessor.php | 2 ++ src/Processor/JsonProcessor.php | 2 ++ src/Processor/KvProcessor.php | 2 ++ src/Processor/LowercaseProcessor.php | 2 ++ src/Processor/RemoveProcessor.php | 2 ++ src/Processor/RenameProcessor.php | 2 ++ src/Processor/SetProcessor.php | 2 ++ src/Processor/SortProcessor.php | 2 ++ src/Processor/SplitProcessor.php | 2 ++ src/Processor/Traits/FieldTrait.php | 2 ++ src/Processor/Traits/IgnoreFailureTrait.php | 2 ++ src/Processor/Traits/IgnoreMissingTrait.php | 2 ++ src/Processor/Traits/TargetFieldTrait.php | 2 ++ src/Processor/TrimProcessor.php | 2 ++ src/Processor/UppercaseProcessor.php | 2 ++ src/QueryBuilder/DSL.php | 2 ++ src/QueryBuilder/DSL/Aggregation.php | 2 ++ src/QueryBuilder/DSL/Collapse.php | 2 ++ src/QueryBuilder/DSL/Query.php | 4 +++- src/QueryBuilder/DSL/Suggest.php | 2 ++ src/QueryBuilder/Facade.php | 2 ++ src/QueryBuilder/Version.php | 2 ++ src/QueryBuilder/Version/Latest.php | 2 ++ src/QueryBuilder/Version/Version700.php | 2 ++ src/Rescore/AbstractRescore.php | 2 ++ src/Rescore/Query.php | 2 ++ src/ResultSet/BuilderInterface.php | 2 ++ src/ResultSet/ChainProcessor.php | 2 ++ src/ResultSet/DefaultBuilder.php | 2 ++ src/ResultSet/ProcessingBuilder.php | 2 ++ src/ResultSet/ProcessorInterface.php | 2 ++ src/Script/AbstractScript.php | 2 ++ src/Script/Script.php | 2 ++ src/Script/ScriptFields.php | 2 ++ src/Script/ScriptId.php | 2 ++ src/Suggest/AbstractSuggest.php | 2 ++ .../CandidateGenerator/AbstractCandidateGenerator.php | 2 ++ src/Suggest/CandidateGenerator/DirectGenerator.php | 2 ++ src/Suggest/Completion.php | 2 ++ src/Suggest/Phrase.php | 2 ++ src/Suggest/Term.php | 2 ++ 86 files changed, 178 insertions(+), 6 deletions(-) diff --git a/src/Bulk/Action.php b/src/Bulk/Action.php index d74775888a..7f94d3d79c 100644 --- a/src/Bulk/Action.php +++ b/src/Bulk/Action.php @@ -1,5 +1,7 @@ get('number_of_replicas') ?? self::DEFAULT_NUMBER_OF_REPLICAS; + return (int) ($this->get('number_of_replicas') ?? self::DEFAULT_NUMBER_OF_REPLICAS); } /** @@ -195,7 +197,7 @@ public function getNumberOfReplicas(): int */ public function getNumberOfShards(): int { - return $this->get('number_of_shards') ?? self::DEFAULT_NUMBER_OF_SHARDS; + return (int) ($this->get('number_of_shards') ?? self::DEFAULT_NUMBER_OF_SHARDS); } /** diff --git a/src/Index/Stats.php b/src/Index/Stats.php index e986500355..93269b5703 100644 --- a/src/Index/Stats.php +++ b/src/Index/Stats.php @@ -1,5 +1,7 @@ setRawProcessor($processor); } else { - throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|array, %s given.', self::class, AbstractProcessor::class, \is_object($processor) ? \get_class($processor) : \gettype($processor))); + throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|array, %s given.', self::class, AbstractProcessor::class, \is_object($processor) ? $processor::class : \gettype($processor))); } } diff --git a/src/Processor/JoinProcessor.php b/src/Processor/JoinProcessor.php index d3d786b3fa..52ddcf6b1d 100644 --- a/src/Processor/JoinProcessor.php +++ b/src/Processor/JoinProcessor.php @@ -1,5 +1,7 @@ Date: Sun, 24 Mar 2024 18:33:38 +0300 Subject: [PATCH 4/8] Add strict types to root namespace --- src/AbstractUpdateAction.php | 2 ++ src/ArrayableInterface.php | 2 ++ src/Bulk.php | 2 ++ src/ClientConfiguration.php | 2 ++ src/Cluster.php | 2 ++ src/Collapse.php | 2 ++ src/Document.php | 2 ++ src/Index.php | 2 ++ src/IndexTemplate.php | 2 ++ src/Mapping.php | 2 ++ src/NameableInterface.php | 2 ++ src/Node.php | 2 ++ src/Param.php | 2 ++ src/Pipeline.php | 2 ++ src/PointInTime.php | 2 ++ src/Query.php | 2 ++ src/QueryBuilder.php | 2 ++ src/Reindex.php | 2 ++ src/Request.php | 2 ++ src/Result.php | 2 ++ src/ResultSet.php | 2 ++ src/Scroll.php | 2 ++ src/Search.php | 2 ++ src/SearchableInterface.php | 2 ++ src/Snapshot.php | 2 ++ src/Status.php | 6 +++--- src/Suggest.php | 2 ++ src/Task.php | 2 ++ src/Util.php | 6 ++++-- 29 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/AbstractUpdateAction.php b/src/AbstractUpdateAction.php index 6ddbf84163..508f63df84 100644 --- a/src/AbstractUpdateAction.php +++ b/src/AbstractUpdateAction.php @@ -1,5 +1,7 @@ getData(); - return \array_map(static function ($name): string { - return (string) $name; - }, \array_keys($data['indices'])); + return \array_map(static fn ($name): string => (string) $name, \array_keys($data['indices'])); } /** diff --git a/src/Suggest.php b/src/Suggest.php index dfe604b84b..1fa1536d9d 100644 --- a/src/Suggest.php +++ b/src/Suggest.php @@ -1,5 +1,7 @@ '%2F' - return false !== \strpos(\strtoupper($requestUri), '%2F'); + return \str_contains(\strtoupper($requestUri), '%2F'); } /** @@ -64,7 +66,7 @@ public static function escapeDateMath($requestUri) $escapedUriSegment = \str_replace(static::$dateMathSymbols, static::$escapedDateMathSymbols, $uriSegment); // '\\{' and '\\}' should not be escaped - if (false !== \strpos($uriSegment, '\\\\')) { + if (\str_contains($uriSegment, '\\\\')) { $escapedUriSegment = \str_replace(['\\\\%7B', '\\\\%7D'], ['\\\\{', '\\\\}'], $escapedUriSegment); } From 49a378a9f9cfab9040b49f5deb2054d57273ad98 Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 24 Mar 2024 18:43:32 +0300 Subject: [PATCH 5/8] Fix test and cast document ID to string --- src/Index.php | 2 +- tests/Base.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Index.php b/src/Index.php index 4f001e3a5f..f5a91e8749 100644 --- a/src/Index.php +++ b/src/Index.php @@ -297,7 +297,7 @@ public function getDocument($id, array $options = []): Document $data = []; } - $doc = new Document($id, $data, $this->getName()); + $doc = new Document((string) $id, $data, $this->getName()); $doc->setVersionParams($result); return $doc; diff --git a/tests/Base.php b/tests/Base.php index 6adf4d6209..e77ab3dd5e 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -46,11 +46,11 @@ protected static function showDeprecated(): void } /** - * @param array $params Additional configuration params. Host and Port are already set + * @param array $config Additional configuration params. Host and Port are already set */ - protected function _getClient(array $params = [], ?LoggerInterface $logger = null): Client + protected function _getClient(array $config = [], ?LoggerInterface $logger = null): Client { - $config = $params ?: [$this->_getHost().':'.$this->_getPort()]; + $config['hosts'] ??= [$this->_getHost().':'.$this->_getPort()]; $config['transport_config']['node_pool'] = $config['transport_config']['node_pool'] ?? new TraceableSimpleNodePool( new RoundRobin(), From 98334b861c9e796eb7fc9e9a824bb86fd9e32a38 Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 24 Mar 2024 18:49:46 +0300 Subject: [PATCH 6/8] Add strict types in tests --- .../AbstractSimpleAggregationTest.php | 2 ++ tests/Aggregation/AdjacencyMatrixTest.php | 2 ++ tests/Aggregation/AggregationMetadataTest.php | 2 ++ tests/Aggregation/AutoDateHistogramTest.php | 2 ++ tests/Aggregation/AvgBucketTest.php | 2 ++ tests/Aggregation/AvgTest.php | 2 ++ tests/Aggregation/BaseAggregationTest.php | 2 ++ tests/Aggregation/BucketScriptTest.php | 2 ++ tests/Aggregation/BucketSelectorTest.php | 2 ++ tests/Aggregation/CardinalityTest.php | 2 ++ tests/Aggregation/ChildrenTest.php | 2 ++ tests/Aggregation/CompositeTest.php | 2 ++ tests/Aggregation/CumulativeSumTest.php | 2 ++ tests/Aggregation/DateHistogramTest.php | 2 ++ tests/Aggregation/DateRangeTest.php | 2 ++ tests/Aggregation/DerivativeTest.php | 2 ++ tests/Aggregation/DiversifiedSamplerTest.php | 2 ++ tests/Aggregation/ExtendedStatsBucketTest.php | 2 ++ tests/Aggregation/ExtendedStatsTest.php | 2 ++ tests/Aggregation/FilterTest.php | 2 ++ tests/Aggregation/FiltersTest.php | 2 ++ tests/Aggregation/GeoBoundsTest.php | 2 ++ tests/Aggregation/GeoCentroidTest.php | 2 ++ tests/Aggregation/GeoDistanceTest.php | 2 ++ tests/Aggregation/GeohashGridTest.php | 2 ++ tests/Aggregation/GeotileGridAggregationTest.php | 2 ++ tests/Aggregation/GlobalAggregationTest.php | 2 ++ tests/Aggregation/HistogramTest.php | 2 ++ tests/Aggregation/IpRangeTest.php | 2 ++ tests/Aggregation/MaxTest.php | 2 ++ tests/Aggregation/MinTest.php | 2 ++ tests/Aggregation/MissingTest.php | 2 ++ tests/Aggregation/NestedTest.php | 2 ++ tests/Aggregation/NormalizeAggregationTest.php | 2 ++ tests/Aggregation/ParentAggregationTest.php | 2 ++ tests/Aggregation/PercentilesBucketTest.php | 2 ++ tests/Aggregation/PercentilesTest.php | 2 ++ tests/Aggregation/RangeTest.php | 2 ++ tests/Aggregation/ReverseNestedTest.php | 2 ++ tests/Aggregation/SamplerTest.php | 2 ++ tests/Aggregation/ScriptTest.php | 2 ++ tests/Aggregation/ScriptedMetricTest.php | 2 ++ tests/Aggregation/SerialDiffTest.php | 2 ++ tests/Aggregation/SignificantTermsTest.php | 2 ++ tests/Aggregation/StatsBucketTest.php | 2 ++ tests/Aggregation/StatsTest.php | 2 ++ tests/Aggregation/SumBucketTest.php | 2 ++ tests/Aggregation/SumTest.php | 2 ++ tests/Aggregation/TermsTest.php | 2 ++ tests/Aggregation/TopHitsTest.php | 2 ++ tests/Aggregation/ValueCountTest.php | 2 ++ tests/Aggregation/WeightedAvgTest.php | 2 ++ tests/Base.php | 4 +++- tests/BasePipeline.php | 2 ++ tests/Bulk/Action/AbstractDocumentTest.php | 2 ++ tests/Bulk/Action/UpdateDocumentTest.php | 14 ++++++++------ tests/Bulk/ActionTest.php | 2 ++ tests/Bulk/ResponseSetTest.php | 2 ++ tests/BulkTest.php | 16 +++++++++------- tests/ClientConfigurationTest.php | 2 ++ tests/ClientFunctionalTest.php | 4 +++- tests/ClientTest.php | 2 ++ tests/Cluster/Health/IndexTest.php | 2 ++ tests/Cluster/Health/ShardTest.php | 2 ++ tests/Cluster/HealthTest.php | 2 ++ tests/Cluster/SettingsTest.php | 2 ++ tests/ClusterTest.php | 2 ++ tests/Collapse/CollapseTest.php | 2 ++ tests/DeprecatedClassBase.php | 2 ++ tests/DocumentTest.php | 2 ++ tests/ExampleTest.php | 2 ++ tests/Exception/AbstractExceptionTest.php | 2 ++ .../Bulk/Response/ActionExceptionTest.php | 2 ++ tests/Exception/Bulk/ResponseExceptionTest.php | 2 ++ tests/Exception/BulkExceptionTest.php | 2 ++ tests/Exception/ClientExceptionTest.php | 2 ++ tests/Exception/InvalidExceptionTest.php | 2 ++ tests/Exception/NotFoundExceptionTest.php | 2 ++ tests/Exception/NotImplementedExceptionTest.php | 2 ++ tests/Exception/QueryBuilderExceptionTest.php | 2 ++ tests/Exception/RuntimeExceptionTest.php | 2 ++ tests/Index/RecoveryTest.php | 2 ++ tests/Index/SettingsTest.php | 2 ++ tests/Index/StatsTest.php | 2 ++ tests/IndexTemplateTest.php | 2 ++ tests/IndexTest.php | 2 ++ tests/JSONTest.php | 2 ++ tests/MappingTest.php | 2 ++ tests/Multi/MultiBuilderTest.php | 2 ++ tests/Multi/SearchTest.php | 2 ++ tests/Node/InfoTest.php | 2 ++ tests/NodeTest.php | 2 ++ tests/ParamTest.php | 2 ++ tests/PipelineTest.php | 2 ++ tests/PointInTimeTest.php | 2 ++ tests/Processor/AppendProcessorTest.php | 2 ++ tests/Processor/AttachmentProcessorTest.php | 2 ++ tests/Processor/BytesProcessorTest.php | 2 ++ tests/Processor/ConvertProcessorTest.php | 2 ++ tests/Processor/DateIndexNameProcessorTest.php | 2 ++ tests/Processor/DateProcessorTest.php | 2 ++ tests/Processor/DotExpanderProcessorTest.php | 2 ++ tests/Processor/FailProcessorTest.php | 2 ++ tests/Processor/ForeachProcessorTest.php | 2 ++ tests/Processor/JoinProcessorTest.php | 2 ++ tests/Processor/JsonProcessorTest.php | 2 ++ tests/Processor/KvProcessorTest.php | 2 ++ tests/Processor/LowercaseProcessorTest.php | 2 ++ tests/Processor/RemoveProcessorTest.php | 2 ++ tests/Processor/RenameProcessorTest.php | 2 ++ tests/Processor/SetProcessorTest.php | 2 ++ tests/Processor/SortProcessorTest.php | 2 ++ tests/Processor/SplitProcessorTest.php | 2 ++ tests/Processor/TrimProcessorTest.php | 2 ++ tests/Processor/UppercaseProcessorTest.php | 2 ++ tests/Query/BoolQueryTest.php | 2 ++ tests/Query/BoostingTest.php | 2 ++ tests/Query/CombinedFieldsQueryTest.php | 2 ++ tests/Query/ConstantScoreTest.php | 2 ++ tests/Query/DisMaxTest.php | 2 ++ tests/Query/DistanceFeatureTest.php | 2 ++ tests/Query/EscapeStringTest.php | 2 ++ tests/Query/ExistsTest.php | 2 ++ tests/Query/FunctionScoreTest.php | 2 ++ tests/Query/FuzzyTest.php | 2 ++ tests/Query/GeoBoundingBoxTest.php | 2 ++ tests/Query/GeoDistanceTest.php | 2 ++ tests/Query/GeoPolygonTest.php | 2 ++ tests/Query/GeoShapePreIndexedTest.php | 2 ++ tests/Query/GeoShapeProvidedTest.php | 2 ++ tests/Query/HasChildTest.php | 2 ++ tests/Query/HasParentTest.php | 2 ++ tests/Query/HighlightTest.php | 2 ++ tests/Query/IdsTest.php | 2 ++ tests/Query/InnerHitsTest.php | 2 ++ tests/Query/LimitTest.php | 2 ++ tests/Query/MatchAllTest.php | 2 ++ tests/Query/MatchNoneTest.php | 2 ++ tests/Query/MatchPhrasePrefixTest.php | 2 ++ tests/Query/MatchPhraseTest.php | 2 ++ tests/Query/MatchQueryTest.php | 2 ++ tests/Query/MoreLikeThisTest.php | 2 ++ tests/Query/MultiMatchTest.php | 2 ++ tests/Query/NestedTest.php | 2 ++ tests/Query/ParentIdTest.php | 2 ++ tests/Query/PercolateTest.php | 2 ++ tests/Query/PostFilterTest.php | 2 ++ tests/Query/PrefixTest.php | 2 ++ tests/Query/QueryStringTest.php | 4 +++- tests/Query/RangeTest.php | 2 ++ tests/Query/RegexpTest.php | 2 ++ tests/Query/RescoreTest.php | 2 ++ tests/Query/ScriptTest.php | 2 ++ tests/Query/SimpleQueryStringTest.php | 2 ++ tests/Query/SimpleTest.php | 2 ++ tests/Query/SpanContainingTest.php | 2 ++ tests/Query/SpanFirstTest.php | 2 ++ tests/Query/SpanMultiTest.php | 2 ++ tests/Query/SpanNearTest.php | 2 ++ tests/Query/SpanNotTest.php | 2 ++ tests/Query/SpanOrTest.php | 2 ++ tests/Query/SpanTermTest.php | 2 ++ tests/Query/SpanWithinTest.php | 2 ++ tests/Query/TermTest.php | 2 ++ tests/Query/TermsSetTest.php | 2 ++ tests/Query/TermsTest.php | 2 ++ tests/Query/WildcardTest.php | 2 ++ tests/QueryBuilder/DSL/AbstractDSLTest.php | 4 +++- tests/QueryBuilder/DSL/AggregationTest.php | 2 ++ tests/QueryBuilder/DSL/CollapseTest.php | 2 ++ tests/QueryBuilder/DSL/QueryTest.php | 2 ++ tests/QueryBuilder/DSL/SuggestTest.php | 2 ++ tests/QueryBuilder/VersionTest.php | 10 ++++++---- tests/QueryBuilderTest.php | 2 ++ tests/QueryTest.php | 2 ++ tests/ReindexTest.php | 2 ++ tests/ResponseFunctionalTest.php | 2 ++ tests/ResponseTest.php | 2 ++ tests/ResultSet/BuilderTest.php | 2 ++ tests/ResultSet/ChainProcessorTest.php | 2 ++ tests/ResultSet/ProcessingBuilderTest.php | 2 ++ tests/ResultSetTest.php | 2 ++ tests/ResultTest.php | 2 ++ tests/Script/ScriptFieldsTest.php | 2 ++ tests/Script/ScriptIdTest.php | 2 ++ tests/Script/ScriptTest.php | 2 ++ tests/ScrollTest.php | 2 ++ tests/SearchTest.php | 2 ++ tests/SnapshotTest.php | 2 ++ tests/StatusTest.php | 6 +++--- tests/Suggest/CompletionTest.php | 2 ++ tests/Suggest/PhraseTest.php | 2 ++ tests/Suggest/TermTest.php | 2 ++ tests/SuggestTest.php | 2 ++ tests/TaskTest.php | 2 ++ tests/UtilTest.php | 2 ++ tests/bootstrap.php | 2 ++ 197 files changed, 416 insertions(+), 24 deletions(-) diff --git a/tests/Aggregation/AbstractSimpleAggregationTest.php b/tests/Aggregation/AbstractSimpleAggregationTest.php index 2580fb5822..2e2740917a 100644 --- a/tests/Aggregation/AbstractSimpleAggregationTest.php +++ b/tests/Aggregation/AbstractSimpleAggregationTest.php @@ -1,5 +1,7 @@ _getHost().':'.$this->_getPort()]; - $config['transport_config']['node_pool'] = $config['transport_config']['node_pool'] ?? new TraceableSimpleNodePool( + $config['transport_config']['node_pool'] ??= new TraceableSimpleNodePool( new RoundRobin(), new NoResurrect() ); diff --git a/tests/BasePipeline.php b/tests/BasePipeline.php index 6d0b10c2dc..5737fd4e20 100644 --- a/tests/BasePipeline.php +++ b/tests/BasePipeline.php @@ -1,5 +1,7 @@ assertTrue($action->hasSource()); $expected = <<<'JSON' -{"update":{"_id":"1","_index":"index"}} -{"doc":{"foo":"bar"},"doc_as_upsert":true} -JSON; + {"update":{"_id":"1","_index":"index"}} + {"doc":{"foo":"bar"},"doc_as_upsert":true} + JSON; $this->assertSame($expected, \trim((string) $action)); @@ -81,9 +83,9 @@ public function testUpdateDocumentAsUpsert(): void $action->setDocument($document); $expected = <<<'JSON' -{"update":{"_id":"1","_index":"index"}} -{"doc":{"foo":"bar"}} -JSON; + {"update":{"_id":"1","_index":"index"}} + {"doc":{"foo":"bar"}} + JSON; $this->assertSame($expected, \trim((string) $action)); diff --git a/tests/Bulk/ActionTest.php b/tests/Bulk/ActionTest.php index 644bf6440e..c4200f856a 100644 --- a/tests/Bulk/ActionTest.php +++ b/tests/Bulk/ActionTest.php @@ -1,5 +1,7 @@ assertSame($expectedJson, \trim((string) $bulk)); diff --git a/tests/ClientConfigurationTest.php b/tests/ClientConfigurationTest.php index 5566843811..0e32eb5224 100644 --- a/tests/ClientConfigurationTest.php +++ b/tests/ClientConfigurationTest.php @@ -1,5 +1,7 @@ assertEquals(['query_string' => $expected], $query->toArray()); $fields = []; - $max = \mt_rand(1, 10); + $max = \random_int(1, 10); for ($i = 0; $i < $max; ++$i) { $fields[] = \uniqid(); } diff --git a/tests/Query/RangeTest.php b/tests/Query/RangeTest.php index 71320a7efa..f687b4cf19 100644 --- a/tests/Query/RangeTest.php +++ b/tests/Query/RangeTest.php @@ -1,5 +1,7 @@ hasMethod('__construct')) { $this->assertEmpty($method->getParameters(), 'Constructor is not defined, but method has some parameters'); } else { diff --git a/tests/QueryBuilder/DSL/AggregationTest.php b/tests/QueryBuilder/DSL/AggregationTest.php index a00b792852..5dd9fa4c63 100644 --- a/tests/QueryBuilder/DSL/AggregationTest.php +++ b/tests/QueryBuilder/DSL/AggregationTest.php @@ -1,5 +1,7 @@ getQueries() as $query) { $this->assertTrue( \method_exists($dsl[0], $query), - 'query "'.$query.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[0]) + 'query "'.$query.'" in '.$version::class.' must be defined in '.\get_class($dsl[0]) ); } foreach ($version->getAggregations() as $aggregation) { $this->assertTrue( \method_exists($dsl[1], $aggregation), - 'aggregation "'.$aggregation.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[2]) + 'aggregation "'.$aggregation.'" in '.$version::class.' must be defined in '.\get_class($dsl[2]) ); } foreach ($version->getSuggesters() as $suggester) { $this->assertTrue( \method_exists($dsl[2], $suggester), - 'suggester "'.$suggester.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[2]) + 'suggester "'.$suggester.'" in '.$version::class.' must be defined in '.\get_class($dsl[2]) ); } foreach ($version->getCollapsers() as $collapser) { $this->assertTrue( \method_exists($dsl[3], $collapser), - 'suggester "'.$collapser.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[3]) + 'suggester "'.$collapser.'" in '.$version::class.' must be defined in '.\get_class($dsl[3]) ); } } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index ba0660e078..f7d0d28a79 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -1,5 +1,7 @@ getIndicesWithAlias($aliasName); $this->assertEquals([$indexName], \array_map( - static function ($index) { - return $index->getName(); - }, + static fn ($index) => $index->getName(), $indicesWithAlias )); } diff --git a/tests/Suggest/CompletionTest.php b/tests/Suggest/CompletionTest.php index 58df78ee97..7833319fdb 100644 --- a/tests/Suggest/CompletionTest.php +++ b/tests/Suggest/CompletionTest.php @@ -1,5 +1,7 @@ Date: Sun, 24 Mar 2024 18:58:18 +0300 Subject: [PATCH 7/8] Fix tests --- tests/Aggregation/DateRangeTest.php | 2 +- tests/Cluster/SettingsTest.php | 2 +- tests/Index/SettingsTest.php | 10 +++------- tests/IndexTemplateTest.php | 7 +++---- tests/PipelineTest.php | 7 +++---- tests/Query/CombinedFieldsQueryTest.php | 10 +++++----- tests/Query/MultiMatchTest.php | 10 +++++----- tests/Query/QueryStringTest.php | 5 ++--- tests/SearchTest.php | 7 +++---- 9 files changed, 26 insertions(+), 34 deletions(-) diff --git a/tests/Aggregation/DateRangeTest.php b/tests/Aggregation/DateRangeTest.php index 9e0dea6616..6078f0639d 100644 --- a/tests/Aggregation/DateRangeTest.php +++ b/tests/Aggregation/DateRangeTest.php @@ -136,7 +136,7 @@ public function testDateRangeSetFormatAccordingToFormatTargetField(): void $this->_getIndexForTest()->search($query)->getAggregation('date'); $this->fail('Should throw exception to and from parameters in date_range aggregation are interpreted according of the target field'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('search_phase_execution_exception', $error['type']); $this->assertStringStartsWith('failed to parse date field', $error['root_cause'][0]['reason']); diff --git a/tests/Cluster/SettingsTest.php b/tests/Cluster/SettingsTest.php index f0ffb4ab9c..c61e6d7cfd 100644 --- a/tests/Cluster/SettingsTest.php +++ b/tests/Cluster/SettingsTest.php @@ -40,7 +40,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('should throw read only exception'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('cluster read-only', $error['reason']); diff --git a/tests/Index/SettingsTest.php b/tests/Index/SettingsTest.php index e3475d4a36..820d9ebe21 100644 --- a/tests/Index/SettingsTest.php +++ b/tests/Index/SettingsTest.php @@ -7,7 +7,6 @@ use Elastic\Elasticsearch\Exception\ClientResponseException; use Elastica\Document; use Elastica\Index\Settings as IndexSettings; -use Elastica\ResponseConverter; use Elastica\Test\Base as BaseTest; /** @@ -138,8 +137,7 @@ public function testDeleteAliasWithException(): void $indexAlias->delete(); $this->fail('Should throw exception because you should delete the concrete index and not the alias'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('illegal_argument_exception', $error['type']); $this->assertStringContainsString('specify the corresponding concrete indices instead.', $error['reason']); @@ -351,8 +349,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('Should throw exception because of read only'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('read-only', $error['reason']); @@ -453,8 +450,7 @@ public function testNotFoundIndex(): void $index->getSettings()->get(); $this->fail('Should throw exception because of index not found'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('index_not_found_exception', $error['type']); } diff --git a/tests/IndexTemplateTest.php b/tests/IndexTemplateTest.php index bd66de7878..bf51488122 100644 --- a/tests/IndexTemplateTest.php +++ b/tests/IndexTemplateTest.php @@ -78,13 +78,12 @@ public function testCreateAlreadyExistsTemplateException(): void $indexTemplate->create($template); try { $indexTemplate->create($template); - } catch (ClientResponseException $ex) { - $response = ResponseConverter::toElastica($ex->getResponse()); - $error = $response->getFullError(); + } catch (ClientResponseException $e) { + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertNotEquals('index_template_already_exists_exception', $error['type']); $this->assertEquals('resource_already_exists_exception', $error['type']); - $this->assertEquals(400, $ex->getResponse()->getStatusCode()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } } diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index c9ec96a9fd..bdde1cabba 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -135,11 +135,10 @@ public function testDeletePipeline(): void $pipeline->deletePipeline('non_existent_pipeline'); $this->fail('an exception should be raised!'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $result = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; - $this->assertEquals('resource_not_found_exception', $result['type']); - $this->assertEquals('pipeline [non_existent_pipeline] is missing', $result['reason']); + $this->assertEquals('resource_not_found_exception', $error['type']); + $this->assertEquals('pipeline [non_existent_pipeline] is missing', $error['reason']); } } } diff --git a/tests/Query/CombinedFieldsQueryTest.php b/tests/Query/CombinedFieldsQueryTest.php index de775dac9b..f10d96340b 100644 --- a/tests/Query/CombinedFieldsQueryTest.php +++ b/tests/Query/CombinedFieldsQueryTest.php @@ -18,10 +18,10 @@ class CombinedFieldsQueryTest extends BaseTest { private static $data = [ - ['id' => 1, 'title' => 'Rodolfo', 'body' => 'Moraes', 'abstract' => 'Lorem'], - ['id' => 2, 'title' => 'Tristan', 'body' => 'Maindron', 'abstract' => 'Dolor'], - ['id' => 3, 'title' => 'Monique', 'body' => 'Maindron', 'abstract' => 'Ipsum'], - ['id' => 4, 'title' => 'John', 'body' => 'not Doe', 'abstract' => 'Consectetur'], + ['id' => '1', 'title' => 'Rodolfo', 'body' => 'Moraes', 'abstract' => 'Lorem'], + ['id' => '2', 'title' => 'Tristan', 'body' => 'Maindron', 'abstract' => 'Dolor'], + ['id' => '3', 'title' => 'Monique', 'body' => 'Maindron', 'abstract' => 'Ipsum'], + ['id' => '4', 'title' => 'John', 'body' => 'not Doe', 'abstract' => 'Consectetur'], ]; /** @@ -145,7 +145,7 @@ private function _generateIndex(): Index ); foreach (self::$data as $key => $docData) { - $index->addDocument(new Document($key, $docData)); + $index->addDocument(new Document((string) $key, $docData)); } // Refresh index diff --git a/tests/Query/MultiMatchTest.php b/tests/Query/MultiMatchTest.php index a4b392e9da..17fd671b56 100644 --- a/tests/Query/MultiMatchTest.php +++ b/tests/Query/MultiMatchTest.php @@ -18,10 +18,10 @@ class MultiMatchTest extends BaseTest { private static $data = [ - ['id' => 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'], - ['id' => 2, 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'], - ['id' => 3, 'name' => 'Monique', 'last_name' => 'Maindron', 'full_name' => 'Monique Maindron'], - ['id' => 4, 'name' => 'John', 'last_name' => 'not Doe', 'full_name' => 'John not Doe'], + ['id' => '1', 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'], + ['id' => '2', 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'], + ['id' => '3', 'name' => 'Monique', 'last_name' => 'Maindron', 'full_name' => 'Monique Maindron'], + ['id' => '4', 'name' => 'John', 'last_name' => 'not Doe', 'full_name' => 'John not Doe'], ]; /** @@ -218,7 +218,7 @@ private function _generateIndex(): Index ); foreach (self::$data as $key => $docData) { - $index->addDocument(new Document($key, $docData)); + $index->addDocument(new Document((string) $key, $docData)); } // Refresh index diff --git a/tests/Query/QueryStringTest.php b/tests/Query/QueryStringTest.php index 9324f0a3fd..3774f38de2 100644 --- a/tests/Query/QueryStringTest.php +++ b/tests/Query/QueryStringTest.php @@ -107,14 +107,13 @@ public function testSearchFieldsValidationException(): void try { $index->search($query); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('query_shard_exception', $error['root_cause'][0]['type']); $this->assertStringContainsString('failed to create query', $error['root_cause'][0]['reason']); $this->assertStringContainsString('[fields] parameter in conjunction with [default_field]', $error['failed_shards'][0]['reason']['caused_by']['reason']); - $this->assertEquals(400, $response->getStatus()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } diff --git a/tests/SearchTest.php b/tests/SearchTest.php index e21147ff0e..d7ef80fc20 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -258,7 +258,7 @@ public function testSearchScrollRequest(): void ]); \parse_str($search->getClient()->getLastRequest()->getUri()->getQuery(), $lastRequestQuery); - $lastRequestData = \json_decode($search->getClient()->getLastRequest()->getBody(), true); + $lastRequestData = \json_decode((string) $search->getClient()->getLastRequest()->getBody(), true); $this->assertFalse($result->getResponse()->hasError()); $this->assertCount(5, $result->getResults()); @@ -271,7 +271,7 @@ public function testSearchScrollRequest(): void ]); \parse_str($search->getClient()->getLastRequest()->getUri()->getQuery(), $lastRequestQuery); - $lastRequestData = \json_decode($search->getClient()->getLastRequest()->getBody(), true); + $lastRequestData = \json_decode((string) $search->getClient()->getLastRequest()->getBody(), true); $this->assertFalse($result->getResponse()->hasError()); $this->assertCount(0, $result->getResults()); @@ -688,8 +688,7 @@ public function testIgnoreUnavailableOption(): void $search->search($query); $this->fail('Should raise an Index not found exception'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertEquals('index_not_found_exception', $error['type']); $this->assertEquals('no such index [elastica_7086b4c2ee585bbb6740ece5ed7ece01]', $error['reason']); From 78072602c05c98da5fdd8aed5e14f6218d4f4f0b Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 24 Mar 2024 19:45:50 +0300 Subject: [PATCH 8/8] apply rules to all files --- .php-cs-fixer.dist.php | 5 ++++- src/JSON.php | 2 ++ src/Response.php | 2 ++ src/ResponseConverter.php | 4 +++- tests/Aggregation/DateRangeTest.php | 2 +- tests/Cluster/SettingsTest.php | 2 +- tests/Index/SettingsTest.php | 6 +++--- tests/IndexTemplateTest.php | 3 +-- tests/PipelineTest.php | 3 +-- tests/Query/QueryStringTest.php | 3 +-- tests/SearchTest.php | 3 +-- 11 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c612e7edd8..6c604d3a32 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,7 @@ in(__DIR__.'/src') ->in(__DIR__.'/tests') @@ -8,7 +10,8 @@ return (new PhpCsFixer\Config()) ->setFinder($finder) ->setRules([ - '@PHP71Migration' => true, + '@PHP80Migration' => true, + '@PHP80Migration:risky' => true, '@PhpCsFixer' => true, '@PHPUnit75Migration:risky' => true, '@PSR2' => true, diff --git a/src/JSON.php b/src/JSON.php index e901dca453..c92de56c6e 100644 --- a/src/JSON.php +++ b/src/JSON.php @@ -1,5 +1,7 @@ asString(), $response->getStatusCode()); } - return new Response($response->getBody(), $response->getStatusCode()); + return new Response((string) $response->getBody(), $response->getStatusCode()); } } diff --git a/tests/Aggregation/DateRangeTest.php b/tests/Aggregation/DateRangeTest.php index 6078f0639d..c81c16ba29 100644 --- a/tests/Aggregation/DateRangeTest.php +++ b/tests/Aggregation/DateRangeTest.php @@ -136,7 +136,7 @@ public function testDateRangeSetFormatAccordingToFormatTargetField(): void $this->_getIndexForTest()->search($query)->getAggregation('date'); $this->fail('Should throw exception to and from parameters in date_range aggregation are interpreted according of the target field'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('search_phase_execution_exception', $error['type']); $this->assertStringStartsWith('failed to parse date field', $error['root_cause'][0]['reason']); diff --git a/tests/Cluster/SettingsTest.php b/tests/Cluster/SettingsTest.php index c61e6d7cfd..657f0a4c2e 100644 --- a/tests/Cluster/SettingsTest.php +++ b/tests/Cluster/SettingsTest.php @@ -40,7 +40,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('should throw read only exception'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('cluster read-only', $error['reason']); diff --git a/tests/Index/SettingsTest.php b/tests/Index/SettingsTest.php index 820d9ebe21..192555d564 100644 --- a/tests/Index/SettingsTest.php +++ b/tests/Index/SettingsTest.php @@ -137,7 +137,7 @@ public function testDeleteAliasWithException(): void $indexAlias->delete(); $this->fail('Should throw exception because you should delete the concrete index and not the alias'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('illegal_argument_exception', $error['type']); $this->assertStringContainsString('specify the corresponding concrete indices instead.', $error['reason']); @@ -349,7 +349,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('Should throw exception because of read only'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('read-only', $error['reason']); @@ -450,7 +450,7 @@ public function testNotFoundIndex(): void $index->getSettings()->get(); $this->fail('Should throw exception because of index not found'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('index_not_found_exception', $error['type']); } diff --git a/tests/IndexTemplateTest.php b/tests/IndexTemplateTest.php index bf51488122..c0f05516fe 100644 --- a/tests/IndexTemplateTest.php +++ b/tests/IndexTemplateTest.php @@ -7,7 +7,6 @@ use Elastic\Elasticsearch\Exception\ClientResponseException; use Elastica\Exception\InvalidException; use Elastica\IndexTemplate; -use Elastica\ResponseConverter; use Elastica\Test\Base as BaseTest; /** @@ -79,7 +78,7 @@ public function testCreateAlreadyExistsTemplateException(): void try { $indexTemplate->create($template); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertNotEquals('index_template_already_exists_exception', $error['type']); $this->assertEquals('resource_already_exists_exception', $error['type']); diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index bdde1cabba..3df74fa7bf 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -12,7 +12,6 @@ use Elastica\Processor\RenameProcessor; use Elastica\Processor\SetProcessor; use Elastica\Processor\TrimProcessor; -use Elastica\ResponseConverter; /** * @internal @@ -135,7 +134,7 @@ public function testDeletePipeline(): void $pipeline->deletePipeline('non_existent_pipeline'); $this->fail('an exception should be raised!'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertEquals('resource_not_found_exception', $error['type']); $this->assertEquals('pipeline [non_existent_pipeline] is missing', $error['reason']); diff --git a/tests/Query/QueryStringTest.php b/tests/Query/QueryStringTest.php index 3774f38de2..e426b22ff3 100644 --- a/tests/Query/QueryStringTest.php +++ b/tests/Query/QueryStringTest.php @@ -7,7 +7,6 @@ use Elastic\Elasticsearch\Exception\ClientResponseException; use Elastica\Document; use Elastica\Query\QueryString; -use Elastica\ResponseConverter; use Elastica\Test\Base as BaseTest; /** @@ -107,7 +106,7 @@ public function testSearchFieldsValidationException(): void try { $index->search($query); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('query_shard_exception', $error['root_cause'][0]['type']); $this->assertStringContainsString('failed to create query', $error['root_cause'][0]['reason']); diff --git a/tests/SearchTest.php b/tests/SearchTest.php index d7ef80fc20..84252bf63d 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -15,7 +15,6 @@ use Elastica\Query\MatchAll; use Elastica\Query\QueryString; use Elastica\Request; -use Elastica\ResponseConverter; use Elastica\ResultSet; use Elastica\Script\Script; use Elastica\Search; @@ -688,7 +687,7 @@ public function testIgnoreUnavailableOption(): void $search->search($query); $this->fail('Should raise an Index not found exception'); } catch (ClientResponseException $e) { - $error = json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertEquals('index_not_found_exception', $error['type']); $this->assertEquals('no such index [elastica_7086b4c2ee585bbb6740ece5ed7ece01]', $error['reason']);