Completed
Push — develop ( b67add...4b36a1 )
by Jaap
03:57 queued 24s
created

DsnTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 170
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

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