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