-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathHostRecordTest.php
More file actions
85 lines (75 loc) · 2.35 KB
/
HostRecordTest.php
File metadata and controls
85 lines (75 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Uri;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class HostRecordTest extends TestCase
{
#[Test]
#[DataProvider('provideRecordsForIpTesting')]
public function it_can_tell_if_a_record_is_an_ip_address(
?string $address,
bool $isIp,
bool $isRegisteredName,
bool $isDomain
): void {
self::assertSame($isIp, HostRecord::isIp($address));
self::assertSame($isRegisteredName, HostRecord::isRegisteredName($address));
self::assertSame($isDomain, HostRecord::isDomain($address));
}
/**
* @return iterable<non-empty-string, array{
* address: ?string,
* isIp: bool,
* isRegisteredName: bool,
* isDomain: bool,
* }>
*/
public static function provideRecordsForIpTesting(): iterable
{
yield 'a null host is not an IP address' => [
'address' => null,
'isIp' => false,
'isRegisteredName' => true,
'isDomain' => true,
];
yield 'a registerable host is not an IP address' => [
'address' => 'example.com',
'isIp' => false,
'isRegisteredName' => true,
'isDomain' => true,
];
yield 'a IPv4 host is an IP address' => [
'address' => '127.0.0.1',
'isIp' => true,
'isRegisteredName' => false,
'isDomain' => false,
];
yield 'a IPv6 host is an IP address' => [
'address' => '[::1]',
'isIp' => true,
'isRegisteredName' => false,
'isDomain' => false,
];
yield 'a IPvFuture host is an IP address' => [
'address' => '[v8.1.2.3]',
'isIp' => true,
'isRegisteredName' => false,
'isDomain' => false,
];
yield 'a random string not registrable is not an IP address' => [
'address' => '\/?:^',
'isIp' => false,
'isRegisteredName' => false,
'isDomain' => false,
];
}
}