Skip to content

Commit 49735f0

Browse files
committed
:octocat: test coverage
1 parent cb263a4 commit 49735f0

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

src/message_helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ function decompress_content(MessageInterface $message):string{
239239
'ldap' => 389,
240240
];
241241

242+
/**
243+
* Checks whether the URI has a port set and if that port is one of the default ports for the given scheme
244+
*/
242245
function uriIsDefaultPort(UriInterface $uri):bool{
243246
$port = $uri->getPort();
244247
$scheme = $uri->getScheme();
@@ -292,7 +295,6 @@ function uriIsAbsolutePathReference(UriInterface $uri):bool{
292295
*
293296
* A relative reference that does not begin with a slash character is termed a relative-path reference.
294297
*
295-
* @return bool
296298
* @link https://tools.ietf.org/html/rfc3986#section-4.2
297299
*/
298300
function uriIsRelativePathReference(UriInterface $uri):bool{

tests/FactoryHelpersTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
namespace chillerlan\HTTPTest\Utils;
1212

1313
use chillerlan\HTTP\Utils\Server;
14+
use InvalidArgumentException;
1415

1516
use function time;
16-
use const UPLOAD_ERR_OK;
17-
use const UPLOAD_ERR_PARTIAL;
17+
use const UPLOAD_ERR_OK, UPLOAD_ERR_PARTIAL;
1818

1919
class FactoryHelpersTest extends TestAbstract{
2020

@@ -236,4 +236,10 @@ public function testNormalizeMultipleFiles():void{
236236
$this::assertSame(UPLOAD_ERR_PARTIAL, $normalized[1]->getError());
237237
}
238238

239+
public function testNormalizeFilesInvalidValueException():void{
240+
$this->expectException(InvalidArgumentException::class);
241+
$this->expectExceptionMessage('Invalid value in files specification');
242+
$this->server->normalizeFiles(['files' => 'foo']);
243+
}
244+
239245
}

tests/MessageHelpersTest.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
use TypeError;
1414

1515
use function chillerlan\HTTP\Utils\{
16-
decompress_content, get_json, get_xml, message_to_string, r_rawurlencode,
17-
uriIsAbsolute, uriIsAbsolutePathReference, uriIsNetworkPathReference,
16+
decompress_content, get_json, get_xml, message_to_string, parseUrl, r_rawurlencode,
17+
uriIsAbsolute, uriIsAbsolutePathReference, uriIsDefaultPort, uriIsNetworkPathReference,
1818
uriIsRelativePathReference, uriWithoutQueryValue, uriWithQueryValue
1919
};
2020

21+
use const chillerlan\HTTP\Utils\URI_DEFAULT_PORTS;
22+
2123
class MessageHelpersTest extends TestAbstract{
2224

2325
public function rawurlencodeDataProvider():array{
@@ -222,4 +224,41 @@ public function testUriWithoutQueryValueHandlesEncoding():void{
222224
$this::assertSame('', $uri->getQuery());
223225
}
224226

227+
public function testUriIsDefaultPort():void{
228+
229+
foreach(URI_DEFAULT_PORTS as $scheme => $port){
230+
$uri = $this->uriFactory->createUri($scheme.'://localhost:'.$port);
231+
232+
$this::assertTrue(uriIsDefaultPort($uri));
233+
$this->assertSame($scheme.'://localhost', (string)$uri);
234+
}
235+
236+
$uri = $this->uriFactory->createUri('https://localhost:42');
237+
$this->assertSame('https://localhost:42', (string)$uri);
238+
239+
}
240+
241+
public function parseUrlProvider():array{
242+
return [
243+
['http://', null],
244+
['https://яндекAс.рф', [
245+
'scheme' => 'https',
246+
'host' => 'яндекAс.рф'
247+
]],
248+
['http://[2a00:f48:1008::212:183:10]:56?foo=bar', [
249+
'scheme' => 'http',
250+
'host' => '[2a00:f48:1008::212:183:10]',
251+
'port' => '56',
252+
'query' => 'foo=bar',
253+
]]
254+
];
255+
}
256+
257+
/**
258+
* @dataProvider parseUrlProvider
259+
*/
260+
public function testParseUrl($url, $expected):void{
261+
$this::assertSame($expected, parseUrl($url));
262+
}
263+
225264
}

0 commit comments

Comments
 (0)