Skip to content
Snippets Groups Projects
Commit e7021ffc authored by Mantas Simkus's avatar Mantas Simkus
Browse files

Added tests, improved coverage

parent 6b01b9e2
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -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']);
}
}
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment