From 161ba5085328015e70a02b49e00e5fddc2b4f6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Mon, 6 Dec 2021 10:49:59 +0100 Subject: [PATCH 1/3] Deprecate not setting a method when constructing NormalizeAggregation --- src/Aggregation/NormalizeAggregation.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Aggregation/NormalizeAggregation.php b/src/Aggregation/NormalizeAggregation.php index 5904127819..88fca91a3f 100644 --- a/src/Aggregation/NormalizeAggregation.php +++ b/src/Aggregation/NormalizeAggregation.php @@ -27,6 +27,10 @@ public function __construct(string $name, ?string $bucketsPath = null, ?string $ if (null !== $method) { $this->setMethod($method); + } elseif (\func_num_args() >= 3) { + \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 3rd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); + } else { + \trigger_deprecation('ruflin/elastica', '7.1.3', 'Not passing a 3rd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); } } From 858522a37c2888b70b53e1b4e78e3b0d51cb417d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Tue, 7 Dec 2021 16:21:18 +0100 Subject: [PATCH 2/3] Add tests --- .../Aggregation/NormalizeAggregationTest.php | 21 +++++++++++++++---- tests/QueryBuilder/DSL/AggregationTest.php | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/Aggregation/NormalizeAggregationTest.php b/tests/Aggregation/NormalizeAggregationTest.php index 9f123ea009..530d4775b5 100644 --- a/tests/Aggregation/NormalizeAggregationTest.php +++ b/tests/Aggregation/NormalizeAggregationTest.php @@ -64,9 +64,10 @@ public function testToArray(): void * @group unit * @group legacy */ - public function testLegacyConstructWithNoBucketsPath(): void + public function testLegacyConstructWithNoBucketsPathAndNoMethod(): void { $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\NormalizeAggregation::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); + $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 3rd argument to "Elastica\Aggregation\NormalizeAggregation::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); new NormalizeAggregation('normalize_agg'); } @@ -79,7 +80,18 @@ public function testLegacyConstructWithNullBucketsPath(): void { $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\NormalizeAggregation::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - new NormalizeAggregation('normalize_agg', null); + new NormalizeAggregation('normalize_agg', null, 'method'); + } + + /** + * @group unit + * @group legacy + */ + public function testLegacyConstructWithNullMethod(): void + { + $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 3rd argument to "Elastica\Aggregation\NormalizeAggregation::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); + + new NormalizeAggregation('normalize_agg', 'buckets_path', null); } /** @@ -96,13 +108,14 @@ public function testLegacyToArrayWithNoBucketsPath(): void /** * @group unit + * @group legacy */ public function testToArrayInvalidMethod(): void { $this->expectException(InvalidException::class); + $this->expectExceptionMessage('Method parameter is required'); - $normalizeAgg = new NormalizeAggregation('normalize_agg', 'agg'); - $normalizeAgg->toArray(); + (new NormalizeAggregation('normalize_agg', 'buckets_path'))->toArray(); } /** diff --git a/tests/QueryBuilder/DSL/AggregationTest.php b/tests/QueryBuilder/DSL/AggregationTest.php index 8a0fd2a937..1e3c35d4b1 100644 --- a/tests/QueryBuilder/DSL/AggregationTest.php +++ b/tests/QueryBuilder/DSL/AggregationTest.php @@ -52,7 +52,7 @@ public function testInterface(): void $this->_assertImplemented($aggregationDSL, 'min', Aggregation\Min::class, ['name']); $this->_assertImplemented($aggregationDSL, 'missing', Aggregation\Missing::class, ['name', 'field']); $this->_assertImplemented($aggregationDSL, 'nested', Aggregation\Nested::class, ['name', 'path']); - $this->_assertImplemented($aggregationDSL, 'normalize', Aggregation\NormalizeAggregation::class, ['name', 'buckets_path']); + $this->_assertImplemented($aggregationDSL, 'normalize', Aggregation\NormalizeAggregation::class, ['name', 'buckets_path', 'method']); $this->_assertImplemented($aggregationDSL, 'percentiles', Aggregation\Percentiles::class, ['name']); $this->_assertImplemented($aggregationDSL, 'percentiles_bucket', Aggregation\PercentilesBucket::class, ['name', 'buckets_path']); $this->_assertImplemented($aggregationDSL, 'range', Aggregation\Range::class, ['name']); From 42fd26d27b1f887c9cf72e16d408cd6ab81850ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Tue, 7 Dec 2021 16:50:56 +0100 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b6f0953a..67c8e27107 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Deprecated `cutoff_frequency` option of `Elastica\Query\MultiMatch` [#2015](https://github.com/ruflin/Elastica/pull/2015) * Deprecated `Elastica\Bulk::toString()`, `Elastica\Bulk\Action::toString()` and `Elastica\Request::toString()` methods, use `__toString()` method or cast to string instead [#2033](https://github.com/ruflin/Elastica/pull/2033) * Deprecated not passing a `buckets_path` when constructing `Elastica\Aggregation\AvgBucket`, `Elastica\Aggregation\Derivative`, `Elastica\Aggregation\NormalizeAggregation`, `Elastica\Aggregation\PercentilesBucket`, `Elastica\Aggregation\SerialDiff`, `Elastica\Aggregation\StatsBucket` and `Elastica\Aggregation\SumBucket` [#2038](https://github.com/ruflin/Elastica/pull/2038) +* Deprecated not passing a `method` when constructing `Elastica\Aggregation\NormalizeAggregation` [#2040](https://github.com/ruflin/Elastica/pull/2040) ### Removed * Removed remaining `_type` field usages [#2017](https://github.com/ruflin/Elastica/pull/2017) * Removed `Elastica\Bulk::$_type` dead property [#2034](https://github.com/ruflin/Elastica/pull/2034)