|
13 | 13 | use TypeError; |
14 | 14 |
|
15 | 15 | 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, |
18 | 18 | uriIsRelativePathReference, uriWithoutQueryValue, uriWithQueryValue |
19 | 19 | }; |
20 | 20 |
|
| 21 | +use const chillerlan\HTTP\Utils\URI_DEFAULT_PORTS; |
| 22 | + |
21 | 23 | class MessageHelpersTest extends TestAbstract{ |
22 | 24 |
|
23 | 25 | public function rawurlencodeDataProvider():array{ |
@@ -222,4 +224,41 @@ public function testUriWithoutQueryValueHandlesEncoding():void{ |
222 | 224 | $this::assertSame('', $uri->getQuery()); |
223 | 225 | } |
224 | 226 |
|
| 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 | + |
225 | 264 | } |
0 commit comments