Skip to content

Commit 10422c5

Browse files
committed
ext/uri: increased test coverage
1 parent 08b9d05 commit 10422c5

33 files changed

Lines changed: 831 additions & 12 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal fragment
3+
--EXTENSIONS--
4+
reflection
5+
--FILE--
6+
<?php
7+
8+
$builder = new Uri\Rfc3986\UriBuilder();
9+
new ReflectionProperty($builder, 'fragment')->setValue($builder, '<');
10+
11+
try {
12+
$builder->build();
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECT--
19+
Uri\InvalidUriException: The specified fragment is malformed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal host
3+
--EXTENSIONS--
4+
reflection
5+
--FILE--
6+
<?php
7+
8+
$builder = new Uri\Rfc3986\UriBuilder();
9+
new ReflectionProperty($builder, 'host')->setValue($builder, '[');
10+
11+
try {
12+
$builder->build();
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECT--
19+
Uri\InvalidUriException: The specified host is malformed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal query
3+
--EXTENSIONS--
4+
reflection
5+
--FILE--
6+
<?php
7+
8+
$builder = new Uri\Rfc3986\UriBuilder();
9+
new ReflectionProperty($builder, 'query')->setValue($builder, '<');
10+
11+
try {
12+
$builder->build();
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECT--
19+
Uri\InvalidUriException: The specified query is malformed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal scheme
3+
--EXTENSIONS--
4+
reflection
5+
--FILE--
6+
<?php
7+
8+
$builder = new Uri\Rfc3986\UriBuilder();
9+
new ReflectionProperty($builder, 'scheme')->setValue($builder, ':');
10+
11+
try {
12+
$builder->build();
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECT--
19+
Uri\InvalidUriException: The specified scheme is malformed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::build() - success - referenced component
3+
--FILE--
4+
<?php
5+
6+
$scope = "\0Uri\\Rfc3986\\UriBuilder\0";
7+
8+
$serialised = serialize(new Uri\Rfc3986\UriBuilder());
9+
10+
$serialised = str_replace(
11+
"s:30:\"{$scope}scheme\";N;",
12+
"s:30:\"{$scope}scheme\";s:5:\"https\";",
13+
$serialised,
14+
);
15+
16+
$serialised = str_replace(
17+
"s:28:\"{$scope}host\";N;",
18+
"s:28:\"{$scope}host\";s:11:\"example.com\";",
19+
$serialised,
20+
);
21+
22+
$serialised = str_replace(
23+
"s:28:\"{$scope}path\";s:0:\"\";",
24+
"s:28:\"{$scope}path\";s:5:\"/path\";",
25+
$serialised,
26+
);
27+
28+
// make fragment share path value
29+
$serialised = str_replace(
30+
"s:32:\"{$scope}fragment\";N;",
31+
"s:32:\"{$scope}fragment\";R:6;",
32+
$serialised,
33+
);
34+
35+
$uri = unserialize($serialised)->build();
36+
37+
var_dump($uri->toRawString());
38+
var_dump($uri);
39+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
40+
41+
?>
42+
--EXPECTF--
43+
string(30) "https://example.com/path#/path"
44+
object(Uri\Rfc3986\Uri)#%d (%d) {
45+
["scheme"]=>
46+
string(5) "https"
47+
["username"]=>
48+
NULL
49+
["password"]=>
50+
NULL
51+
["host"]=>
52+
string(11) "example.com"
53+
["port"]=>
54+
NULL
55+
["path"]=>
56+
string(5) "/path"
57+
["query"]=>
58+
NULL
59+
["fragment"]=>
60+
string(5) "/path"
61+
}
62+
bool(true)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Test Uri\Rfc3986\UriBuilder::setHost() - success - empty string
3+
--FILE--
4+
<?php
5+
6+
$builder = new Uri\Rfc3986\UriBuilder();
7+
$builder->setHost('');
8+
$uri = $builder->build();
9+
10+
var_dump($uri->toRawString());
11+
var_dump($uri);
12+
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
13+
14+
?>
15+
--EXPECTF--
16+
string(2) "//"
17+
object(Uri\Rfc3986\Uri)#%d (%d) {
18+
["scheme"]=>
19+
NULL
20+
["username"]=>
21+
NULL
22+
["password"]=>
23+
NULL
24+
["host"]=>
25+
string(0) ""
26+
["port"]=>
27+
NULL
28+
["path"]=>
29+
string(0) ""
30+
["query"]=>
31+
NULL
32+
["fragment"]=>
33+
NULL
34+
}
35+
bool(true)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri component retrieval - userinfo - without password separator
3+
--FILE--
4+
<?php
5+
6+
$uri = new Uri\Rfc3986\Uri('https://user@example.com');
7+
8+
var_dump($uri->getUserInfo());
9+
var_dump($uri->getUsername());
10+
var_dump($uri->getPassword());
11+
12+
?>
13+
--EXPECT--
14+
string(4) "user"
15+
string(4) "user"
16+
string(0) ""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri::withHost() - error - unsetting with port
3+
--FILE--
4+
<?php
5+
6+
$uri = new Uri\Rfc3986\Uri('https://example.com:8080');
7+
8+
try {
9+
$uri->withHost(null);
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), "\n";
12+
}
13+
14+
?>
15+
--EXPECT--
16+
Uri\InvalidUriException: Cannot remove the host from a URI that has a port
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri parsing - port - excessive number of digits
3+
--FILE--
4+
<?php
5+
6+
try {
7+
new \Uri\Rfc3986\Uri('https://example.com:4242424269424242426942424242694242424269');
8+
} catch (Throwable $e) {
9+
echo $e::class, ': ', $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
Uri\InvalidUriException: The port is out of range

‎ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ Test Uri\Rfc3986\Uri parsing - port - integer overflow
33
--FILE--
44
<?php
55

6-
if (PHP_INT_SIZE == 8) {
7-
$uri = new \Uri\Rfc3986\Uri('https://example.com:9223372036854775807');
8-
echo $uri->getPort(), "\n";
9-
echo "2147483647", "\n";
10-
} else {
11-
$uri = new \Uri\Rfc3986\Uri('https://example.com:2147483647');
12-
echo "9223372036854775807", "\n";
13-
echo $uri->getPort(), "\n";
14-
}
15-
166
try {
177
if (PHP_INT_SIZE == 8) {
188
new \Uri\Rfc3986\Uri('https://example.com:9223372036854775808');
@@ -25,6 +15,4 @@ try {
2515

2616
?>
2717
--EXPECT--
28-
9223372036854775807
29-
2147483647
3018
Uri\InvalidUriException: The port is out of range

0 commit comments

Comments
 (0)