Completed
Push — develop ( 114abf...08add9 )
by Jaap
03:44
created

DsnTest::testInvalidScheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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 ::getScheme
132
     * @covers ::getPort
133
     * @covers ::<private>
134
     */
135
    public function testCorrectDefaultPorts()
136
    {
137
        $dsn ="git+http://github.com";
138
        $fixture = new Dsn($dsn);
139
        $this->assertEquals(80, $fixture->getPort());
140
141
        $dsn ="git+https://github.com";
142
        $fixture = new Dsn($dsn);
143
        $this->assertEquals(443, $fixture->getPort());
144
    }
145
}
146