Skip to content

Commit

Permalink
Improve interfaces tools
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 3, 2023
1 parent 09be537 commit 36e02ea
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file
- New method to `UriInterface::toString`
- New method to `UriInterface::toComponents`
- `League\Uri\IPv4\Converter` class
- `League\Uri\Idna\Converter` class
- `League\Uri\Idna\Error` class
- `League\Uri\Idna\Option` class
- `League\Uri\UriString` class
Expand Down
2 changes: 1 addition & 1 deletion Idna/Idna.php → Idna/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* @see https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/uidna_8h.html
*/
final class Idna
final class Converter
{
private const REGEXP_IDNA_PATTERN = '/[^\x20-\x7f]/';
private const MAX_DOMAIN_LENGTH = 253;
Expand Down
16 changes: 8 additions & 8 deletions Idna/IdnaTest.php → Idna/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \League\Uri\Idna\Idna
* @coversDefaultClass \League\Uri\Idna\Converter
*/
final class IdnaTest extends TestCase
final class ConverterTest extends TestCase
{
/**
* @dataProvider invalidDomainProvider
*/
public function testToAsciiThrowsException(string $domain): void
{
self::assertNotEmpty(Idna::toAscii($domain, Option::forIDNA2008Ascii())->errors());
self::assertNotEmpty(Converter::toAscii($domain, Option::forIDNA2008Ascii())->errors());
}

/**
Expand All @@ -44,15 +44,15 @@ public static function invalidDomainProvider(): iterable

public function testToUnicodeThrowsException(): void
{
self::assertNotEmpty(Idna::toUnicode('xn--a-ecp.ru', Option::forIDNA2008Unicode())->errors());
self::assertNotEmpty(Converter::toUnicode('xn--a-ecp.ru', Option::forIDNA2008Unicode())->errors());
}

/**
* @dataProvider toUnicodeProvider
*/
public function testToIDN(string $domain, string $expectedDomain): void
{
self::assertSame($expectedDomain, Idna::toUnicode($domain, Option::forIDNA2008Unicode())->domain());
self::assertSame($expectedDomain, Converter::toUnicode($domain, Option::forIDNA2008Unicode())->domain());
}

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function toUnicodeProvider(): iterable
*/
public function testToAscii(string $domain, string $expectedDomain): void
{
self::assertSame($expectedDomain, Idna::toAscii($domain, Option::forIDNA2008Ascii())->domain());
self::assertSame($expectedDomain, Converter::toAscii($domain, Option::forIDNA2008Ascii())->domain());
}

/**
Expand Down Expand Up @@ -123,11 +123,11 @@ public static function toAsciiProvider(): iterable

public function testExceptionThrownOnConversionToAsciiIfTheDomainIsTooLong(): void
{
self::assertNotEmpty(Idna::toAscii(str_repeat('A', 255), Option::forIDNA2008Ascii())->errors());
self::assertNotEmpty(Converter::toAscii(str_repeat('A', 255), Option::forIDNA2008Ascii())->errors());
}

public function testExceptionThrownOnConversionToAsciiIfTheDomainLabelIsTooLong(): void
{
self::assertNotEmpty(Idna::toAscii('aa'.str_repeat('A', 64), Option::forIDNA2008Ascii())->errors());
self::assertNotEmpty(Converter::toAscii('aa'.str_repeat('A', 64), Option::forIDNA2008Ascii())->errors());
}
}
2 changes: 1 addition & 1 deletion Idna/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testItCanBeInstantiatedFromArray(): void

public function testInvalidSyntaxAfterIDNConversion(): void
{
$result = Idna::toAscii('%00.com', Option::forIDNA2008Ascii());
$result = Converter::toAscii('%00.com', Option::forIDNA2008Ascii());

self::assertTrue($result->hasErrors());
self::assertCount(1, $result->errors());
Expand Down
4 changes: 2 additions & 2 deletions UriString.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use League\Uri\Exceptions\SyntaxError;
use League\Uri\Idna\ConversionFailed;
use League\Uri\Idna\Idna;
use League\Uri\Idna\Converter;
use League\Uri\Idna\MissingSupport;
use Stringable;
use function array_merge;
Expand Down Expand Up @@ -405,7 +405,7 @@ private static function filterRegisteredName(string $host): string
throw new SyntaxError(sprintf('Host `%s` is invalid : the host is not a valid registered name', $host));
}

$result = Idna::toAscii($host);
$result = Converter::toAscii($host);
if ($result->hasErrors()) {
throw ConversionFailed::dueToError($host, $result);
}
Expand Down

0 comments on commit 36e02ea

Please sign in to comment.