1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AndrewAndante\SubMuncher\Test; |
4
|
|
|
|
5
|
|
|
use AndrewAndante\SubMuncher\SubMuncher; |
6
|
|
|
use AndrewAndante\SubMuncher\Util; |
7
|
|
|
|
8
|
|
|
class RealWorldTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
private $json_data; |
11
|
|
|
|
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
$this->json_data = json_decode(file_get_contents(__DIR__ . '/../data/real_world_data.json'), true); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testConsolidateSubnets() |
19
|
|
|
{ |
20
|
|
|
$this->assertEquals( |
21
|
|
|
$this->json_data['consolidated_subnets'], |
22
|
|
|
SubMuncher::consolidate_subnets($this->json_data['subnets']) |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testConsolidateSubnetsVerbose() |
27
|
|
|
{ |
28
|
|
|
$this->assertEquals( |
29
|
|
|
[ |
30
|
|
|
'consolidated_subnets' => $this->json_data['consolidated_subnets'], |
31
|
|
|
'initial_IPs' => $this->json_data['raw_ips'], |
32
|
|
|
'total_IPs' => $this->json_data['raw_ips'], |
33
|
|
|
], |
34
|
|
|
SubMuncher::consolidate_subnets_verbose($this->json_data['subnets']) |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testConsolidateSubnetsPerformance() |
39
|
|
|
{ |
40
|
|
|
$result = SubMuncher::consolidate_subnets($this->json_data['subnets'], 1); |
41
|
|
|
$this->assertLessThanOrEqual(1, count($result)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testConsolidateSubnetsWithMaxRules() |
45
|
|
|
{ |
46
|
|
|
$result = SubMuncher::consolidate_subnets($this->json_data['subnets'], 25); |
47
|
|
|
$fail = true; |
48
|
|
|
foreach ($this->json_data['raw_ips'] as $ip) { |
49
|
|
|
foreach ($result as $subnet) { |
50
|
|
|
if (Util::cidr_contains($subnet, $ip)) { |
51
|
|
|
$fail = false; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($fail) { |
58
|
|
|
$this->fail($ip . " not contained in any subnets returned"); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
It seems like you are relying on a variable being defined by an iteration: