/** * Tests removeRangeByKey method. */ public function testRangeAggregationRemoveRangeByKey() { $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' => 'name']]]; $result = $aggregation->getArray(); $this->assertEquals($result, $expected, 'get array of ranges when keyed=true'); $result = $aggregation->removeRangeByKey('name'); $this->assertTrue($result, 'returns true when removed valid range name'); $result = $aggregation->removeRangeByKey('not_existing_key'); $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, 'should not allow remove not existing key if keyed=false'); $aggregation->addRange(100, 300, 'name'); $result = $aggregation->removeRangeByKey('name'); $this->assertFalse($result, 'can not remove any existing range if keyed=false'); }