Skip to content

Commit 5e3162c

Browse files
committed
Add test for URL::parse()
1 parent 7d45837 commit 5e3162c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/WhatWg/URLStaticsParseTest.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rowbot\URL\Tests\WhatWg;
6+
7+
use PHPUnit\Framework\Attributes\DataProvider;
8+
use Rowbot\URL\URL;
9+
10+
/**
11+
* @see https://github.com/web-platform-tests/wpt/blob/master/url/url-statics-parse.any.js
12+
*/
13+
class URLStaticsParseTest extends WhatwgTestCase
14+
{
15+
#[DataProvider('parseDataProvider')]
16+
public function testParse(?string $url, ?string $base, bool $expected): void
17+
{
18+
if (!$expected) {
19+
self::assertNull(URL::parse($url, $base));
20+
21+
return;
22+
}
23+
24+
self::assertSame((new URL($url, $base))->href, URL::parse($url, $base)->href);
25+
}
26+
27+
public function testParseShouldReturnUniqueObject(): void
28+
{
29+
self::assertNotSame(URL::parse('https://example.com/'), URL::parse('https://example.com/'));
30+
}
31+
32+
public static function parseDataProvider(): iterable
33+
{
34+
return [
35+
[
36+
"url" => '',
37+
"base" => null,
38+
"expected" => false
39+
],
40+
[
41+
"url" => "aaa:b",
42+
"base" => null,
43+
"expected" => true
44+
],
45+
[
46+
"url" => '',
47+
"base" => "aaa:b",
48+
"expected" => false
49+
],
50+
[
51+
"url" => "aaa:/b",
52+
"base" => null,
53+
"expected" => true
54+
],
55+
[
56+
"url" => '',
57+
"base" => "aaa:/b",
58+
"expected" => true
59+
],
60+
[
61+
"url" => "https://test:test",
62+
"base" => null,
63+
"expected" => false
64+
],
65+
[
66+
"url" => "a",
67+
"base" => "https://b/",
68+
"expected" => true
69+
],
70+
];
71+
}
72+
}

0 commit comments

Comments
 (0)