1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* League.Uri (https://uri.thephpleague.com) |
5
|
|
|
* |
6
|
|
|
* (c) Ignace Nyamagana Butera <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LeagueTest\Uri; |
13
|
|
|
|
14
|
|
|
use League\Uri\Exceptions\SyntaxError; |
15
|
|
|
use League\Uri\Uri; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @group ftp |
20
|
|
|
* @group uri |
21
|
|
|
* @coversDefaultClass League\Uri\Uri |
22
|
|
|
*/ |
23
|
|
|
class FtpTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @dataProvider validUrlProvider |
27
|
|
|
*/ |
28
|
|
|
public function testCreateFromString(string $uri, string $expected): void |
29
|
|
|
{ |
30
|
|
|
self::assertSame($expected, (string) Uri::createFromString($uri)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function validUrlProvider(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
'with default port' => [ |
37
|
|
|
'FtP://ExAmpLe.CoM:21/foo/bar', |
38
|
|
|
'ftp://example.com/foo/bar', |
39
|
|
|
], |
40
|
|
|
'with user info' => [ |
41
|
|
|
'ftp://login:[email protected]/', |
42
|
|
|
'ftp://login:[email protected]/', |
43
|
|
|
], |
44
|
|
|
'with network path' => [ |
45
|
|
|
'//ExAmpLe.CoM:80', |
46
|
|
|
'//example.com:80', |
47
|
|
|
], |
48
|
|
|
'absolute path' => [ |
49
|
|
|
'/path/to/my/file', |
50
|
|
|
'/path/to/my/file', |
51
|
|
|
], |
52
|
|
|
'relative path' => [ |
53
|
|
|
'.././path/../is/./relative', |
54
|
|
|
'.././path/../is/./relative', |
55
|
|
|
], |
56
|
|
|
'empty string' => [ |
57
|
|
|
'', |
58
|
|
|
'', |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
|
65
|
|
|
* |
66
|
|
|
* @dataProvider invalidUrlProvider |
67
|
|
|
*/ |
68
|
|
|
public function testConstructorThrowInvalidArgumentException(string $uri): void |
69
|
|
|
{ |
70
|
|
|
self::expectException(SyntaxError::class); |
71
|
|
|
Uri::createFromString($uri); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function invalidUrlProvider(): array |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
//['http://example.com'], |
78
|
|
|
['ftp:/example.com'], |
79
|
|
|
['ftp:example.com'], |
80
|
|
|
['ftp://example.com?query#fragment'], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testModificationFailedWithEmptyAuthority(): void |
85
|
|
|
{ |
86
|
|
|
self::expectException(SyntaxError::class); |
87
|
|
|
Uri::createFromString('ftp://example.com/path') |
88
|
|
|
->withScheme(null) |
89
|
|
|
->withHost(null) |
90
|
|
|
->withPath('//toto'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @dataProvider portProvider |
95
|
|
|
* @param ?int $port |
|
|
|
|
96
|
|
|
*/ |
97
|
|
|
public function testPort(string $uri, ?int $port): void |
98
|
|
|
{ |
99
|
|
|
self::assertSame($port, Uri::createFromString($uri)->getPort()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function portProvider(): array |
103
|
|
|
{ |
104
|
|
|
return [ |
105
|
|
|
['ftp://www.example.com:443/', 443], |
106
|
|
|
['ftp://www.example.com:21/', null], |
107
|
|
|
['ftp://www.example.com', null], |
108
|
|
|
['//www.example.com:21/', 21], |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.