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\Http; |
15
|
|
|
use League\Uri\Uri; |
16
|
|
|
use League\Uri\UriResolver; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use TypeError; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @group modifer |
22
|
|
|
* @coversDefaultClass \League\Uri\UriResolver |
23
|
|
|
*/ |
24
|
|
|
class ResolverTest extends TestCase |
25
|
|
|
{ |
26
|
|
View Code Duplication |
public function testResolveLetThrowResolvedInvalidUri(): void |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$http = Uri::createFromString('http://example.com/path/to/file'); |
29
|
|
|
$ftp = Http::createFromString('ftp://a/b/c/d;p'); |
30
|
|
|
$res = UriResolver::resolve($ftp, $http); |
31
|
|
|
self::assertEquals($res, $ftp); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testResolveThrowExceptionOnConstructor(): void |
35
|
|
|
{ |
36
|
|
|
self::expectException(TypeError::class); |
37
|
|
|
UriResolver::resolve('ftp//a/b/c/d;p', 'toto'); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider resolveProvider |
42
|
|
|
*/ |
43
|
|
|
public function testCreateResolve(string $base_uri, string $uri, string $expected): void |
44
|
|
|
{ |
45
|
|
|
self::assertSame($expected, (string) UriResolver::resolve( |
46
|
|
|
Uri::createFromString($uri), |
47
|
|
|
Http::createFromString($base_uri) |
48
|
|
|
)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function resolveProvider(): array |
52
|
|
|
{ |
53
|
|
|
$base_uri = 'http://a/b/c/d;p?q'; |
54
|
|
|
|
55
|
|
|
return [ |
56
|
|
|
'base uri' => [$base_uri, '', $base_uri], |
57
|
|
|
'scheme' => [$base_uri, 'http://d/e/f', 'http://d/e/f'], |
58
|
|
|
'path 1' => [$base_uri, 'g', 'http://a/b/c/g'], |
59
|
|
|
'path 2' => [$base_uri, './g', 'http://a/b/c/g'], |
60
|
|
|
'path 3' => [$base_uri, 'g/', 'http://a/b/c/g/'], |
61
|
|
|
'path 4' => [$base_uri, '/g', 'http://a/g'], |
62
|
|
|
'authority' => [$base_uri, '//g', 'http://g'], |
63
|
|
|
'query' => [$base_uri, '?y', 'http://a/b/c/d;p?y'], |
64
|
|
|
'path + query' => [$base_uri, 'g?y', 'http://a/b/c/g?y'], |
65
|
|
|
'fragment' => [$base_uri, '#s', 'http://a/b/c/d;p?q#s'], |
66
|
|
|
'path + fragment' => [$base_uri, 'g#s', 'http://a/b/c/g#s'], |
67
|
|
|
'path + query + fragment' => [$base_uri, 'g?y#s', 'http://a/b/c/g?y#s'], |
68
|
|
|
'single dot 1' => [$base_uri, '.', 'http://a/b/c/'], |
69
|
|
|
'single dot 2' => [$base_uri, './', 'http://a/b/c/'], |
70
|
|
|
'single dot 3' => [$base_uri, './g/.', 'http://a/b/c/g/'], |
71
|
|
|
'single dot 4' => [$base_uri, 'g/./h', 'http://a/b/c/g/h'], |
72
|
|
|
'double dot 1' => [$base_uri, '..', 'http://a/b/'], |
73
|
|
|
'double dot 2' => [$base_uri, '../', 'http://a/b/'], |
74
|
|
|
'double dot 3' => [$base_uri, '../g', 'http://a/b/g'], |
75
|
|
|
'double dot 4' => [$base_uri, '../..', 'http://a/'], |
76
|
|
|
'double dot 5' => [$base_uri, '../../', 'http://a/'], |
77
|
|
|
'double dot 6' => [$base_uri, '../../g', 'http://a/g'], |
78
|
|
|
'double dot 7' => [$base_uri, '../../../g', 'http://a/g'], |
79
|
|
|
'double dot 8' => [$base_uri, '../../../../g', 'http://a/g'], |
80
|
|
|
'double dot 9' => [$base_uri, 'g/../h' , 'http://a/b/c/h'], |
81
|
|
|
'mulitple slashes' => [$base_uri, 'foo////g', 'http://a/b/c/foo////g'], |
82
|
|
|
'complex path 1' => [$base_uri, ';x', 'http://a/b/c/;x'], |
83
|
|
|
'complex path 2' => [$base_uri, 'g;x', 'http://a/b/c/g;x'], |
84
|
|
|
'complex path 3' => [$base_uri, 'g;x?y#s', 'http://a/b/c/g;x?y#s'], |
85
|
|
|
'complex path 4' => [$base_uri, 'g;x=1/./y', 'http://a/b/c/g;x=1/y'], |
86
|
|
|
'complex path 5' => [$base_uri, 'g;x=1/../y', 'http://a/b/c/y'], |
87
|
|
|
'dot segments presence 1' => [$base_uri, '/./g', 'http://a/g'], |
88
|
|
|
'dot segments presence 2' => [$base_uri, '/../g', 'http://a/g'], |
89
|
|
|
'dot segments presence 3' => [$base_uri, 'g.', 'http://a/b/c/g.'], |
90
|
|
|
'dot segments presence 4' => [$base_uri, '.g', 'http://a/b/c/.g'], |
91
|
|
|
'dot segments presence 5' => [$base_uri, 'g..', 'http://a/b/c/g..'], |
92
|
|
|
'dot segments presence 6' => [$base_uri, '..g', 'http://a/b/c/..g'], |
93
|
|
|
'origin uri without path' => ['http://h:b@a', 'b/../y', 'http://h:b@a/y'], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.