/** * Tests removing ranges from aggregation. */ public function testRemoveAggregationWithFalse() { $range = new RangeAggregation('bar'); $this->assertFalse($range->removeRange(10, 20), 'Range does not exist'); $range->addRange(10, 20); $range->addRange(25, 30, 'test_key'); $this->assertTrue($range->removeRange(10, 20), 'Range removed.'); $this->assertFalse($range->removeRangeByKey('test_key'), 'Keyed ranges are not enabled yet!'); $range->setKeyed(true); $range->addRange(15, 20, 'foo'); $this->assertFalse($range->removeRangeByKey('key'), 'Keyed range does not exist.'); $this->assertTrue($range->removeRangeByKey('foo'), 'Keyed range should be removed.'); }
/** * Tests removeRange method. */ public function testRangeAggregationRemoveRange() { $aggregation = new RangeAggregation('foo'); $aggregation->setField('price'); $aggregation->setKeyed(true); $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, 'get expected array of ranges'); $result = $aggregation->removeRange(500, 700); $this->assertFalse($result, 'returns false after removing not-existing range'); }