Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4792898
IPTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
IPTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Tests\Network
;
use
Keruald\OmniTools\Network\IP
;
use
PHPUnit\Framework\TestCase
;
class
IPTest
extends
TestCase
{
///
/// Data providers for IP addresses
///
/// These data providers methods allow to provide IP addresses
/// to validate or invalidate.
///
/// The advanced IPv6 tests have been curated by Stephen Ryan
/// Source: https://web.archive.org/web/20110515134717/http://forums.dartware.com/viewtopic.php?t=452
///
public
function
provideValidIP
()
:
iterable
{
yield
[
"0.0.0.0"
];
yield
[
"17.17.17.17"
];
yield
[
"fe80:0000:0000:0000:0204:61ff:fe9d:f156"
];
}
public
function
provideInvalidIP
()
:
iterable
{
yield
[
""
];
yield
[
"1"
];
yield
[
"17.17"
];
yield
[
"17.17.17.256"
];
}
public
function
provideValidIPv4
()
:
iterable
{
return
[[
"0.0.0.0"
],
[
"17.17.17.17"
]];
}
public
function
provideInvalidIPv4
()
:
iterable
{
yield
[
""
];
yield
[
"1"
];
yield
[
"17.17"
];
yield
[
"17.17.17.256"
];
yield
[
"fe80:0000:0000:0000:0204:61ff:fe9d:f156"
];
}
public
function
provideValidIPv6
()
:
iterable
{
yield
[
"::1"
];
yield
[
"::ffff:192.0.2.128"
];
yield
[
"fe80:0000:0000:0000:0204:61ff:fe9d:f156"
];
yield
[
"::ffff:192.0.2.128"
,
"IPv4 represented as dotted-quads"
];
}
public
function
provideInvalidIPv6
()
:
iterable
{
yield
[
"0.0.0.0"
];
yield
[
""
];
yield
[
"1"
];
yield
[
"17.17"
];
yield
[
"17.17.17.17"
];
yield
[
"::fg"
,
"Valid IPv6 digits are 0-f, ie 0-9 and a-f"
];
yield
[
"02001:0000:1234:0000:0000:C1C0:ABCD:0876"
,
"Extra 0"
];
yield
[
"2001:0000:1234:0000:00001:C1C0:ABCD:0876"
,
"Extra 0"
];
yield
[
"1.2.3.4:1111:2222:3333:4444::5555"
];
}
///
/// Test cases
///
/**
* @covers \Keruald\OmniTools\Network\IP::isIP
* @dataProvider provideValidIP
*/
public
function
testIsIP
(
$ip
)
{
$this
->
assertTrue
(
IP
::
isIP
(
$ip
));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIP
* @dataProvider provideInvalidIP
*/
public
function
testIsIPWhenItIsNot
(
$ip
)
{
$this
->
assertFalse
(
IP
::
isIP
(
$ip
));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv4
* @dataProvider provideValidIPv4
*/
public
function
testIsIPv4
(
$ip
)
{
$this
->
assertTrue
(
IP
::
isIPv4
(
$ip
));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv4
* @dataProvider provideInvalidIPv4
*/
public
function
testIsIPv4WhenItIsNot
(
$ip
)
{
$this
->
assertFalse
(
IP
::
isIPv4
(
$ip
));
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv6
* @dataProvider provideValidIPv6
*/
public
function
testIsIPv6
(
string
$ip
,
string
$message
=
""
)
{
$this
->
assertTrue
(
IP
::
isIPv6
(
$ip
),
$message
);
}
/**
* @covers \Keruald\OmniTools\Network\IP::isIPv6
* @dataProvider provideInvalidIPv6
*/
public
function
testIsIPv6WhenItIsNot
(
string
$ip
,
string
$message
=
""
)
:
void
{
$this
->
assertFalse
(
IP
::
isIPv6
(
$ip
),
$message
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 21:39 (22 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2436989
Default Alt Text
IPTest.php (3 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment