Completed
Push — issue#666 ( 5c565a...94715f )
by Guilherme
03:27
created

HttpUriTest::testInvalidUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\RemoteClaimsBundle\Tests\Model;
12
13
use LoginCidadao\RemoteClaimsBundle\Model\HttpUri;
14
15
class HttpUriTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testValidCompleteUri()
18
    {
19
        $uri = 'https://user:[email protected]:8042/over/there?name=ferret#nose';
20
        $http = HttpUri::createFromString($uri);
21
22
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\HttpUri', $http);
23
        $this->assertEquals($uri, $http->__toString());
24
        $this->assertEquals('https', $http->getScheme());
25
        $this->assertEquals('user:password', $http->getUserInfo());
26
        $this->assertEquals('example.com', $http->getHost());
27
        $this->assertEquals(8042, $http->getPort());
28
        $this->assertEquals('user:[email protected]:8042', $http->getAuthority());
29
        $this->assertEquals('/over/there', $http->getPath());
30
        $this->assertEquals('name=ferret', $http->getQuery());
31
        $this->assertEquals('nose', $http->getFragment());
32
    }
33
34
    public function testValidSimpleUri()
35
    {
36
        $uri = 'http://example.com';
37
        $http = HttpUri::createFromString($uri);
38
39
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\HttpUri', $http);
40
        $this->assertEquals($uri, $http->__toString());
41
        $this->assertEquals('http', $http->getScheme());
42
        $this->assertEquals('', $http->getUserInfo());
43
        $this->assertEquals('example.com', $http->getHost());
44
        $this->assertNull($http->getPort());
45
        $this->assertEquals('example.com', $http->getAuthority());
46
        $this->assertEquals('', $http->getPath());
47
        $this->assertEquals('', $http->getQuery());
48
        $this->assertEquals('', $http->getFragment());
49
    }
50
51
    public function testWithMethods()
52
    {
53
        $http = (new HttpUri())
54
            ->withScheme('https')
55
            ->withUserInfo('user', 'password')
56
            ->withHost('example.com')
57
            ->withPort(8042)
58
            ->withPath('/over/there')
59
            ->withQuery('name=ferret')
60
            ->withFragment('nose');
61
62
        $uri = 'https://user:[email protected]:8042/over/there?name=ferret#nose';
63
        $this->assertEquals($uri, $http->__toString());
64
    }
65
66
    public function testInvalidUri()
67
    {
68
        $this->setExpectedException('\InvalidArgumentException');
69
        $uri = 'not valid';
70
        HttpUri::createFromString($uri);
71
    }
72
73
    public function testInvalidScheme()
74
    {
75
        $this->setExpectedException('\InvalidArgumentException');
76
        $uri = 'ftp://example.com';
77
        HttpUri::createFromString($uri);
78
    }
79
80
    public function testInvalidHost()
81
    {
82
        $this->setExpectedException('\InvalidArgumentException');
83
        $uri = 'https://not valid.com';
84
        HttpUri::createFromString($uri);
85
    }
86
87
    public function testInvalidPath()
88
    {
89
        $this->setExpectedException('\InvalidArgumentException');
90
        $uri = 'https://example.com/not valid';
91
        HttpUri::createFromString($uri);
92
    }
93
}
94