Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate not setting a method when constructing NormalizeAggregation #2040

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Aggregation/NormalizeAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}
}

Expand Down
21 changes: 17 additions & 4 deletions tests/Aggregation/NormalizeAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
}

/**
Expand All @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/QueryBuilder/DSL/AggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down