UriTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 100
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_return_root_domain() 0 4 1
A rootDomainProvider() 0 11 1
A it_can_return_last_dir() 0 4 1
A lastDirProvider() 0 10 1
A it_can_detect_image() 0 4 1
A imageProvider() 0 11 1
A it_can_detect_absolute_uris() 0 4 1
A isAbsoluteProvider() 0 8 1
A it_can_transform_a_relative_uri_into_an_absolute_url() 0 4 1
A toAbsoluteUrlProvider() 0 8 1
1
<?php
2
3
namespace Fetcher\Tests;
4
5
use Fetcher\Uri;
6
use Fetcher\Url;
7
8
class UriTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @test
12
     * @dataProvider rootDomainProvider
13
     */
14
    public function it_can_return_root_domain($uri, $expected)
15
    {
16
        $this->assertEquals($expected, (new Uri($uri))->getRootDomain());
17
    }
18
19
    public function rootDomainProvider()
20
    {
21
        return array(
22
            array('http://example.org/a/b/c.html', 'http://example.org/'),
23
            array('http://example.org/a/b.html', 'http://example.org/'),
24
            array('http://example.org/b.html', 'http://example.org/'),
25
            array('http://example.org/a/', 'http://example.org/'),
26
            array('http://example.org/', 'http://example.org/'),
27
            array('http://example.org', 'http://example.org/'),
28
        );
29
    }
30
31
    /**
32
     * @test
33
     * @dataProvider lastDirProvider
34
     */
35
    public function it_can_return_last_dir($uri, $expected)
36
    {
37
        $this->assertEquals($expected, (new Uri($uri))->getLastDir());
38
    }
39
40
    public function lastDirProvider()
41
    {
42
        return array(
43
            array('http://example.org/a/b/c.html', 'http://example.org/a/b/'),
44
            array('http://example.org/a/b.html', 'http://example.org/a/'),
45
            array('http://example.org/a/', 'http://example.org/a/'),
46
            array('http://example.org/', 'http://example.org/'),
47
            array('http://example.org', 'http://example.org/'),
48
        );
49
    }
50
51
    /**
52
     * @test
53
     * @dataProvider imageProvider
54
     */
55
    public function it_can_detect_image($uri, $expected)
56
    {
57
        $this->assertEquals($expected, (new Uri($uri))->isImage());
58
    }
59
60
    public function imageProvider()
61
    {
62
        return array(
63
            array('http://example.org/image.png', true),
64
            array('http://example.org/IMAGE.PNG', true),
65
            array('http://example.org/image.gif', true),
66
            array('http://example.org/image.jpg', true),
67
            array('http://example.org/image.jpeg', true),
68
            array('http://example.org/a.html', false),
69
        );
70
    }
71
72
    /**
73
     * @test
74
     * @dataProvider isAbsoluteProvider
75
     */
76
    public function it_can_detect_absolute_uris($uri, $expected)
77
    {
78
        $this->assertEquals($expected, (new Uri($uri))->isAbsolute());
79
    }
80
81
    public function isAbsoluteProvider()
82
    {
83
        return array(
84
            array('http://example.org/', true),
85
            array('https://example.org/', true),
86
            array('a/b/c.html', false),
87
        );
88
    }
89
90
    /**
91
     * @test
92
     * @dataProvider toAbsoluteUrlProvider
93
     */
94
    public function it_can_transform_a_relative_uri_into_an_absolute_url($url, $uri, $expected)
95
    {
96
        $this->assertEquals($expected, (string) (new Uri($uri))->toAbsoluteUrl(new Url($url)));
97
    }
98
99
    public function toAbsoluteUrlProvider()
100
    {
101
        return array(
102
            array('http://www.example.org/', 'a.html', 'http://www.example.org/a.html'),
103
            array('http://www.example.org/a/b.html', 'c.html', 'http://www.example.org/a/c.html'),
104
            array('http://www.example.org/a/b/', '/c.html', 'http://www.example.org/c.html'),
105
        );
106
    }
107
}
108