Completed
Push — develop ( d73a05...7ce957 )
by Mike
07:24
created

DsnTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidDsn() 0 5 1
A testInvalidScheme() 0 5 1
A testInvalidKeyValuePair() 0 5 1
A testValidDsnWithScheme() 0 24 1
A testValidDsnWithoutScheme() 0 11 1
A testValidWindowsDsnWithoutScheme() 0 17 1
A testValidWindowsDsnWithScheme() 0 11 1
A testCorrectDefaultPorts() 0 10 1
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2018 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor;
14
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * Class DsnTest
19
 * @coversDefaultClass \phpDocumentor\Dsn
20
 */
21
class DsnTest extends TestCase
22
{
23
    /**
24
     * @covers ::__construct
25
     * @covers ::<private>
26
     * @expectedException \InvalidArgumentException
27
     */
28
    public function testInvalidDsn()
29
    {
30
        $dsn = 'git+http://namé:[email protected]';
31
        new Dsn($dsn);
32
    }
33
34
    /**
35
     * @covers ::__construct
36
     * @covers ::<private>
37
     * @expectedException \InvalidArgumentException
38
     */
39
    public function testInvalidScheme()
40
    {
41
        $dsn = 'gittt+http://github.com';
42
        new Dsn($dsn);
43
    }
44
45
    /**
46
     * @covers ::__construct
47
     * @covers ::getScheme
48
     * @covers ::<private>
49
     * @expectedException \InvalidArgumentException
50
     */
51
    public function testInvalidKeyValuePair()
52
    {
53
        $dsn = 'git+http://@github.com/phpDocumentor/phpDocumentor2?q+query';
54
        new Dsn($dsn);
55
    }
56
57
    /**
58
     * @covers ::__construct
59
     * @covers ::__toString
60
     * @covers ::getScheme
61
     * @covers ::getUsername
62
     * @covers ::getPassword
63
     * @covers ::getPort
64
     * @covers ::getHost
65
     * @covers ::getPath
66
     * @covers ::getQuery
67
     * @covers ::getParameters
68
     * @covers ::<private>
69
     * @uses \phpDocumentor\Path
70
     */
71
    public function testValidDsnWithScheme()
72
    {
73
        $dsn = 'git+http://user:[email protected]:8000/phpDocumentor/phpDocumentor2?q=qry1&x=qry2;branch=dev;other=xxx';
74
        $fixture = new Dsn($dsn);
75
        $query = [
76
            'q' => 'qry1',
77
            'x' => 'qry2',
78
        ];
79
80
        $parameters = [
81
            'branch' => 'dev',
82
            'other' => 'xxx',
83
        ];
84
85
        $this->assertEquals($dsn, (string) $fixture);
86
        $this->assertEquals('git+http', $fixture->getScheme());
87
        $this->assertEquals('user', $fixture->getUsername());
88
        $this->assertEquals('pw', $fixture->getPassword());
89
        $this->assertEquals(8000, $fixture->getPort());
90
        $this->assertEquals('github.com', $fixture->getHost());
91
        $this->assertEquals('/phpDocumentor/phpDocumentor2', $fixture->getPath());
92
        $this->assertEquals($query, $fixture->getQuery());
93
        $this->assertEquals($parameters, $fixture->getParameters());
94
    }
95
96
    /**
97
     * @covers ::__construct
98
     * @covers ::__toString
99
     * @covers ::getScheme
100
     * @covers ::getHost
101
     * @covers ::getPort
102
     * @covers ::getPath
103
     * @covers ::<private>
104
     * @uses \phpDocumentor\Path
105
     */
106
    public function testValidDsnWithoutScheme()
107
    {
108
        $dsn = 'src';
109
        $fixture = new Dsn($dsn);
110
111
        $this->assertEquals('file://src', (string) $fixture);
112
        $this->assertEquals('file', $fixture->getScheme());
113
        $this->assertEquals(null, $fixture->getHost());
114
        $this->assertEquals(0, $fixture->getPort());
115
        $this->assertEquals('src', $fixture->getPath());
116
    }
117
118
    /**
119
     * @covers ::__construct
120
     * @covers ::__toString
121
     * @covers ::getScheme
122
     * @covers ::getHost
123
     * @covers ::getPort
124
     * @covers ::getPath
125
     * @covers ::<private>
126
     * @uses \phpDocumentor\Path
127
     */
128
    public function testValidWindowsDsnWithoutScheme()
129
    {
130
        $dsn = 'C:\\phpdocumentor\\tests\\unit\\phpDocumentor\\Infrastructure\\Parser';
131
        $fixture = new Dsn($dsn);
132
133
        $this->assertEquals(
134
            'file://C:\\phpdocumentor\\tests\\unit\\phpDocumentor\\Infrastructure\\Parser',
135
            (string) $fixture
136
        );
137
        $this->assertEquals('file', $fixture->getScheme());
138
        $this->assertEquals(null, $fixture->getHost());
139
        $this->assertEquals(0, $fixture->getPort());
140
        $this->assertEquals(
141
            'C:\\phpdocumentor\\tests\\unit\\phpDocumentor\\Infrastructure\\Parser',
142
            $fixture->getPath()
143
        );
144
    }
145
146
    /**
147
     * @covers ::__construct
148
     * @covers ::__toString
149
     * @covers ::getScheme
150
     * @covers ::getHost
151
     * @covers ::getPort
152
     * @covers ::getPath
153
     * @covers ::<private>
154
     * @uses \phpDocumentor\Path
155
     */
156
    public function testValidWindowsDsnWithScheme()
157
    {
158
        $dsn = 'file://C:\\phpdocumentor\\tests';
159
        $fixture = new Dsn($dsn);
160
161
        $this->assertEquals('file://C:\\phpdocumentor\\tests', (string) $fixture);
162
        $this->assertEquals('file', $fixture->getScheme());
163
        $this->assertEquals(null, $fixture->getHost());
164
        $this->assertEquals(0, $fixture->getPort());
165
        $this->assertEquals('C:\\phpdocumentor\\tests', $fixture->getPath());
166
    }
167
168
    /**
169
     * @covers ::__construct
170
     * @covers ::getScheme
171
     * @covers ::getPort
172
     * @covers ::<private>
173
     */
174
    public function testCorrectDefaultPorts()
175
    {
176
        $dsn = 'git+http://github.com';
177
        $fixture = new Dsn($dsn);
178
        $this->assertEquals(80, $fixture->getPort());
179
180
        $dsn = 'git+https://github.com';
181
        $fixture = new Dsn($dsn);
182
        $this->assertEquals(443, $fixture->getPort());
183
    }
184
}
185