diff --git a/Aggregation/ChildrenAggregationTest.php b/Aggregation/ChildrenAggregationTest.php index fc264d69bb26d8c823edcf51237064e0e8ee2bce..e050d87ad77a969898e7d7120613deeedd479192 100644 --- a/Aggregation/ChildrenAggregationTest.php +++ b/Aggregation/ChildrenAggregationTest.php @@ -28,4 +28,27 @@ class ChildrenAggregationTest extends \PHPUnit_Framework_TestCase $aggregation = new ChildrenAggregation('foo'); $aggregation->getArray(); } + + /** + * Tests getType method. + */ + public function testChildrenAggregationGetType() + { + $aggregation = new ChildrenAggregation('foo'); + $result = $aggregation->getType(); + $this->assertEquals('children', $result); + } + + /** + * Tests getArray method. + */ + public function testChildrenAggregationGetArray() + { + $mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Aggregation\AbstractAggregation') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $aggregation = new ChildrenAggregation('foo'); + $aggregation->addAggregation($mock); + $aggregation->getArray(); + } } diff --git a/Aggregation/DateRangeAggregationTest.php b/Aggregation/DateRangeAggregationTest.php index 26081ef0cff2e1a6500e5d5ac54f11b2a69f39b5..f2643adaaf0d311824f8245c51fea4bc0aac5c98 100644 --- a/Aggregation/DateRangeAggregationTest.php +++ b/Aggregation/DateRangeAggregationTest.php @@ -38,4 +38,32 @@ class DateRangeAggregationTest extends \PHPUnit_Framework_TestCase $agg = new DateRangeAggregation('test_agg'); $agg->addRange(null, null); } + + /** + * Test getArray method. + */ + public function testDateRangeAggregationGetArray() + { + $agg = new DateRangeAggregation('foo'); + $agg->addRange(10, 20); + $agg->setFormat('bar'); + $agg->setField('baz'); + $result = $agg->getArray(); + $expected = [ + 'format' => 'bar', + 'field' => 'baz', + 'ranges' => [['from' => 10, 'to' => 20]], + ]; + $this->assertEquals($expected, $result); + } + + /** + * Tests getType method. + */ + public function testDateRangeAggregationGetType() + { + $aggregation = new DateRangeAggregation('foo'); + $result = $aggregation->getType(); + $this->assertEquals('date_range', $result); + } } diff --git a/Aggregation/FiltersAggregationTest.php b/Aggregation/FiltersAggregationTest.php index 4bdcc2a5c454e958aa4600252600438ebb21180d..38c9cae2ab577436b14891ea8b8bdbaa27862297 100644 --- a/Aggregation/FiltersAggregationTest.php +++ b/Aggregation/FiltersAggregationTest.php @@ -30,4 +30,71 @@ class FiltersAggregationTest extends \PHPUnit_Framework_TestCase $aggregation = new FiltersAggregation('test_agg'); $aggregation->addFilter($mock); } + + /** + * Test GetArray method. + */ + public function testFiltersAggregationGetArray() + { + $mock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\BuilderInterface')->getMock(); + $aggregation = new FiltersAggregation('test_agg'); + $aggregation->setAnonymous(true); + $aggregation->addFilter($mock, 'name'); + $result = $aggregation->getArray(); + $this->assertArrayHasKey('filters', $result); + } + + /** + * Tests getType method. + */ + public function testFiltersAggregationGetType() + { + $aggregation = new FiltersAggregation('foo'); + $result = $aggregation->getType(); + $this->assertEquals('filters', $result); + } + + /** + * Test for filter aggregation toArray() method. + */ + public function testToArray() + { + $aggregation = new FiltersAggregation('test_agg'); + $filter = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\BuilderInterface') + ->setMethods(['toArray', 'getType']) + ->getMockForAbstractClass(); + $filter->expects($this->any()) + ->method('getType') + ->willReturn('test_filter'); + $filter->expects($this->any()) + ->method('toArray') + ->willReturn(['test_field' => ['test_value' => 'test']]); + + $aggregation->addFilter($filter, 'first'); + $aggregation->addFilter($filter, 'second'); + $results = $aggregation->toArray(); + $expected = [ + 'agg_test_agg' => [ + 'filters' => [ + 'filters' => [ + 'first' => [ + 'test_filter' => [ + 'test_field' => [ + 'test_value' => 'test', + ], + ], + ], + 'second' => [ + 'test_filter' => [ + 'test_field' => [ + 'test_value' => 'test', + ], + ], + ], + ], + ], + ], + ]; + $this->assertEquals($expected, $results); + } } diff --git a/Aggregation/GeoBoundsAggregationTest.php b/Aggregation/GeoBoundsAggregationTest.php index d1ede4672dc7005adb5626e7d6314739ac2f5a81..25eb2d781d14e53957c80845c8468b50f1ae47b7 100644 --- a/Aggregation/GeoBoundsAggregationTest.php +++ b/Aggregation/GeoBoundsAggregationTest.php @@ -28,4 +28,32 @@ class GeoBoundsAggregationTest extends \PHPUnit_Framework_TestCase $agg = new GeoBoundsAggregation('test_agg'); $agg->getArray(); } + + /** + * Tests getType method. + */ + public function testGeoBoundsAggregationGetType() + { + $agg = new GeoBoundsAggregation('foo'); + $result = $agg->getType(); + $this->assertEquals('geo_bounds', $result); + } + + /** + * Tests getArray method. + */ + public function testGeoBoundsAggregationGetArray() + { + $agg = new GeoBoundsAggregation('foo'); + $agg->setField('bar'); + $agg->setWrapLongitude(false); + $result = $agg->getArray(); + $this->assertArrayHasKey('field', $result); + $this->assertArrayHasKey('wrap_longitude', $result); + $this->assertEquals('bar', $result['field']); + $this->assertFalse($result['wrap_longitude']); + $agg->setWrapLongitude(true); + $result = $agg->getArray(); + $this->assertTrue($result['wrap_longitude']); + } } diff --git a/Aggregation/GeoDistanceAggregationTest.php b/Aggregation/GeoDistanceAggregationTest.php index 73075a6b2c18a78e408b55795921847221ad4503..4dd3e0ece475d757f7a795f3df2257bd988adf95 100644 --- a/Aggregation/GeoDistanceAggregationTest.php +++ b/Aggregation/GeoDistanceAggregationTest.php @@ -52,4 +52,64 @@ class GeoDistanceAggregationTest extends \PHPUnit_Framework_TestCase $agg = new GeoDistanceAggregation('test_agg'); $agg->addRange(); } + + /** + * Data provider for testGeoDistanceAggregationGetArray(). + * + * @return array + */ + public function testGeoDistanceAggregationGetArrayDataProvider() + { + $out = []; + $filterData = [ + 'field' => 'location', + 'origin' => '52.3760, 4.894', + 'unit' => 'mi', + 'distance_type' => 'plane', + 'ranges' => [100, 300], + ]; + + $expectedResults = [ + 'field' => 'location', + 'origin' => '52.3760, 4.894', + 'unit' => 'mi', + 'distance_type' => 'plane', + 'ranges' => [['from' => 100, 'to' => 300]], + ]; + + $out[] = [$filterData, $expectedResults]; + + return $out; + } + + /** + * Tests getArray method. + * + * @param array $filterData + * @param array $expected + * + * @dataProvider testGeoDistanceAggregationGetArrayDataProvider + */ + public function testGeoDistanceAggregationGetArray($filterData, $expected) + { + $aggregation = new GeoDistanceAggregation('foo'); + $aggregation->setOrigin($filterData['origin']); + $aggregation->setField($filterData['field']); + $aggregation->setUnit($filterData['unit']); + $aggregation->setDistanceType($filterData['distance_type']); + $aggregation->addRange($filterData['ranges'][0], $filterData['ranges'][1]); + + $result = $aggregation->getArray(); + $this->assertEquals($result, $expected); + } + + /** + * Tests getType method. + */ + public function testGeoDistanceAggregationGetType() + { + $aggregation = new GeoDistanceAggregation('foo'); + $result = $aggregation->getType(); + $this->assertEquals('geo_distance', $result); + } } diff --git a/Aggregation/GeoHashGridAggregationTest.php b/Aggregation/GeoHashGridAggregationTest.php index 0a520e9fe28f99f9afcbce6e0d45359150da080f..aac572646b759121e1621439afaa6e8b4d749e4c 100644 --- a/Aggregation/GeoHashGridAggregationTest.php +++ b/Aggregation/GeoHashGridAggregationTest.php @@ -28,4 +28,62 @@ class GeoHashGridAggregationTest extends \PHPUnit_Framework_TestCase $agg = new GeoHashGridAggregation('test_agg'); $agg->getArray(); } + + /** + * Data provider for testGeoHashGridAggregationGetArray(). + * + * @return array + */ + public function getArrayDataProvider() + { + $out = []; + + $filterData = [ + 'field' => 'location', + 'precision' => 3, + 'size' => 10, + 'shard_size' => 10, + ]; + + $expectedResults = [ + 'field' => 'location', + 'precision' => 3, + 'size' => 10, + 'shard_size' => 10, + ]; + + $out[] = [$filterData, $expectedResults]; + + return $out; + } + + /** + * Tests getArray method. + * + * @param array $filterData + * @param array $expected + * + * @dataProvider getArrayDataProvider + */ + public function testGeoHashGridAggregationGetArray($filterData, $expected) + { + $aggregation = new GeoHashGridAggregation('foo'); + $aggregation->setPrecision($filterData['precision']); + $aggregation->setSize($filterData['size']); + $aggregation->setShardSize($filterData['shard_size']); + $aggregation->setField($filterData['field']); + + $result = $aggregation->getArray(); + $this->assertEquals($result, $expected); + } + + /** + * Tests getType method. + */ + public function testGeoHashGridAggregationGetType() + { + $aggregation = new GeoHashGridAggregation('foo'); + $result = $aggregation->getType(); + $this->assertEquals('geohash_grid', $result); + } } diff --git a/Aggregation/MissingAggregationTest.php b/Aggregation/MissingAggregationTest.php index df8e0b164e36068b38f2d49d4c3cc1b687e808e1..52b63fca0fd75e454b7c1617122abe7355eba9eb 100644 --- a/Aggregation/MissingAggregationTest.php +++ b/Aggregation/MissingAggregationTest.php @@ -26,4 +26,26 @@ class MissingAggregationTest extends \PHPUnit_Framework_TestCase $agg = new MissingAggregation('test_agg'); $agg->getArray(); } + + /** + * Test getArray method. + */ + public function testMissingAggregationGetArray() + { + $aggregation = new MissingAggregation('foo'); + $aggregation->setField('bar'); + $result = $aggregation->getArray(); + $this->assertEquals('bar', $result['field']); + $this->assertArrayHasKey('field', $result); + } + + /** + * Test getType method. + */ + public function testMissingAggregationGetType() + { + $aggregation = new MissingAggregation('bar'); + $result = $aggregation->getType(); + $this->assertEquals('missing', $result); + } }