Passed
Pull Request — master (#407)
by Kirill
05:29
created

UriParserTest::testPrepareUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Spiral\Tests\Storage\Unit\Parser;
4
5
use Spiral\Storage\Exception\UriException;
6
use Spiral\Storage\Parser\Uri;
7
use Spiral\Tests\Storage\Unit\UnitTestCase;
8
9
class UriParserTest extends UnitTestCase
10
{
11
    /**
12
     * @dataProvider getUriList
13
     *
14
     * @param string $fs
15
     * @param string $path
16
     * @param string $uri
17
     * @throws UriException
18
     */
19
    public function testPrepareUri(string $fs, string $path, string $uri): void
20
    {
21
        $uriStructure = Uri::create($fs, $path);
22
23
        $this->assertEquals($fs, $uriStructure->getFileSystem());
24
        $this->assertEquals($path, $uriStructure->getPath());
25
        $this->assertEquals($uri, (string)$uriStructure);
26
    }
27
28
    /**
29
     * @dataProvider getUriList
30
     *
31
     * @param string $fs
32
     * @param string $path
33
     * @param string $uri
34
     *
35
     * @throws UriException
36
     */
37
    public function testParseUri(string $fs, string $path, string $uri): void
38
    {
39
        $uriStructure = $this->getUriParser()->parse($uri);
0 ignored issues
show
Bug introduced by
$uri of type string is incompatible with the type Spiral\Storage\Parser\UriLikeType expected by parameter $uri of Spiral\Storage\Parser\UriParserInterface::parse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $uriStructure = $this->getUriParser()->parse(/** @scrutinizer ignore-type */ $uri);
Loading history...
40
41
        $this->assertEquals($fs, $uriStructure->getFileSystem());
42
        $this->assertEquals($path, $uriStructure->getPath());
43
        $this->assertEquals($uri, (string)$uriStructure);
44
    }
45
46
    /**
47
     * @dataProvider getBadUriList
48
     *
49
     * @param string $uri
50
     * @param string $expectedMsg
51
     *
52
     * @throws UriException
53
     */
54
    public function testParseUriThrowsException(string $uri, string $expectedMsg): void
55
    {
56
        $this->expectException(UriException::class);
57
        $this->expectExceptionMessage($expectedMsg);
58
59
        $this->getUriParser()->parse($uri);
0 ignored issues
show
Bug introduced by
$uri of type string is incompatible with the type Spiral\Storage\Parser\UriLikeType expected by parameter $uri of Spiral\Storage\Parser\UriParserInterface::parse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        $this->getUriParser()->parse(/** @scrutinizer ignore-type */ $uri);
Loading history...
60
    }
61
62
    /**
63
     * @dataProvider getUriListWithSeparators
64
     *
65
     * @param string $fs
66
     * @param string $path
67
     * @param string $uri
68
     *
69
     * @throws \ReflectionException
70
     */
71
    public function testBuildUriStructure(string $fs, string $path, string $uri): void
72
    {
73
        $uriStructure = Uri::create($fs, $path);
74
75
        $this->assertEquals($fs, $uriStructure->getFileSystem());
76
        $this->assertEquals($path, $uriStructure->getPath());
77
        $this->assertEquals($uri, (string)$uriStructure);
78
    }
79
80
    public function getUriList(): array
81
    {
82
        return [
83
            [
84
                'local',
85
                'file.txt',
86
                'local://file.txt',
87
            ],
88
            [
89
                'aws',
90
                'some/specific/dir/dirFile.txt',
91
                'aws://some/specific/dir/dirFile.txt',
92
            ],
93
        ];
94
    }
95
96
    public function getUriListWithSeparators(): array
97
    {
98
        return [
99
            [
100
                'local',
101
                'file.txt',
102
                'local://file.txt'
103
            ],
104
            [
105
                'local',
106
                'dir/file.txt',
107
                'local://dir/file.txt'
108
            ],
109
        ];
110
    }
111
112
    public function getBadUriList(): array
113
    {
114
        return [
115
            ['://file.txt', 'Filesystem name can not be empty'],
116
            ['aws://', 'Filesystem pathname can not be empty'],
117
        ];
118
    }
119
}
120