ParserTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 22
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testParseUrl() 0 15 1
A testParseBadUrlThrowsInvalidArgumentException() 0 6 1
A tearDown() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Purl\Test;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use Purl\Parser;
10
11
class ParserTest extends TestCase
12
{
13
    /** @var Parser */
14
    private $parser;
15
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
20
        $this->parser = new Parser();
21
    }
22
23
    protected function tearDown() : void
24
    {
25
        $this->parser = null;
26
        parent::tearDown();
27
    }
28
29
    public function testParseUrl() : void
30
    {
31
        $parts = $this->parser->parseUrl('https://sub.domain.jwage.com:443/about?param=value#fragment?param=value');
32
        $this->assertEquals([
33
            'scheme' => 'https',
34
            'host' => 'sub.domain.jwage.com',
35
            'port' => 443,
36
            'user' => null,
37
            'pass' => null,
38
            'path' => '/about',
39
            'query' => 'param=value',
40
            'fragment' => 'fragment?param=value',
41
            'canonical' => 'com.jwage.domain.sub/about?param=value',
42
            'resource' => '/about?param=value',
43
        ], $parts);
44
    }
45
46
    public function testParseBadUrlThrowsInvalidArgumentException() : void
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionMessage('Invalid url http:///example.com');
50
51
        $this->parser->parseUrl('http:///example.com/one/two?one=two#value');
52
    }
53
}
54