From c05befc4bb1469b03fa3d77e8730e6beb8829e47 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sat, 17 Dec 2022 14:25:35 +0100 Subject: [PATCH] Remove aggregation deprecations --- CHANGELOG.md | 11 ++++ src/Aggregation/AvgBucket.php | 24 +------ src/Aggregation/BucketScript.php | 28 +-------- src/Aggregation/BucketSelector.php | 11 +--- src/Aggregation/Derivative.php | 24 +------ src/Aggregation/NormalizeAggregation.php | 37 +---------- src/Aggregation/PercentilesBucket.php | 24 +------ src/Aggregation/SerialDiff.php | 24 +------ src/Aggregation/StatsBucket.php | 24 +------ src/Aggregation/SumBucket.php | 24 +------ src/QueryBuilder/DSL/Aggregation.php | 20 +++--- tests/Aggregation/AvgBucketTest.php | 38 ------------ tests/Aggregation/BucketScriptTest.php | 35 ++--------- tests/Aggregation/DerivativeTest.php | 25 -------- .../Aggregation/NormalizeAggregationTest.php | 62 ------------------- tests/Aggregation/PercentilesBucketTest.php | 38 ------------ tests/Aggregation/SerialDiffTest.php | 38 ------------ tests/Aggregation/StatsBucketTest.php | 38 ------------ tests/Aggregation/SumBucketTest.php | 38 ------------ tests/QueryBuilder/DSL/AggregationTest.php | 5 +- 20 files changed, 48 insertions(+), 520 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7966586981..1815bf9037 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `Elastica\Result::getType()` * `Elastica\Suggest\Phrase::addCandidateGenerator()` -> use `Elastica\Suggest\Phrase::addDirectGenerator()` instead * `Elastica\Util::getParamName()` +* Changed following aggregation constructors [#2138](https://github.com/ruflin/Elastica/pull/2138) + * `Elastica\Aggregation\AvgBucket`: The second argument `$bucketsPath` is now mandatory + * `Elastica\Aggregation\BucketScript`: The second (`array $bucketsPath`) and the third (`string $script`) argument are now mandatory + * `Elastica\Aggregation\BucketSelector`: The second (`array $bucketsPath`) and the third (`string $script`) argument are now mandatory + * `Elastica\Aggregation\Derivative`: The second argument (`string $bucketsPath`) is now mandatory + * `Elastica\Aggregation\NormalizeAggregation`: The second (`string $bucketsPath`) and the third (`string $method`) argument are now mandatory + * `Elastica\Aggregation\PercentilesBucket`: The second argument (`string $bucketsPath`) is now mandatory + * `Elastica\Aggregation\SerialDiff`: The second argument (`string $bucketsPath`) is now mandatory + * `Elastica\Aggregation\StatsBucket`: The second argument (`string $bucketsPath`) is now mandatory + * `Elastica\Aggregation\SumBucket`: The second argument (`string $bucketsPath`) is now mandatory + ### Added * Added support for PHP 8.2 [#2136](https://github.com/ruflin/Elastica/pull/2136) ### Changed diff --git a/src/Aggregation/AvgBucket.php b/src/Aggregation/AvgBucket.php index 80ffcd55f9..7571f2121b 100644 --- a/src/Aggregation/AvgBucket.php +++ b/src/Aggregation/AvgBucket.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class AvgBucket. * @@ -16,17 +14,11 @@ class AvgBucket extends AbstractAggregation implements GapPolicyInterface public const DEFAULT_FORMAT_VALUE = null; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } + $this->setBucketsPath($bucketsPath); } /** @@ -38,16 +30,4 @@ public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/BucketScript.php b/src/Aggregation/BucketScript.php index bb0d8a63ac..14c2998ab4 100644 --- a/src/Aggregation/BucketScript.php +++ b/src/Aggregation/BucketScript.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class BucketScript. * @@ -13,17 +11,12 @@ class BucketScript extends AbstractAggregation implements GapPolicyInterface { use Traits\GapPolicyTrait; - public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null) + public function __construct(string $name, array $bucketsPath, string $script) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } - - if (null !== $script) { - $this->setScript($script); - } + $this->setBucketsPath($bucketsPath); + $this->setScript($script); } /** @@ -55,19 +48,4 @@ public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - if (!$this->hasParam('script')) { - throw new InvalidException('Script parameter is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/BucketSelector.php b/src/Aggregation/BucketSelector.php index ac0c2ee4b4..1627e07a32 100644 --- a/src/Aggregation/BucketSelector.php +++ b/src/Aggregation/BucketSelector.php @@ -11,17 +11,12 @@ class BucketSelector extends AbstractSimpleAggregation implements GapPolicyInter { use Traits\GapPolicyTrait; - public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null) + public function __construct(string $name, array $bucketsPath, string $script) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } - - if (null !== $script) { - $this->setScript($script); - } + $this->setBucketsPath($bucketsPath); + $this->setScript($script); } /** diff --git a/src/Aggregation/Derivative.php b/src/Aggregation/Derivative.php index 1fef8420de..a26dbd5610 100644 --- a/src/Aggregation/Derivative.php +++ b/src/Aggregation/Derivative.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class Derivative. * @@ -14,17 +12,11 @@ class Derivative extends AbstractAggregation implements GapPolicyInterface use Traits\BucketsPathTrait; use Traits\GapPolicyTrait; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } + $this->setBucketsPath($bucketsPath); } /** @@ -36,16 +28,4 @@ public function setFormat(string $format): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/NormalizeAggregation.php b/src/Aggregation/NormalizeAggregation.php index 88fca91a3f..536900d211 100644 --- a/src/Aggregation/NormalizeAggregation.php +++ b/src/Aggregation/NormalizeAggregation.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class NormalizeAggregation. * @@ -13,25 +11,12 @@ class NormalizeAggregation extends AbstractAggregation { use Traits\BucketsPathTrait; - public function __construct(string $name, ?string $bucketsPath = null, ?string $method = null) + public function __construct(string $name, string $bucketsPath, string $method) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } - - 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__); - } + $this->setBucketsPath($bucketsPath); + $this->setMethod($method); } /** @@ -53,20 +38,4 @@ public function setFormat(string $format): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or method are not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - if (!$this->hasParam('method')) { - throw new InvalidException('Method parameter is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/PercentilesBucket.php b/src/Aggregation/PercentilesBucket.php index e60c510d63..c0d7e63464 100644 --- a/src/Aggregation/PercentilesBucket.php +++ b/src/Aggregation/PercentilesBucket.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class PercentilesBucket. * @@ -15,29 +13,11 @@ class PercentilesBucket extends AbstractAggregation implements GapPolicyInterfac use Traits\GapPolicyTrait; use Traits\KeyedTrait; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } - } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); + $this->setBucketsPath($bucketsPath); } /** diff --git a/src/Aggregation/SerialDiff.php b/src/Aggregation/SerialDiff.php index de2cd6799e..79c1b187ef 100644 --- a/src/Aggregation/SerialDiff.php +++ b/src/Aggregation/SerialDiff.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class SerialDiff. * @@ -15,17 +13,11 @@ class SerialDiff extends AbstractAggregation implements GapPolicyInterface public const DEFAULT_GAP_POLICY_VALUE = GapPolicyInterface::INSERT_ZEROS; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } + $this->setBucketsPath($bucketsPath); } /** @@ -57,16 +49,4 @@ public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/StatsBucket.php b/src/Aggregation/StatsBucket.php index 2db142e7d3..b55753d1e7 100644 --- a/src/Aggregation/StatsBucket.php +++ b/src/Aggregation/StatsBucket.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class StatsBucket. * @@ -14,17 +12,11 @@ class StatsBucket extends AbstractAggregation implements GapPolicyInterface use Traits\BucketsPathTrait; use Traits\GapPolicyTrait; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } + $this->setBucketsPath($bucketsPath); } /** @@ -36,16 +28,4 @@ public function setFormat(string $format): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); - } } diff --git a/src/Aggregation/SumBucket.php b/src/Aggregation/SumBucket.php index 88287823e6..88bf4b61cd 100644 --- a/src/Aggregation/SumBucket.php +++ b/src/Aggregation/SumBucket.php @@ -2,8 +2,6 @@ namespace Elastica\Aggregation; -use Elastica\Exception\InvalidException; - /** * Class SumBucket. * @@ -14,17 +12,11 @@ class SumBucket extends AbstractAggregation implements GapPolicyInterface use Traits\BucketsPathTrait; use Traits\GapPolicyTrait; - public function __construct(string $name, ?string $bucketsPath = null) + public function __construct(string $name, string $bucketsPath) { parent::__construct($name); - if (null !== $bucketsPath) { - $this->setBucketsPath($bucketsPath); - } elseif (\func_num_args() >= 2) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing null as 2nd 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 2nd argument to "%s()" is deprecated, pass a string instead. It will be removed in 8.0.', __METHOD__); - } + $this->setBucketsPath($bucketsPath); } /** @@ -36,16 +28,4 @@ public function setFormat(string $format): self { return $this->setParam('format', $format); } - - /** - * @throws InvalidException If buckets path or script is not set - */ - public function toArray(): array - { - if (!$this->hasParam('buckets_path')) { - throw new InvalidException('Buckets path is required'); - } - - return parent::toArray(); - } } diff --git a/src/QueryBuilder/DSL/Aggregation.php b/src/QueryBuilder/DSL/Aggregation.php index eff4a2b215..333a10bbcd 100644 --- a/src/QueryBuilder/DSL/Aggregation.php +++ b/src/QueryBuilder/DSL/Aggregation.php @@ -99,7 +99,7 @@ public function sum(string $name): Sum * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html */ - public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket + public function sum_bucket(string $name, string $bucketsPath): SumBucket { return new SumBucket($name, $bucketsPath); } @@ -119,7 +119,7 @@ public function avg(string $name): Avg * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html */ - public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket + public function avg_bucket(string $name, string $bucketsPath): AvgBucket { return new AvgBucket($name, $bucketsPath); } @@ -137,7 +137,7 @@ public function stats(string $name): Stats /** * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-stats-bucket-aggregation.html */ - public function stats_bucket(string $name, ?string $bucketsPath = null): StatsBucket + public function stats_bucket(string $name, string $bucketsPath): StatsBucket { return new StatsBucket($name, $bucketsPath); } @@ -180,10 +180,10 @@ public function percentiles(string $name, ?string $field = null): Percentiles * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html * - * @param string $name the name of this aggregation - * @param string|null $bucketsPath the field on which to perform this aggregation + * @param string $name the name of this aggregation + * @param string $bucketsPath the field on which to perform this aggregation */ - public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket + public function percentiles_bucket(string $name, string $bucketsPath): PercentilesBucket { return new PercentilesBucket($name, $bucketsPath); } @@ -431,7 +431,7 @@ public function geotile_grid(string $name, string $field): GeotileGridAggregatio * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html */ - public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript + public function bucket_script(string $name, array $bucketsPath, string $script): BucketScript { return new BucketScript($name, $bucketsPath, $script); } @@ -441,7 +441,7 @@ public function bucket_script(string $name, ?array $bucketsPath = null, ?string * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html */ - public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff + public function serial_diff(string $name, string $bucketsPath): SerialDiff { return new SerialDiff($name, $bucketsPath); } @@ -469,7 +469,7 @@ public function sampler(string $name): Sampler /** * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html */ - public function derivative(string $name, ?string $bucketsPath = null): Derivative + public function derivative(string $name, string $bucketsPath): Derivative { return new Derivative($name, $bucketsPath); } @@ -509,7 +509,7 @@ public function composite(string $name): Composite * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-normalize-aggregation.html */ - public function normalize(string $name, ?string $bucketsPath = null, ?string $method = null): NormalizeAggregation + public function normalize(string $name, string $bucketsPath, string $method): NormalizeAggregation { return new NormalizeAggregation($name, $bucketsPath, $method); } diff --git a/tests/Aggregation/AvgBucketTest.php b/tests/Aggregation/AvgBucketTest.php index 4f7c1cb83b..5f8767b8b6 100644 --- a/tests/Aggregation/AvgBucketTest.php +++ b/tests/Aggregation/AvgBucketTest.php @@ -7,18 +7,14 @@ use Elastica\Aggregation\GapPolicyInterface; use Elastica\Aggregation\Terms; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class AvgBucketTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group functional */ @@ -67,40 +63,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $aggregation->toArray()); } - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\AvgBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new AvgBucket('avg_bucket'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\AvgBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new AvgBucket('avg_bucket', null); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new AvgBucket('avg_bucket'))->toArray(); - } - private function getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/Aggregation/BucketScriptTest.php b/tests/Aggregation/BucketScriptTest.php index c00f3945ed..7c5ff05377 100644 --- a/tests/Aggregation/BucketScriptTest.php +++ b/tests/Aggregation/BucketScriptTest.php @@ -7,7 +7,6 @@ use Elastica\Aggregation\Histogram; use Elastica\Aggregation\Max; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; @@ -52,15 +51,13 @@ public function testBucketScriptAggregation(): void */ public function testConstructThroughSetters(): void { - $serialDiffAgg = new BucketScript('bucket_scripted'); + $serialDiffAgg = new BucketScript('bucket_scripted', [ + 'x' => 'agg_max', + 'y' => 'agg_sum', + 'z' => 'agg_min', + ], 'x / y * z'); $serialDiffAgg - ->setScript('x / y * z') - ->setBucketsPath([ - 'x' => 'agg_max', - 'y' => 'agg_sum', - 'z' => 'agg_min', - ]) ->setFormat('test_format') ->setGapPolicy(GapPolicyInterface::INSERT_ZEROS) ; @@ -81,28 +78,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $serialDiffAgg->toArray()); } - /** - * @group unit - */ - public function testToArrayInvalidBucketsPath(): void - { - $this->expectException(InvalidException::class); - - $serialDiffAgg = new BucketScript('bucket_scripted'); - $serialDiffAgg->toArray(); - } - - /** - * @group unit - */ - public function testToArrayInvalidScript(): void - { - $this->expectException(InvalidException::class); - - $serialDiffAgg = new BucketScript('bucket_scripted', ['path' => 'agg']); - $serialDiffAgg->toArray(); - } - protected function _getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/Aggregation/DerivativeTest.php b/tests/Aggregation/DerivativeTest.php index 12ed813caa..8be63a119f 100644 --- a/tests/Aggregation/DerivativeTest.php +++ b/tests/Aggregation/DerivativeTest.php @@ -8,37 +8,12 @@ use Elastica\Document; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class DerivativeTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\Derivative::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new Derivative('derivative'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\Derivative::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new Derivative('derivative', null); - } - /** * @group unit */ diff --git a/tests/Aggregation/NormalizeAggregationTest.php b/tests/Aggregation/NormalizeAggregationTest.php index 4f2a7edf11..cc830453bb 100644 --- a/tests/Aggregation/NormalizeAggregationTest.php +++ b/tests/Aggregation/NormalizeAggregationTest.php @@ -6,18 +6,14 @@ use Elastica\Aggregation\NormalizeAggregation; use Elastica\Aggregation\Sum; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class NormalizeAggregationTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group unit */ @@ -60,64 +56,6 @@ public function testToArray(): void $this->assertEquals($expected, $dateHistogramAgg->toArray()); } - /** - * @group unit - * @group legacy - */ - 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'); - } - - /** - * @group unit - * @group legacy - */ - 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, '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); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new NormalizeAggregation('normalize_agg'))->toArray(); - } - - /** - * @group unit - * @group legacy - */ - public function testToArrayInvalidMethod(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Method parameter is required'); - - (new NormalizeAggregation('normalize_agg', 'buckets_path'))->toArray(); - } - /** * @group functional */ diff --git a/tests/Aggregation/PercentilesBucketTest.php b/tests/Aggregation/PercentilesBucketTest.php index 23724e6bed..c8a934c29e 100644 --- a/tests/Aggregation/PercentilesBucketTest.php +++ b/tests/Aggregation/PercentilesBucketTest.php @@ -7,18 +7,14 @@ use Elastica\Aggregation\PercentilesBucket; use Elastica\Aggregation\Terms; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class PercentilesBucketTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group functional */ @@ -76,40 +72,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $aggregation->toArray()); } - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\PercentilesBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new PercentilesBucket('percentiles_bucket'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\PercentilesBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new PercentilesBucket('percentiles_bucket', null); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new PercentilesBucket('percentiles_bucket'))->toArray(); - } - private function getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/Aggregation/SerialDiffTest.php b/tests/Aggregation/SerialDiffTest.php index a36a99a672..5439147519 100644 --- a/tests/Aggregation/SerialDiffTest.php +++ b/tests/Aggregation/SerialDiffTest.php @@ -7,19 +7,15 @@ use Elastica\Aggregation\Max; use Elastica\Aggregation\SerialDiff; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Mapping; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class SerialDiffTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group functional */ @@ -65,40 +61,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $aggregation->toArray()); } - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\SerialDiff::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new SerialDiff('serial_diff'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\SerialDiff::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new SerialDiff('serial_diff', null); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new SerialDiff('serial_diff'))->toArray(); - } - private function getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/Aggregation/StatsBucketTest.php b/tests/Aggregation/StatsBucketTest.php index d182a91f32..0e692f3fbd 100644 --- a/tests/Aggregation/StatsBucketTest.php +++ b/tests/Aggregation/StatsBucketTest.php @@ -7,18 +7,14 @@ use Elastica\Aggregation\Max; use Elastica\Aggregation\StatsBucket; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class StatsBucketTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group functional */ @@ -67,40 +63,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $aggregation->toArray()); } - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\StatsBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new StatsBucket('stats_bucket'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\StatsBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new StatsBucket('stats_bucket', null); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new StatsBucket('stats_bucket'))->toArray(); - } - private function getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/Aggregation/SumBucketTest.php b/tests/Aggregation/SumBucketTest.php index d0e10bb66c..9833d64de7 100644 --- a/tests/Aggregation/SumBucketTest.php +++ b/tests/Aggregation/SumBucketTest.php @@ -7,18 +7,14 @@ use Elastica\Aggregation\SumBucket; use Elastica\Aggregation\Terms; use Elastica\Document; -use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Query; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class SumBucketTest extends BaseAggregationTest { - use ExpectDeprecationTrait; - /** * @group functional */ @@ -67,40 +63,6 @@ public function testConstructThroughSetters(): void $this->assertEquals($expected, $aggregation->toArray()); } - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNoBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Not passing a 2nd argument to "Elastica\Aggregation\SumBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new SumBucket('sum_bucket'); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyConstructWithNullBucketsPath(): void - { - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing null as 2nd argument to "Elastica\Aggregation\SumBucket::__construct()" is deprecated, pass a string instead. It will be removed in 8.0.'); - - new SumBucket('sum_bucket', null); - } - - /** - * @group unit - * @group legacy - */ - public function testLegacyToArrayWithNoBucketsPath(): void - { - $this->expectException(InvalidException::class); - $this->expectExceptionMessage('Buckets path is required'); - - (new SumBucket('sum_bucket'))->toArray(); - } - private function getIndexForTest(): Index { $index = $this->_createIndex(); diff --git a/tests/QueryBuilder/DSL/AggregationTest.php b/tests/QueryBuilder/DSL/AggregationTest.php index 409ebd013d..a00b792852 100644 --- a/tests/QueryBuilder/DSL/AggregationTest.php +++ b/tests/QueryBuilder/DSL/AggregationTest.php @@ -5,15 +5,12 @@ use Elastica\Aggregation; use Elastica\Query\Exists; use Elastica\QueryBuilder\DSL; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @internal */ class AggregationTest extends AbstractDSLTest { - use ExpectDeprecationTrait; - /** * @group unit */ @@ -66,7 +63,7 @@ public function testInterface(): void $this->_assertImplemented($aggregationDSL, 'terms', Aggregation\Terms::class, ['name']); $this->_assertImplemented($aggregationDSL, 'top_hits', Aggregation\TopHits::class, ['name']); $this->_assertImplemented($aggregationDSL, 'value_count', Aggregation\ValueCount::class, ['name', 'field']); - $this->_assertImplemented($aggregationDSL, 'bucket_script', Aggregation\BucketScript::class, ['name']); + $this->_assertImplemented($aggregationDSL, 'bucket_script', Aggregation\BucketScript::class, ['name', [], 'script']); $this->_assertImplemented($aggregationDSL, 'serial_diff', Aggregation\SerialDiff::class, ['name', 'buckets_path']); $this->_assertImplemented($aggregationDSL, 'adjacency_matrix', Aggregation\AdjacencyMatrix::class, ['name']); $this->_assertImplemented($aggregationDSL, 'sampler', Aggregation\Sampler::class, ['name']);