assertNotNull($res); $this->assertSame(ip2long('192.168.1.0'), $res['start']); $this->assertSame(ip2long('192.168.1.255'), $res['end']); } public function testParseCidrSingleIp(): void { $res = IpUtil::parseCidr('10.0.0.1'); $this->assertNotNull($res); $this->assertSame(ip2long('10.0.0.1'), $res['start']); $this->assertSame(ip2long('10.0.0.1'), $res['end']); } public function testParseCidrInvalid(): void { $this->assertNull(IpUtil::parseCidr('1.2.3.4/33')); $this->assertNull(IpUtil::parseCidr('not-an-ip')); } public function testIsValidSubnetRange(): void { $start = ip2long('192.168.0.0'); $end = ip2long('192.168.0.255'); $this->assertTrue(IpUtil::isValidSubnetRange($start, $end)); $start = ip2long('192.168.0.1'); $end = ip2long('192.168.0.254'); $this->assertFalse(IpUtil::isValidSubnetRange($start, $end)); // single IP should be considered a valid /32 range $ip = ip2long('10.0.0.1'); $this->assertTrue(IpUtil::isValidSubnetRange($ip, $ip)); } public function testRangeToCidrValid(): void { $start = ip2long('192.168.2.0'); $end = ip2long('192.168.2.255'); $this->assertSame('192.168.2.0/24', IpUtil::rangeToCidr($start, $end)); } public function testRangeToCidrNotSubnet(): void { $start = ip2long('192.168.5.1'); $end = ip2long('192.168.5.254'); $this->assertSame( 'NOT SUBNET: 192.168.5.1-192.168.5.254', IpUtil::rangeToCidr($start, $end) ); } }