From 1a7701f564fffd822f2e95b00dea42a9320dbb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= <simonas.serlinskas@nfq.com> Date: Thu, 24 Jan 2019 16:37:11 +0200 Subject: [PATCH] add moving function aggregation --- .../Pipeline/MovingFunctionAggregation.php | 28 +++++++++++++++ .../MovingFunctionAggregationTest.php | 36 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/Aggregation/Pipeline/MovingFunctionAggregation.php create mode 100644 tests/Unit/Aggregation/Pipeline/MovingFunctionAggregationTest.php diff --git a/src/Aggregation/Pipeline/MovingFunctionAggregation.php b/src/Aggregation/Pipeline/MovingFunctionAggregation.php new file mode 100644 index 0000000..70d587e --- /dev/null +++ b/src/Aggregation/Pipeline/MovingFunctionAggregation.php @@ -0,0 +1,28 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchDSL\Aggregation\Pipeline; + +/** + * Class representing Max Bucket Pipeline Aggregation. + * + * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movfn-aggregation.html + */ +class MovingFunctionAggregation extends AbstractPipelineAggregation +{ + /** + * {@inheritdoc} + */ + public function getType() + { + return 'moving_fn'; + } +} diff --git a/tests/Unit/Aggregation/Pipeline/MovingFunctionAggregationTest.php b/tests/Unit/Aggregation/Pipeline/MovingFunctionAggregationTest.php new file mode 100644 index 0000000..0f769cf --- /dev/null +++ b/tests/Unit/Aggregation/Pipeline/MovingFunctionAggregationTest.php @@ -0,0 +1,36 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Pipeline; + +use ONGR\ElasticsearchDSL\Aggregation\Pipeline\MovingFunctionAggregation; + +/** + * Unit test for sum bucket aggregation. + */ +class MovingFunctionAggregationTest extends \PHPUnit\Framework\TestCase +{ + /** + * Tests toArray method. + */ + public function testToArray() + { + $aggregation = new MovingFunctionAggregation('acme', 'test'); + + $expected = [ + 'moving_fn' => [ + 'buckets_path' => 'test', + ], + ]; + + $this->assertEquals($expected, $aggregation->toArray()); + } +} -- GitLab