Skip to content

Commit

Permalink
Add support for PHPUnit 10 and PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Apr 12, 2024
1 parent 8358e08 commit fb4ec62
Show file tree
Hide file tree
Showing 33 changed files with 345 additions and 716 deletions.
29 changes: 10 additions & 19 deletions components/Components/AuthorityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
use League\Uri\Http;
use League\Uri\Uri;
use League\Uri\UriString;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as Psr7UriInterface;

use function parse_url;

/**
* @group userinfo
* @coversDefaultClass \League\Uri\Components\Authority
*/
#[CoversClass(Authority::class)]
#[Group('userinfo')]
final class AuthorityTest extends TestCase
{
/**
* @dataProvider validAuthorityDataProvider
*/
#[DataProvider('validAuthorityDataProvider')]
public function testConstructor(
?string $authority,
?string $host,
Expand Down Expand Up @@ -90,9 +89,7 @@ public static function validAuthorityDataProvider(): array
];
}

/**
* @dataProvider invalidAuthorityDataProvider
*/
#[DataProvider('invalidAuthorityDataProvider')]
public function testConstructorFails(string $authority): void
{
$this->expectException(SyntaxError::class);
Expand All @@ -116,9 +113,7 @@ public function testWithHost(): void
self::assertNotEquals($authority, $authority->withHost('[::1]'));
}

/**
* @dataProvider invalidHostDataProvider
*/
#[DataProvider('invalidHostDataProvider')]
public function testWithHostFails(?string $host): void
{
$this->expectException(SyntaxError::class);
Expand Down Expand Up @@ -164,9 +159,7 @@ public function testWithUserInfoFails(): void
Authority::new('foo:[email protected]:443')->withUserInfo("\0foo", 'bar');
}

/**
* @dataProvider stringRepresentationDataProvider
*/
#[DataProvider('stringRepresentationDataProvider')]
public function testAuthorityStringRepresentation(
?string $authority,
string $string,
Expand Down Expand Up @@ -220,9 +213,7 @@ public static function stringRepresentationDataProvider(): array
];
}

/**
* @dataProvider getURIProvider
*/
#[DataProvider('getURIProvider')]
public function testCreateFromUri(UriInterface|Psr7UriInterface $uri, ?string $expected, array $components): void
{
$authority = Authority::fromUri($uri);
Expand Down
47 changes: 15 additions & 32 deletions components/Components/DataPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Http;
use League\Uri\Uri;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as Psr7UriInterface;

use function base64_encode;
use function dirname;
use function file_get_contents;

/**
* @group path
* @group datapath
* @coversDefaultClass \League\Uri\Components\DataPath
*/
#[CoversClass(DataPath::class)]
#[Group('path')]
#[Group('datapath')]
final class DataPathTest extends TestCase
{
private string $rootPath;
Expand Down Expand Up @@ -71,19 +72,15 @@ public function testConstructorFailedMalformePath(): void
DataPath::new('');
}

/**
* @dataProvider invalidDataUriPath
*/
#[DataProvider('invalidDataUriPath')]
public function testCreateFromPathFailed(string $path): void
{
$this->expectException(SyntaxError::class);

DataPath::fromFileContents($path);
}

/**
* @dataProvider invalidDataUriPath
*/
#[DataProvider('invalidDataUriPath')]
public function testConstructorFailed(string $path): void
{
$this->expectException(SyntaxError::class);
Expand All @@ -98,9 +95,7 @@ public static function invalidDataUriPath(): array
];
}

/**
* @dataProvider validPathContent
*/
#[DataProvider('validPathContent')]
public function testDefaultConstructor(string $path, string $expected): void
{
self::assertSame($expected, DataPath::new($path)->toString());
Expand All @@ -124,9 +119,7 @@ public static function validPathContent(): array
];
}

/**
* @dataProvider validFilePath
*/
#[DataProvider('validFilePath')]
public function testCreateFromPath(string $path, string $mimetype, string $mediatype): void
{
$uri = DataPath::fromFileContents($path);
Expand Down Expand Up @@ -162,9 +155,7 @@ public function testWithParametersOnBinaryData(): void
self::assertSame($expected, $newUri->getParameters());
}

/**
* @dataProvider invalidParametersString
*/
#[DataProvider('invalidParametersString')]
public function testWithParametersFailedWithInvalidParameters(string $path, string $parameters): void
{
$this->expectException(SyntaxError::class);
Expand All @@ -186,17 +177,13 @@ public static function invalidParametersString(): array
];
}

/**
* @dataProvider fileProvider
*/
#[DataProvider('fileProvider')]
public function testToBinary(DataPath $uri): void
{
self::assertTrue($uri->toBinary()->isBinaryData());
}

/**
* @dataProvider fileProvider
*/
#[DataProvider('fileProvider')]
public function testToAscii(DataPath $uri): void
{
self::assertFalse($uri->toAscii()->isBinaryData());
Expand All @@ -212,9 +199,7 @@ public static function fileProvider(): array
];
}

