1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AndrewAndante\SubMuncher\Test; |
4
|
|
|
|
5
|
|
|
use AndrewAndante\SubMuncher\SubMuncher; |
6
|
|
|
|
7
|
|
|
class RealWorldTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
private $data; |
|
|
|
|
10
|
|
|
|
11
|
|
|
protected function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
$this->data = json_decode(file_get_contents(__DIR__ . '/../data/real_world_data.json'), true); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testConsolidateSubnets() |
18
|
|
|
{ |
19
|
|
|
$this->assertEquals( |
20
|
|
|
$this->data['consolidated_subnets'], |
21
|
|
|
SubMuncher::consolidate_subnets($this->data['subnets']) |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testConsolidateSubnetsVerbose() |
26
|
|
|
{ |
27
|
|
|
$this->assertEquals( |
28
|
|
|
[ |
29
|
|
|
'consolidated_subnets' => $this->data['consolidated_subnets'], |
30
|
|
|
'initial_IPs' => $this->data['raw_ips'], |
31
|
|
|
'total_IPs' => $this->data['raw_ips'], |
32
|
|
|
], |
33
|
|
|
SubMuncher::consolidate_subnets_verbose($this->data['subnets']) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testConsolidateSubnetsVerboseWithMaxRules() |
38
|
|
|
{ |
39
|
|
|
$result = SubMuncher::consolidate_subnets_verbose($this->data['subnets'], 25); |
40
|
|
|
$this->assertCount(25, $result['consolidated_subnets']); |
41
|
|
|
$this->assertEquals($this->data['raw_ips'], $result['initial_IPs']); |
42
|
|
|
$this->assertGreaterThanOrEqual(count($this->data['raw_ips']), count($result['total_IPs'])); |
43
|
|
|
foreach ($this->data['raw_ips'] as $raw_ip) { |
44
|
|
|
$this->assertContains($raw_ip, $result['total_IPs']); |
45
|
|
|
} |
46
|
|
|
$this->assertEquals( |
47
|
|
|
['205.234.225.128', '205.234.225.131', '60.254.186.52', '60.254.186.55'], |
48
|
|
|
array_values(array_diff($result['total_IPs'], $result['initial_IPs'])) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|