1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Uri;
use League\Uri\Exceptions\SyntaxError;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
#[CoversClass(\League\Uri\Uri::class)]
#[Group('file')]
#[Group('uri')]
final class FileTest extends TestCase
{
public function testDefaultConstructor(): void
{
self::assertSame('', (string) Uri::new());
}
#[DataProvider('validUrlProvider')]
public function testCreateFromString(string $uri, string $expected): void
{
self::assertSame($expected, (string) Uri::new($uri));
}
public static function validUrlProvider(): array
{
return [
'relative path' => [
'.././path/../is/./relative',
'.././path/../is/./relative',
],
'absolute path' => [
'/path/is/absolute',
'/path/is/absolute',
],
'empty path' => [
'',
'',
],
'with host' => [
'//example.com/path',
'//example.com/path',
],
'with normalized host' => [
'//ExAmpLe.CoM/path',
'//example.com/path',
],
'with empty host' => [
'///path',
'///path',
],
'with scheme' => [
'file://localhost/path',
'file://localhost/path',
],
'with normalized scheme' => [
'FiLe://localhost/path',
'file://localhost/path',
],
'with empty host and scheme' => [
'FiLe:///path',
'file:///path',
],
'with windows path' => [
'file:///C|/demo',
'file:///C:/demo',
],
];
}
#[DataProvider('invalidUrlProvider')]
public function testConstructorThrowsException(string $uri): void
{
self::expectException(SyntaxError::class);
Uri::new($uri);
}
public static function invalidUrlProvider(): array
{
return [
'no authority 1' => ['file:example.com'],
'no authority 2' => ['file:/example.com'],
'query string' => ['file://example.com?'],
'fragment' => ['file://example.com#'],
'user info' => ['file://user:pass@example.com'],
'port' => ['file://example.com:42'],
];
}
}
|