/**
* @dataProvider invalidParameters
*/
#[DataProvider('invalidParameters')]
public function testUpdateParametersFailed(string $parameters): void
{
$this->expectException(SyntaxError::class);
Expand Down Expand Up @@ -299,9 +284,7 @@ public function testInvalidMimetype(): void
}


/**
* @dataProvider getURIProvider
*/
#[DataProvider('getURIProvider')]
public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void
{
$path = DataPath::fromUri($uri);
Expand Down
55 changes: 17 additions & 38 deletions components/Components/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Http;
use League\Uri\Uri;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as Psr7UriInterface;

/**
* @group host
* @coversDefaultClass \League\Uri\Components\Domain
*/
#[CoversClass(Domain::class)]
#[Group('host')]
final class DomainTest extends TestCase
{
public function testItCanBeInstantiatedWithAHostInterfaceImplementingObject(): void
Expand Down Expand Up @@ -60,8 +61,8 @@ public function testIterator(): void

/**
* Test valid Domain.
* @dataProvider validDomainProvider
*/
#[DataProvider('validDomainProvider')]
public function testValidDomain(string $host, string $uri, string $iri): void
{
$host = Domain::new($host);
Expand Down Expand Up @@ -111,9 +112,7 @@ public static function validDomainProvider(): array
];
}

/**
* @dataProvider invalidDomainProvider
*/
#[DataProvider('invalidDomainProvider')]
public function testInvalidDomain(?string $invalid): void
{
$this->expectException(SyntaxError::class);
Expand Down Expand Up @@ -150,9 +149,7 @@ public static function invalidDomainProvider(): array
];
}

/**
* @dataProvider isAbsoluteProvider
*/
#[DataProvider('isAbsoluteProvider')]
public function testIsAbsolute(string $raw, bool $expected): void
{
self::assertSame($expected, Domain::new($raw)->isAbsolute());
Expand All @@ -174,9 +171,7 @@ public function testIpProperty(): void
self::assertNull($host->getIp());
}

/**
* @dataProvider hostnamesProvider
*/
#[DataProvider('hostnamesProvider')]
public function testValidUnicodeDomain(string $unicode, string $ascii): void
{
$host = Domain::new($unicode);
Expand Down Expand Up @@ -211,9 +206,7 @@ public static function hostnamesProvider(): array
];
}

/**
* @dataProvider countableProvider
*/
#[DataProvider('countableProvider')]
public function testCountable(string $host, int $nblabels): void
{
self::assertCount($nblabels, Domain::new($host));
Expand All @@ -227,9 +220,7 @@ public static function countableProvider(): array
];
}

/**
* @dataProvider createFromLabelsValid
*/
#[DataProvider('createFromLabelsValid')]
public function testCreateFromLabels(iterable $input, string $expected): void
{
self::assertSame($expected, (string) Domain::fromLabels(...$input));
Expand Down Expand Up @@ -279,9 +270,7 @@ public function testLabels(): void
self::assertSame(['', 'localhost'], [...Domain::new('localhost.')]);
}

/**
* @dataProvider withoutProvider
*/
#[DataProvider('withoutProvider')]
public function testWithout(string $host, int $without, string $res): void
{
self::assertSame($res, (string) Domain::new($host)->withoutLabel($without));
Expand Down Expand Up @@ -309,9 +298,7 @@ public function testWithoutTriggersException(): void
Domain::new('bébé.be')->withoutLabel(-23);
}

/**
* @dataProvider validPrepend
*/
#[DataProvider('validPrepend')]
public function testPrepend(string $raw, string $prepend, string $expected): void
{
self::assertSame($expected, (string) Domain::new($raw)->prepend($prepend));
Expand Down Expand Up @@ -343,9 +330,7 @@ public function testPrependNull(): void
self::assertSame($domain->prepend(null), $domain);
}

/**
* @dataProvider validAppend
*/
#[DataProvider('validAppend')]
public function testAppend(string $raw, string $append, string $expected): void
{
self::assertSame($expected, (string) Domain::new($raw)->append($append));
Expand Down Expand Up @@ -378,9 +363,7 @@ public function testAppendNull(): void
self::assertSame($domain->append(null), $domain);
}

/**
* @dataProvider replaceValid
*/
#[DataProvider('replaceValid')]
public function testReplace(string $raw, string $input, int $offset, string $expected): void
{
self::assertSame($expected, (string) Domain::new($raw)->withLabel($offset, $input));
Expand Down Expand Up @@ -414,9 +397,7 @@ public function testReplaceMustFailed(): void
Domain::new('secure.example.com')->withLabel(23, 'foo');
}

/**
* @dataProvider rootProvider
*/
#[DataProvider('rootProvider')]
public function testWithRoot(string $host, string $expected_with_root, string $expected_without_root): void
{
$host = Domain::new($host);
Expand All @@ -433,9 +414,7 @@ public static function rootProvider(): array
];
}

/**
* @dataProvider getURIProvider
*/
#[DataProvider('getURIProvider')]
public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void
{
$domain = Domain::fromUri($uri);
Expand Down
Loading

0 comments on commit fb4ec62

Please sign in to comment.