Skip to content

Commit 648371f

Browse files
committed
ext/uri: expanded uri builder coverage
1 parent da7cd2a commit 648371f

88 files changed

Lines changed: 3633 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder basic - success - absolute URI with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setScheme('http')
10+
->setHost('example.net')
11+
->setPath('/newPath')
12+
->build($base);
13+
14+
var_dump($uri->toRawString());
15+
var_dump($uri);
16+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
17+
var_dump($uri->equals(new Uri\Rfc3986\Uri('http://example.net/newPath', $base), Uri\UriComparisonMode::IncludeFragment));
18+
19+
?>
20+
--EXPECTF--
21+
string(26) "http://example.net/newPath"
22+
object(Uri\Rfc3986\Uri)#%d (%d) {
23+
["scheme"]=>
24+
string(4) "http"
25+
["username"]=>
26+
NULL
27+
["password"]=>
28+
NULL
29+
["host"]=>
30+
string(11) "example.net"
31+
["port"]=>
32+
NULL
33+
["path"]=>
34+
string(8) "/newPath"
35+
["query"]=>
36+
NULL
37+
["fragment"]=>
38+
NULL
39+
}
40+
bool(true)
41+
bool(true)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder basic - success - empty relative reference with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->build($base);
10+
11+
var_dump($uri->toRawString());
12+
var_dump($uri);
13+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
14+
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));
15+
16+
?>
17+
--EXPECTF--
18+
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
19+
object(Uri\Rfc3986\Uri)#%d (%d) {
20+
["scheme"]=>
21+
string(5) "https"
22+
["username"]=>
23+
string(4) "user"
24+
["password"]=>
25+
string(4) "pass"
26+
["host"]=>
27+
string(11) "example.com"
28+
["port"]=>
29+
int(123)
30+
["path"]=>
31+
string(10) "/base/path"
32+
["query"]=>
33+
string(8) "oldQuery"
34+
["fragment"]=>
35+
NULL
36+
}
37+
bool(true)
38+
bool(true)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setFragment() - success - empty string
3+
--FILE--
4+
<?php
5+
6+
$uri = new Uri\Rfc3986\UriBuilder()
7+
->setFragment('')
8+
->build();
9+
10+
var_dump($uri->toRawString());
11+
var_dump($uri);
12+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
13+
var_dump($uri->equals(new Uri\Rfc3986\Uri('#'), Uri\UriComparisonMode::IncludeFragment));
14+
15+
?>
16+
--EXPECTF--
17+
string(1) "#"
18+
object(Uri\Rfc3986\Uri)#%d (%d) {
19+
["scheme"]=>
20+
NULL
21+
["username"]=>
22+
NULL
23+
["password"]=>
24+
NULL
25+
["host"]=>
26+
NULL
27+
["port"]=>
28+
NULL
29+
["path"]=>
30+
string(0) ""
31+
["query"]=>
32+
NULL
33+
["fragment"]=>
34+
string(0) ""
35+
}
36+
bool(true)
37+
bool(true)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setFragment() - success - empty string with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://example.com/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setFragment('')
10+
->build($base);
11+
12+
var_dump($uri->toRawString());
13+
var_dump($uri);
14+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
15+
var_dump($uri->equals(new Uri\Rfc3986\Uri('#', $base), Uri\UriComparisonMode::IncludeFragment));
16+
17+
?>
18+
--EXPECTF--
19+
string(39) "https://example.com/base/path?oldQuery#"
20+
object(Uri\Rfc3986\Uri)#%d (%d) {
21+
["scheme"]=>
22+
string(5) "https"
23+
["username"]=>
24+
NULL
25+
["password"]=>
26+
NULL
27+
["host"]=>
28+
string(11) "example.com"
29+
["port"]=>
30+
NULL
31+
["path"]=>
32+
string(10) "/base/path"
33+
["query"]=>
34+
string(8) "oldQuery"
35+
["fragment"]=>
36+
string(0) ""
37+
}
38+
bool(true)
39+
bool(true)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setFragment() - success - null with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setFragment('newFragment')
10+
->setFragment(null) // confirm unset
11+
->build($base);
12+
13+
var_dump($uri->toRawString());
14+
var_dump($uri);
15+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
16+
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));
17+
18+
?>
19+
--EXPECTF--
20+
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
21+
object(Uri\Rfc3986\Uri)#%d (%d) {
22+
["scheme"]=>
23+
string(5) "https"
24+
["username"]=>
25+
string(4) "user"
26+
["password"]=>
27+
string(4) "pass"
28+
["host"]=>
29+
string(11) "example.com"
30+
["port"]=>
31+
int(123)
32+
["path"]=>
33+
string(10) "/base/path"
34+
["query"]=>
35+
string(8) "oldQuery"
36+
["fragment"]=>
37+
NULL
38+
}
39+
bool(true)
40+
bool(true)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setFragment() - success - with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setFragment('newFragment')
10+
->build($base);
11+
12+
var_dump($uri->toRawString());
13+
var_dump($uri);
14+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
15+
var_dump($uri->equals(new Uri\Rfc3986\Uri('#newFragment', $base), Uri\UriComparisonMode::IncludeFragment));
16+
17+
?>
18+
--EXPECTF--
19+
string(64) "https://user:pass@example.com:123/base/path?oldQuery#newFragment"
20+
object(Uri\Rfc3986\Uri)#%d (%d) {
21+
["scheme"]=>
22+
string(5) "https"
23+
["username"]=>
24+
string(4) "user"
25+
["password"]=>
26+
string(4) "pass"
27+
["host"]=>
28+
string(11) "example.com"
29+
["port"]=>
30+
int(123)
31+
["path"]=>
32+
string(10) "/base/path"
33+
["query"]=>
34+
string(8) "oldQuery"
35+
["fragment"]=>
36+
string(11) "newFragment"
37+
}
38+
bool(true)
39+
bool(true)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setFragment() - success - with network-path reference
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setHost('example.net')
10+
->setPath('/newPath')
11+
->setFragment('newFragment')
12+
->build($base);
13+
14+
var_dump($uri->toRawString());
15+
var_dump($uri);
16+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
17+
var_dump($uri->equals(new Uri\Rfc3986\Uri('//example.net/newPath#newFragment', $base), Uri\UriComparisonMode::IncludeFragment));
18+
19+
?>
20+
--EXPECTF--
21+
string(39) "https://example.net/newPath#newFragment"
22+
object(Uri\Rfc3986\Uri)#%d (%d) {
23+
["scheme"]=>
24+
string(5) "https"
25+
["username"]=>
26+
NULL
27+
["password"]=>
28+
NULL
29+
["host"]=>
30+
string(11) "example.net"
31+
["port"]=>
32+
NULL
33+
["path"]=>
34+
string(8) "/newPath"
35+
["query"]=>
36+
NULL
37+
["fragment"]=>
38+
string(11) "newFragment"
39+
}
40+
bool(true)
41+
bool(true)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setHost() - success - empty host with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setHost('')
10+
->build($base);
11+
12+
var_dump($uri->toRawString());
13+
var_dump($uri);
14+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
15+
var_dump($uri->equals(new Uri\Rfc3986\Uri('//', $base), Uri\UriComparisonMode::IncludeFragment));
16+
17+
?>
18+
--EXPECTF--
19+
string(8) "https://"
20+
object(Uri\Rfc3986\Uri)#%d (%d) {
21+
["scheme"]=>
22+
string(5) "https"
23+
["username"]=>
24+
NULL
25+
["password"]=>
26+
NULL
27+
["host"]=>
28+
string(0) ""
29+
["port"]=>
30+
NULL
31+
["path"]=>
32+
string(0) ""
33+
["query"]=>
34+
NULL
35+
["fragment"]=>
36+
NULL
37+
}
38+
bool(true)
39+
bool(true)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setHost() - success - null with base URI
3+
--FILE--
4+
<?php
5+
6+
$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');
7+
8+
$uri = new Uri\Rfc3986\UriBuilder()
9+
->setHost('example.net')
10+
->setHost(null) // confirm unset
11+
->build($base);
12+
13+
var_dump($uri->toRawString());
14+
var_dump($uri);
15+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
16+
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));
17+
18+
?>
19+
--EXPECTF--
20+
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
21+
object(Uri\Rfc3986\Uri)#%d (%d) {
22+
["scheme"]=>
23+
string(5) "https"
24+
["username"]=>
25+
string(4) "user"
26+
["password"]=>
27+
string(4) "pass"
28+
["host"]=>
29+
string(11) "example.com"
30+
["port"]=>
31+
int(123)
32+
["path"]=>
33+
string(10) "/base/path"
34+
["query"]=>
35+
string(8) "oldQuery"
36+
["fragment"]=>
37+
NULL
38+
}
39+
bool(true)
40+
bool(true)

0 commit comments

Comments
 (0)