Passed
Pull Request — master (#70)
by Voyula
03:25
created

ParserTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Purl\Test;
6
7
use Pdp\Parser as PslParser;
8
use Pdp\PublicSuffixListManager;
9
use PHPUnit\Framework\TestCase;
10
use Purl\Parser;
11
use function dirname;
12
13
class ParserTest extends TestCase
14
{
15
    /** @var Parser */
16
    private $parser;
17
18
    protected function setUp() : void
19
    {
20
        parent::setUp();
21
        $pslManager   = new PublicSuffixListManager(dirname(__DIR__, 2)) . '/data');
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')' on line 21 at column 82
Loading history...
22
        $pslParser    = new PslParser($pslManager->getList());
23
        $this->parser = new Parser($pslParser);
24
    }
25
26
    protected function tearDown() : void
27
    {
28
        $this->parser = null;
29
        parent::tearDown();
30
    }
31
32
    public function testParseUrl() : void
33
    {
34
        $parts = $this->parser->parseUrl('https://sub.domain.jwage.com:443/about?param=value#fragment?param=value');
35
        $this->assertEquals([
36
            'scheme' => 'https',
37
            'host' => 'sub.domain.jwage.com',
38
            'port' => 443,
39
            'user' => null,
40
            'pass' => null,
41
            'path' => '/about',
42
            'query' => 'param=value',
43
            'fragment' => 'fragment?param=value',
44
            'publicSuffix' => 'com',
45
            'registerableDomain' => 'jwage.com',
46
            'subdomain' => 'sub.domain',
47
            'canonical' => 'com.jwage.domain.sub/about?param=value',
48
            'resource' => '/about?param=value',
49
        ], $parts);
50
    }
51
52
    /**
53
     * @expectedException \InvalidArgumentException
54
     * @expectedExceptionMessage Invalid url http:///example.com
55
     */
56
    public function testParseBadUrlThrowsInvalidArgumentException() : void
57
    {
58
        $this->parser->parseUrl('http:///example.com/one/two?one=two#value');
59
    }
60
}
61