Skip to content

Commit

Permalink
Add test for URL::parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
TRowbotham committed Jun 28, 2024
1 parent 7d45837 commit 5e3162c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/WhatWg/URLStaticsParseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Rowbot\URL\Tests\WhatWg;

use PHPUnit\Framework\Attributes\DataProvider;
use Rowbot\URL\URL;

/**
* @see https://github.com/web-platform-tests/wpt/blob/master/url/url-statics-parse.any.js
*/
class URLStaticsParseTest extends WhatwgTestCase
{
#[DataProvider('parseDataProvider')]
public function testParse(?string $url, ?string $base, bool $expected): void
{
if (!$expected) {
self::assertNull(URL::parse($url, $base));

return;
}

self::assertSame((new URL($url, $base))->href, URL::parse($url, $base)->href);
}

public function testParseShouldReturnUniqueObject(): void
{
self::assertNotSame(URL::parse('https://example.com/'), URL::parse('https://example.com/'));
}

public static function parseDataProvider(): iterable
{
return [
[
"url" => '',
"base" => null,
"expected" => false
],
[
"url" => "aaa:b",
"base" => null,
"expected" => true
],
[
"url" => '',
"base" => "aaa:b",
"expected" => false
],
[
"url" => "aaa:/b",
"base" => null,
"expected" => true
],
[
"url" => '',
"base" => "aaa:/b",
"expected" => true
],
[
"url" => "https://test:test",
"base" => null,
"expected" => false
],
[
"url" => "a",
"base" => "https://b/",
"expected" => true
],
];
}
}

0 comments on commit 5e3162c

Please sign in to comment.