diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php index fce6f857..2f3099f6 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php @@ -1,8 +1,6 @@ <?php - namespace Elastica\Test\Aggregation; - use Elastica\Aggregation\IpRange; use Elastica\Document; use Elastica\Query; @@ -10,38 +8,42 @@ use Elastica\Type\Mapping; class IpRangeTest extends BaseAggregationTest { - protected function setUp() + protected function _getIndexForTest() { - parent::setUp(); - $this->_index = $this->_createIndex("ip_range"); - $mapping = new Mapping(); - $mapping->setProperties(array( - "address" => array("type" => "ip") + $index = $this->_createIndex(); + $type = $index->getType('test'); + + $type->setMapping(new Mapping(null, array( + 'address' => array('type' => 'ip'), + ))); + + $type->addDocuments(array( + new Document(1, array('address' => '192.168.1.100')), + new Document(2, array('address' => '192.168.1.150')), + new Document(3, array('address' => '192.168.1.200')), )); - $type = $this->_index->getType("test"); - $type->setMapping($mapping); - $docs = array( - new Document("1", array("address" => "192.168.1.100")), - new Document("2", array("address" => "192.168.1.150")), - new Document("3", array("address" => "192.168.1.200")), - ); - $type->addDocuments($docs); - $this->_index->refresh(); + + $index->refresh(); + + return $index; } + /** + * @group functional + */ public function testIpRangeAggregation() { - $agg = new IpRange("ip", "address"); - $agg->addRange("192.168.1.101"); - $agg->addRange(null, "192.168.1.200"); - - $cidrRange = "192.168.1.0/24"; + $agg = new IpRange('ip', 'address'); + $agg->addRange('192.168.1.101'); + $agg->addRange(null, '192.168.1.200'); + + $cidrRange = '192.168.1.0/24'; $agg->addMaskRange($cidrRange); $query = new Query(); $query->addAggregation($agg); - $results = $this->_index->search($query)->getAggregation("ip"); - + $results = $this->_getIndexForTest()->search($query)->getAggregation('ip'); + foreach ($results['buckets'] as $bucket) { if (array_key_exists('key', $bucket) && $bucket['key'] == $cidrRange) { // the CIDR mask @@ -53,4 +55,3 @@ class IpRangeTest extends BaseAggregationTest } } } -
\ No newline at end of file |