UrlToolTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMainDomain_HostMissing_ReturnsMainDomain() 0 5 1
A testIsURL_ValidURL_ReturnsTrue() 0 4 1
A testIsURL_InvalidURL_ReturnsFalse() 0 4 1
A testGetMainDomain_DoubleSuffix_ReturnsMainDomain() 0 5 1
A testGetMainDomain_127_0_0_1_ReturnsEmpty() 0 5 1
A testGetMainDomain_HostExists_ReturnsMainDomain() 0 5 1
A testGetMainDomain_Localhost_ReturnsEmpty() 0 5 1
A testGetMainDomain_TwoParts_ReturnsMainDomain() 0 5 1
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use tinymeng\tools\UrlTool;
5
6
class UrlToolTest extends TestCase
7
{
8
    public function testGetMainDomain_HostExists_ReturnsMainDomain()
9
    {
10
        $url = "http://sub.example.com";
11
        $expected = "example.com";
12
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
13
    }
14
15
    public function testGetMainDomain_HostMissing_ReturnsMainDomain()
16
    {
17
        $url = "sub.example.com";
18
        $expected = "example.com";
19
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
20
    }
21
22
    public function testGetMainDomain_Localhost_ReturnsEmpty()
23
    {
24
        $url = "http://localhost";
25
        $expected = "";
26
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
27
    }
28
29
    public function testGetMainDomain_127_0_0_1_ReturnsEmpty()
30
    {
31
        $url = "http://127.0.0.1";
32
        $expected = "";
33
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
34
    }
35
36
    public function testGetMainDomain_DoubleSuffix_ReturnsMainDomain()
37
    {
38
        $url = "http://sub.example.com.cn";
39
        $expected = "example.com.cn";
40
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
41
    }
42
43
    public function testGetMainDomain_TwoParts_ReturnsMainDomain()
44
    {
45
        $url = "http://example.com";
46
        $expected = "example.com";
47
        $this->assertEquals($expected, UrlTool::getMainDomain($url));
48
    }
49
50
    public function testIsURL_ValidURL_ReturnsTrue()
51
    {
52
        $url = "http://example.com";
53
        $this->assertTrue((new UrlTool)->isURL($url));
54
    }
55
56
    public function testIsURL_InvalidURL_ReturnsFalse()
57
    {
58
        $url = "example.com";
59
        $this->assertFalse((new UrlTool)->isURL($url));
60
    }
61
}
62