diff --git a/Aggregation/CardinalityAggregationTest.php b/Aggregation/CardinalityAggregationTest.php index 1c5d26a69d2aecd62602fb31295dd6f33bbe0099..75b9d19b53f5a8c5887eb2ecfbb25d3dd607cf61 100644 --- a/Aggregation/CardinalityAggregationTest.php +++ b/Aggregation/CardinalityAggregationTest.php @@ -25,33 +25,29 @@ class CardinalityAggregationTest extends \PHPUnit_Framework_TestCase { $aggregation = new CardinalityAggregation('bar'); - // When $script is set. $aggregation->setScript('foo'); $result = $aggregation->getArray(); - $this->assertArrayHasKey('script', $result); - $this->assertEquals('foo', $result['script']); + $this->assertArrayHasKey('script', $result, 'key=script when script is set'); + $this->assertEquals('foo', $result['script'], 'script=foo when scripts name=foo'); - // When $field is set. $aggregation->setField('foo'); $result = $aggregation->getArray(); - $this->assertArrayHasKey('field', $result); - $this->assertEquals('foo', $result['field']); + $this->assertArrayHasKey('field', $result, 'key=field when field is set'); + $this->assertEquals('foo', $result['field'], 'field=foo when fields name=foo'); - // When $precisionThreshold is set. $aggregation->setPrecisionThreshold(10); $result = $aggregation->getArray(); - $this->assertArrayHasKey('precision_threshold', $result); - $this->assertEquals(10, $result['precision_threshold']); + $this->assertArrayHasKey('precision_threshold', $result, 'key=precision_threshold when is set'); + $this->assertEquals(10, $result['precision_threshold'], 'precision_threshold=10 when is set'); - // When $rehash is set. $aggregation->setRehash(true); $result = $aggregation->getArray(); - $this->assertArrayHasKey('rehash', $result); - $this->assertEquals(true, $result['rehash']); + $this->assertArrayHasKey('rehash', $result, 'key=rehash when rehash is set'); + $this->assertEquals(true, $result['rehash'], 'rehash=true when rehash is set to true'); } /** diff --git a/Aggregation/GeoBoundsAggregationTest.php b/Aggregation/GeoBoundsAggregationTest.php index 25eb2d781d14e53957c80845c8468b50f1ae47b7..829f371ef59cff8252d6d1f15b44de6d737ff42a 100644 --- a/Aggregation/GeoBoundsAggregationTest.php +++ b/Aggregation/GeoBoundsAggregationTest.php @@ -46,14 +46,26 @@ class GeoBoundsAggregationTest extends \PHPUnit_Framework_TestCase { $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']); + $result = [ + 'agg_foo' => [ + 'geo_bounds' => [ + 'field' => 'bar', + 'wrap_longitude' => true, + ], + ], + ]; + $this->assertEquals($result, $agg->toArray(), 'when wraplongitude is true'); + + $agg->setWrapLongitude(false); + $result = [ + 'agg_foo' => [ + 'geo_bounds' => [ + 'field' => 'bar', + 'wrap_longitude' => false, + ], + ], + ]; + $this->assertEquals($result, $agg->toArray(), 'when wraplongitude is false'); } } diff --git a/Aggregation/GlobalAggregationTest.php b/Aggregation/GlobalAggregationTest.php index 127e7f56e3a675fa16713095272e83b3c47d000f..351c27e2b932718dbad4965e40ebc8e509ba7c7d 100644 --- a/Aggregation/GlobalAggregationTest.php +++ b/Aggregation/GlobalAggregationTest.php @@ -79,7 +79,6 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase * Test for setField method on global aggregation. * * @expectedException \LogicException - * @expectedException doesn't support `field` parameter */ public function testSetField() { diff --git a/Aggregation/MissingAggregationTest.php b/Aggregation/MissingAggregationTest.php index 52b63fca0fd75e454b7c1617122abe7355eba9eb..300971ef16150a4cde2de255ed66b4900d06f951 100644 --- a/Aggregation/MissingAggregationTest.php +++ b/Aggregation/MissingAggregationTest.php @@ -36,7 +36,6 @@ class MissingAggregationTest extends \PHPUnit_Framework_TestCase $aggregation->setField('bar'); $result = $aggregation->getArray(); $this->assertEquals('bar', $result['field']); - $this->assertArrayHasKey('field', $result); } /** diff --git a/Aggregation/RangeAggregationTest.php b/Aggregation/RangeAggregationTest.php index 413bdf86a34719f2135aa73ee353b58adc929b09..fe8c317c7ecf48201d3329f3be51c25aeb4e5f61 100644 --- a/Aggregation/RangeAggregationTest.php +++ b/Aggregation/RangeAggregationTest.php @@ -20,7 +20,6 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase */ public function testRangeAggregationAddRange() { - // Case #0 single range. $aggregation = new RangeAggregation('test_agg'); $aggregation->setField('test_field'); $aggregation->addRange('10', 20); @@ -48,7 +47,6 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase */ public function testRangeAggregationAddRangeMultiple() { - // Case #1 multiple keyed ranges. $aggregation = new RangeAggregation('test_agg'); $aggregation->setField('test_field'); $aggregation->setKeyed(true); @@ -82,7 +80,6 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase */ public function testRangeAggregationAddRangeNested() { - // Case #2 nested aggregation. $aggregation = new RangeAggregation('test_agg'); $aggregation->setField('test_field'); $aggregation->addRange('10', '10'); @@ -134,67 +131,49 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase } /** - * Data provider for testRangeAggregationRemoveRangeByKey(), testRangeAggregationRemoveRange(). - * - * @return array + * Tests removeRangeByKey method. */ - public function testRangeAggregationDataProvider() + public function testRangeAggregationRemoveRangeByKey() { - $expectedResults = [ + $aggregation = new RangeAggregation('foo'); + $aggregation->setField('price'); + $aggregation->setKeyed(true); + $aggregation->addRange(100, 300, 'name'); + + $expected = [ 'field' => 'price', 'keyed' => true, 'ranges' => [ [ 'from' => 100, 'to' => 300, - 'key' => 'key', + 'key' => 'name', ], ], ]; - return [[$expectedResults]]; - } - - /** - * Tests removeRangeByKey method. - * - * @param array $expected - * - * @dataProvider testRangeAggregationDataProvider - */ - public function testRangeAggregationRemoveRangeByKey($expected) - { - $aggregation = new RangeAggregation('foo'); - $aggregation->setField('price'); - $aggregation->setKeyed(true); - $aggregation->addRange(100, 300, 'key'); - $result = $aggregation->getArray(); - $this->assertEquals($result, $expected); + $this->assertEquals($result, $expected, 'get array of ranges when keyed=true'); - $result = $aggregation->removeRangeByKey('key'); - $this->assertTrue($result); + $result = $aggregation->removeRangeByKey('name'); + $this->assertTrue($result, 'returns true when removed valid range name'); $result = $aggregation->removeRangeByKey('not_existing_key'); - $this->assertFalse($result); - // Test with keyed=false. + $this->assertFalse($result, 'should not allow remove not existing key if keyed=true'); + $aggregation->setKeyed(false); $result = $aggregation->removeRangeByKey('not_existing_key'); - $this->assertFalse($result); + $this->assertFalse($result, 'should not allow remove not existing key if keyed=false'); - $aggregation->addRange(100, 300, 'key'); - $result = $aggregation->removeRangeByKey('key'); - $this->assertFalse($result); + $aggregation->addRange(100, 300, 'name'); + $result = $aggregation->removeRangeByKey('name'); + $this->assertFalse($result, 'can not remove any existing range if keyed=false'); } /** * Tests removeRange method. - * - * @param array $expected - * - * @dataProvider testRangeAggregationDataProvider */ - public function testRangeAggregationRemoveRange($expected) + public function testRangeAggregationRemoveRange() { $aggregation = new RangeAggregation('foo'); $aggregation->setField('price'); @@ -202,11 +181,22 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase $aggregation->addRange(100, 300, 'key'); $aggregation->addRange(500, 700, 'range_2'); + $expected = [ + 'field' => 'price', + 'keyed' => true, + 'ranges' => [ + [ + 'from' => 100, + 'to' => 300, + 'key' => 'key', + ], + ], + ]; + $aggregation->removeRange(500, 700); $result = $aggregation->getArray(); - $this->assertEquals($result, $expected); - // Test fake ranges. + $this->assertEquals($result, $expected, 'get expected array of ranges'); $result = $aggregation->removeRange(500, 700); - $this->assertFalse($result); + $this->assertFalse($result, 'returns false after removing not-existing range'); } }