Skip to content

Commit

Permalink
feat: add test for checking ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisros committed Feb 2, 2023
1 parent 04b5272 commit 0419a04
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/IpTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@ public static function validateIp(string $ipaddress): bool
{
if (filter_var($ipaddress, FILTER_VALIDATE_IP)) {
return true;
} else {
return false;
}

return false;
}

public static function isIpv6(string $ipaddress): bool
{
if(filter_var($ipaddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return true;
}

return false;
}

public static function isIpv4(string $ipaddress): bool
{
if(filter_var($ipaddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return true;
}

return false;
}

public static function isIpInRange($ip, $range): bool
Expand Down
15 changes: 15 additions & 0 deletions tests/IpToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ public function testValidateIpAddress()
$this->assertFalse(\JorisRos\IpTools::validateIp('ipaddress'));
}

public function testValidationIpAddressV6()
{
$this->assertTrue(\JorisRos\IpTools::validateIp('2234:0000:0000:6904:0019:d2ff:feb3:5e4f'));
$this->assertTrue(\JorisRos\IpTools::validateIp('0000:0000:0000:0000:0000:0000:0000:0001'));
$this->assertTrue(\JorisRos\IpTools::validateIp('::1'));
}

public function testTypeOfIpAddress()
{
$this->assertTrue(\JorisRos\IpTools::isIpv4('127.0.0.1'));
$this->assertFalse(\JorisRos\IpTools::isIpv4('2234:0000:0000:6904:0019:d2ff:feb3:5e4f'));
$this->assertFalse(\JorisRos\IpTools::isIpv6('127.0.0.1'));
$this->assertTrue(\JorisRos\IpTools::isIpv6('2234:0000:0000:6904:0019:d2ff:feb3:5e4f'));
}

public function testDetermRange()
{
$method = new ReflectionMethod('\JorisRos\IpTools', 'determRange');
Expand Down

0 comments on commit 0419a04

Please sign in to comment.