DomainTests   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 90
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testTopLevelDomain() 0 7 1
A testEmptyTopLevelDomain() 0 4 1
A testInvalidTopLevelDomain() 0 4 1
A testDomain() 0 7 1
A testInvalidDomain() 0 4 1
A testSubdomain() 0 7 1
A testInvalidSubdomain() 0 4 1
A testSubsubdomain() 0 7 1
1
<?php
2
3
/**
4
 * tollwerk-admin
5
 *
6
 * @category    Tollwerk
7
 * @package     Tollwerk\Admin
8
 * @subpackage  Tollwerk\Admin\Tests
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Tollwerk\Admin\Tests;
38
39
use PHPUnit\Framework\TestCase;
40
use Tollwerk\Admin\Domain\Domain\Domain;
41
use Tollwerk\Admin\Domain\Domain\TopLevelDomain;
42
use Tollwerk\Admin\Domain\Factory\DomainFactory;
43
44
/**
45
 * Domain tests
46
 *
47
 * @package Tollwerk\Admin
48
 * @subpackage Tollwerk\Admin\Tests
49
 */
50
class DomainTests extends TestCase
51
{
52
    /**
53
     * Test a top-level-domain
54
     */
55
    public function testTopLevelDomain()
56
    {
57
        $name = 'com';
58
        $tld = DomainFactory::parseString($name);
59
        $this->assertInstanceOf(TopLevelDomain::class, $tld);
60
        $this->assertEquals($name, strval($tld));
61
    }
62
63
    /**
64
     * Test an empty top-level-domain
65
     *
66
     * @expectedException \RuntimeException
67
     * @expectedExceptionCode 1475351791
68
     */
69
    public function testEmptyTopLevelDomain()
70
    {
71
        DomainFactory::parseString('');
72
    }
73
74
    /**
75
     * Test an invalid top-level-domain
76
     *
77
     * @expectedException \RuntimeException
78
     * @expectedExceptionCode 1475352515
79
     */
80
    public function testInvalidTopLevelDomain()
81
    {
82
        DomainFactory::parseString('123');
83
    }
84
85
    /**
86
     * Test a domain
87
     */
88
    public function testDomain()
89
    {
90
        $name = 'example.com';
91
        $domain = DomainFactory::parseString($name);
92
        $this->assertInstanceOf(Domain::class, $domain);
93
        $this->assertEquals($name, strval($domain));
94
    }
95
96
    /**
97
     * Test an invalid top-level-domain
98
     *
99
     * @expectedException \RuntimeException
100
     * @expectedExceptionCode 1475352664
101
     */
102
    public function testInvalidDomain()
103
    {
104
        DomainFactory::parseString('-.com');
105
    }
106
107
    /**
108
     * Test a subdomain
109
     */
110
    public function testSubdomain()
111
    {
112
        $name = 'www.example.com';
113
        $subdomain = DomainFactory::parseString($name);
114
        $this->assertInstanceOf(Domain::class, $subdomain);
115
        $this->assertEquals($name, strval($subdomain));
116
    }
117
118
    /**
119
     * Test an invalid subdomain
120
     *
121
     * @expectedException \RuntimeException
122
     * @expectedExceptionCode 1475352664
123
     */
124
    public function testInvalidSubdomain()
125
    {
126
        DomainFactory::parseString('-.example.com');
127
    }
128
129
    /**
130
     * Test a subdomain
131
     */
132
    public function testSubsubdomain()
133
    {
134
        $name = 'sub.www.example.com';
135
        $subsubdomain = DomainFactory::parseString($name);
136
        $this->assertInstanceOf(Domain::class, $subsubdomain);
137
        $this->assertEquals($name, strval($subsubdomain));
138
    }
139
}
140