diff --git a/components/Components/AuthorityTest.php b/components/Components/AuthorityTest.php index 8a17d62b..c59a8d0f 100644 --- a/components/Components/AuthorityTest.php +++ b/components/Components/AuthorityTest.php @@ -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, @@ -90,9 +89,7 @@ public static function validAuthorityDataProvider(): array ]; } - /** - * @dataProvider invalidAuthorityDataProvider - */ + #[DataProvider('invalidAuthorityDataProvider')] public function testConstructorFails(string $authority): void { $this->expectException(SyntaxError::class); @@ -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); @@ -164,9 +159,7 @@ public function testWithUserInfoFails(): void Authority::new('foo:bar@example.com:443')->withUserInfo("\0foo", 'bar'); } - /** - * @dataProvider stringRepresentationDataProvider - */ + #[DataProvider('stringRepresentationDataProvider')] public function testAuthorityStringRepresentation( ?string $authority, string $string, @@ -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); diff --git a/components/Components/DataPathTest.php b/components/Components/DataPathTest.php index ed7de3f8..584dede8 100644 --- a/components/Components/DataPathTest.php +++ b/components/Components/DataPathTest.php @@ -15,6 +15,9 @@ 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; @@ -22,11 +25,9 @@ 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; @@ -71,9 +72,7 @@ public function testConstructorFailedMalformePath(): void DataPath::new('€'); } - /** - * @dataProvider invalidDataUriPath - */ + #[DataProvider('invalidDataUriPath')] public function testCreateFromPathFailed(string $path): void { $this->expectException(SyntaxError::class); @@ -81,9 +80,7 @@ public function testCreateFromPathFailed(string $path): void DataPath::fromFileContents($path); } - /** - * @dataProvider invalidDataUriPath - */ + #[DataProvider('invalidDataUriPath')] public function testConstructorFailed(string $path): void { $this->expectException(SyntaxError::class); @@ -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()); @@ -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); @@ -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); @@ -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()); @@ -212,9 +199,7 @@ public static function fileProvider(): array ]; } - /** - * @dataProvider invalidParameters - */ + #[DataProvider('invalidParameters')] public function testUpdateParametersFailed(string $parameters): void { $this->expectException(SyntaxError::class); @@ -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); diff --git a/components/Components/DomainTest.php b/components/Components/DomainTest.php index 0396d4b1..5dab01aa 100644 --- a/components/Components/DomainTest.php +++ b/components/Components/DomainTest.php @@ -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 @@ -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); @@ -111,9 +112,7 @@ public static function validDomainProvider(): array ]; } - /** - * @dataProvider invalidDomainProvider - */ + #[DataProvider('invalidDomainProvider')] public function testInvalidDomain(?string $invalid): void { $this->expectException(SyntaxError::class); @@ -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()); @@ -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); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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); @@ -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); diff --git a/components/Components/FragmentTest.php b/components/Components/FragmentTest.php index ff914402..e3746bf7 100644 --- a/components/Components/FragmentTest.php +++ b/components/Components/FragmentTest.php @@ -16,19 +16,14 @@ use League\Uri\Exceptions\SyntaxError; use League\Uri\Http; use League\Uri\Uri; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Message\UriInterface as Psr7UriInterface; use Stringable; -/** - * @group fragment - * @coversDefaultClass \League\Uri\Components\Fragment - */ final class FragmentTest extends TestCase { - /** - * @dataProvider getUriComponentProvider - */ + #[DataProvider('getUriComponentProvider')] public function testStringRepresentation(?string $str, string $encoded): void { self::assertSame($encoded, Fragment::new($str)->toString()); @@ -56,9 +51,7 @@ public static function getUriComponentProvider(): array ]; } - /** - * @dataProvider geValueProvider - */ + #[DataProvider('getValueProvider')] public function testGetValue(Stringable|string|null $str, ?string $expected): void { if ($str instanceof UriComponentInterface) { @@ -68,7 +61,7 @@ public function testGetValue(Stringable|string|null $str, ?string $expected): vo self::assertSame($expected, Fragment::new($str)->decoded()); } - public static function geValueProvider(): array + public static function getValueProvider(): array { return [ [Fragment::new(), null], @@ -87,9 +80,7 @@ public static function geValueProvider(): array ]; } - /** - * @dataProvider getContentProvider - */ + #[DataProvider('getContentProvider')] public function testGetContent(string $input, string $expected): void { self::assertSame($expected, Fragment::new($input)->value()); @@ -129,9 +120,7 @@ public function testPreserverDelimiter(): void self::assertSame('', $fragment->toString()); } - /** - * @dataProvider getURIProvider - */ + #[DataProvider('getURIProvider')] public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void { $fragment = Fragment::fromUri($uri); diff --git a/components/Components/HierarchicalPathTest.php b/components/Components/HierarchicalPathTest.php index d8f75017..92814e54 100644 --- a/components/Components/HierarchicalPathTest.php +++ b/components/Components/HierarchicalPathTest.php @@ -17,16 +17,17 @@ 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 iterator_to_array; -/** - * @group path - * @group hierarchicalpath - * @coversDefaultClass \League\Uri\Components\HierarchicalPath - */ +#[CoversClass(HierarchicalPath::class)] +#[Group('path')] +#[Group('hierarchicalpath')] final class HierarchicalPathTest extends TestCase { public function testIterator(): void @@ -36,9 +37,7 @@ public function testIterator(): void self::assertEquals(['5.0', 'components', 'path'], iterator_to_array($path)); } - /** - * @dataProvider validPathProvider - */ + #[DataProvider('validPathProvider')] public function testValidPath(string $raw, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($raw)); @@ -69,9 +68,7 @@ public static function validPathProvider(): array ]; } - /** - * @dataProvider isAbsoluteProvider - */ + #[DataProvider('isAbsoluteProvider')] public function testIsAbsolute(string $raw, bool $expected): void { $path = HierarchicalPath::new($raw); @@ -89,9 +86,7 @@ public static function isAbsoluteProvider(): array ]; } - /** - * @dataProvider getProvider - */ + #[DataProvider('getProvider')] public function testget(string $raw, int $key, ?string $expected): void { self::assertSame($expected, HierarchicalPath::new($raw)->get($key)); @@ -110,9 +105,8 @@ public static function getProvider(): array /** * Test Removing Dot Segment. - * - * @dataProvider normalizeProvider */ + #[DataProvider('normalizeProvider')] public function testWithoutDotSegments(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withoutDotSegments()); @@ -132,9 +126,7 @@ public static function normalizeProvider(): array ]; } - /** - * @dataProvider withLeadingSlashProvider - */ + #[DataProvider('withLeadingSlashProvider')] public function testWithLeadingSlash(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withLeadingSlash()); @@ -152,9 +144,7 @@ public static function withLeadingSlashProvider(): array ]; } - /** - * @dataProvider withoutLeadingSlashProvider - */ + #[DataProvider('withoutLeadingSlashProvider')] public function testWithoutLeadingSlash(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withoutLeadingSlash()); @@ -171,9 +161,7 @@ public static function withoutLeadingSlashProvider(): array ]; } - /** - * @dataProvider createFromRelativeSegmentsValid - */ + #[DataProvider('createFromRelativeSegmentsValid')] public function testCreateRelativeFromSegments(iterable $input, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::fromRelative(...$input)); @@ -190,9 +178,7 @@ public static function createFromRelativeSegmentsValid(): array ]; } - /** - * @dataProvider createFromAbsoluteSegmentsValid - */ + #[DataProvider('createFromAbsoluteSegmentsValid')] public function testCreateAbsoluteFromSegments(iterable $input, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::fromAbsolute(...$input)); @@ -213,9 +199,7 @@ public static function createFromAbsoluteSegmentsValid(): array ]; } - /** - * @dataProvider prependData - */ + #[DataProvider('prependData')] public function testPrepend(string $source, string $prepend, string $res): void { self::assertSame($res, (string) HierarchicalPath::new($source)->prepend($prepend)); @@ -233,9 +217,7 @@ public static function prependData(): array ]; } - /** - * @dataProvider appendData - */ + #[DataProvider('appendData')] public function testAppend(string $source, string $append, string $res): void { self::assertSame($res, (string) HierarchicalPath::new($source)->append($append)); @@ -263,9 +245,7 @@ public function testWithSegmentUseAppend(): void } - /** - * @dataProvider withoutEmptySegmentsProvider - */ + #[DataProvider('withoutEmptySegmentsProvider')] public function testWithoutEmptySegments(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withoutEmptySegments()); @@ -281,9 +261,7 @@ public static function withoutEmptySegmentsProvider(): array ]; } - /** - * @dataProvider replaceValid - */ + #[DataProvider('replaceValid')] public function testReplace(string $raw, string $input, int $offset, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($raw)->withSegment($offset, $input)); @@ -315,10 +293,10 @@ public function testWithSegmentThrowsException(): void /** * Test AbstractSegment::without. * - * @dataProvider withoutProvider * * @param int[] $without */ + #[DataProvider('withoutProvider')] public function testWithout(string $origin, array $without, string $result): void { self::assertSame($result, (string) HierarchicalPath::new($origin)->withoutSegment(...$without)); @@ -369,9 +347,7 @@ public function testSegments(): void self::assertSame([''], iterator_to_array(HierarchicalPath::new('/'))); } - /** - * @dataProvider arrayProvider - */ + #[DataProvider('arrayProvider')] public function testCountable(string $input, array $gets, int $nbSegment): void { $path = HierarchicalPath::new($input); @@ -388,9 +364,7 @@ public static function arrayProvider(): array ]; } - /** - * @dataProvider provideBasenamePath - */ + #[DataProvider('provideBasenamePath')] public function testGetBasemane(string $path, string $expected): void { self::assertSame($expected, HierarchicalPath::new($path)->getBasename()); @@ -415,9 +389,7 @@ public static function provideBasenamePath(): iterable } - /** - * @dataProvider dirnameProvider - */ + #[DataProvider('dirnameProvider')] public function testGetDirmane(string $path, string $dirname): void { self::assertSame($dirname, HierarchicalPath::new($path)->getDirname()); @@ -437,9 +409,7 @@ public static function dirnameProvider(): array ]; } - /** - * @dataProvider extensionProvider - */ + #[DataProvider('extensionProvider')] public function testGetExtension(string $raw, string $parsed): void { self::assertSame($parsed, HierarchicalPath::new($raw)->getExtension()); @@ -455,9 +425,7 @@ public static function extensionProvider(): array ]; } - /** - * @dataProvider withExtensionProvider - */ + #[DataProvider('withExtensionProvider')] public function testWithExtension(string $raw, string $raw_ext, string $new_path, string $parsed_ext): void { $newPath = HierarchicalPath::new($raw)->withExtension($raw_ext); @@ -485,9 +453,7 @@ public static function withExtensionProvider(): array ]; } - /** - * @dataProvider invalidExtension - */ + #[DataProvider('invalidExtension')] public function testWithExtensionWithInvalidExtension(string $extension): void { $this->expectException(SyntaxError::class); @@ -504,9 +470,7 @@ public static function invalidExtension(): array ]; } - /** - * @dataProvider withExtensionProvider2 - */ + #[DataProvider('withExtensionProvider2')] public function testWithExtensionPreserveTypeCode(string $uri, string $extension, string $expected): void { self::assertSame( @@ -525,9 +489,7 @@ public static function withExtensionProvider2(): array ]; } - /** - * @dataProvider getExtensionProvider - */ + #[DataProvider('getExtensionProvider')] public function testGetExtensionPreserveTypeCode(string $uri, string $extension): void { self::assertSame($extension, HierarchicalPath::new($uri)->getExtension()); @@ -556,9 +518,7 @@ public static function geValueProvider(): array ]; } - /** - * @dataProvider getDirnameProvider - */ + #[DataProvider('getDirnameProvider')] public function testWithDirname(string $path, string $dirname, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withDirname($dirname)); @@ -600,9 +560,7 @@ public static function getDirnameProvider(): array ]; } - /** - * @dataProvider getBasenameProvider - */ + #[DataProvider('getBasenameProvider')] public function testWithBasename(string $path, string $basename, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withBasename($basename)); @@ -639,9 +597,7 @@ public static function getBasenameProvider(): array ]; } - /** - * @dataProvider basenameInvalidProvider - */ + #[DataProvider('basenameInvalidProvider')] public function testWithBasenameThrowException(string $path): void { $this->expectException(SyntaxError::class); @@ -657,9 +613,7 @@ public static function basenameInvalidProvider(): array } - /** - * @dataProvider getURIProvider - */ + #[DataProvider('getURIProvider')] public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void { $path = HierarchicalPath::fromUri($uri); @@ -706,9 +660,7 @@ public function testCreateFromUriWithPSR7Implementation(): void self::assertSame('/path', HierarchicalPath::fromUri($uri)->toString()); } - /** - * @dataProvider trailingSlashProvider - */ + #[DataProvider('trailingSlashProvider')] public function testHasTrailingSlash(string $path, bool $expected): void { self::assertSame($expected, HierarchicalPath::new($path)->hasTrailingSlash()); @@ -726,9 +678,7 @@ public static function trailingSlashProvider(): array ]; } - /** - * @dataProvider withTrailingSlashProvider - */ + #[DataProvider('withTrailingSlashProvider')] public function testWithTrailingSlash(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withTrailingSlash()); @@ -746,9 +696,7 @@ public static function withTrailingSlashProvider(): array ]; } - /** - * @dataProvider withoutTrailingSlashProvider - */ + #[DataProvider('withoutTrailingSlashProvider')] public function testWithoutTrailingSlash(string $path, string $expected): void { self::assertSame($expected, (string) HierarchicalPath::new($path)->withoutTrailingSlash()); @@ -766,9 +714,7 @@ public static function withoutTrailingSlashProvider(): array ]; } - /** - * @dataProvider validPathEncoding - */ + #[DataProvider('validPathEncoding')] public function testGetUriComponent(string $decoded, string $encoded): void { $path = HierarchicalPath::new($decoded); diff --git a/components/Components/HostTest.php b/components/Components/HostTest.php index b7df5c73..6fb6d04c 100644 --- a/components/Components/HostTest.php +++ b/components/Components/HostTest.php @@ -26,17 +26,14 @@ use function array_fill; use function implode; -/** - * @group host - * @coversDefaultClass \League\Uri\Components\Host - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Host::class)] +#[\PHPUnit\Framework\Attributes\Group('host')] final class HostTest extends TestCase { /** * Test valid Host. - * - * @dataProvider validHostProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('validHostProvider')] public function testValidHost(Stringable|int|string|null $host, ?string $uri, ?string $iri): void { $host = match (true) { @@ -126,9 +123,7 @@ public static function validHostProvider(): array ]; } - /** - * @dataProvider invalidHostProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidHostProvider')] public function testInvalidHost(string $invalid): void { $this->expectException(SyntaxError::class); @@ -174,9 +169,8 @@ public function testInvalidi18nConversionReturnsErrors(): void /** * Test Punycode support. - * - * @dataProvider hostnamesProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('hostnamesProvider')] public function testValidUnicodeHost(string $unicode, string $ascii): void { $host = Host::new($unicode); @@ -213,9 +207,7 @@ public static function hostnamesProvider(): array ]; } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void { $host = Host::fromUri($uri); @@ -253,9 +245,7 @@ public static function getURIProvider(): iterable ]; } - /** - * @dataProvider getIsDomainProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getIsDomainProvider')] public function test_host_is_domain(?string $host, bool $expectedIsDomain): void { $host = null !== $host ? Host::new($host) : Host::new(); diff --git a/components/Components/IpAddressTest.php b/components/Components/IpAddressTest.php index 98fe01a2..a77a0707 100644 --- a/components/Components/IpAddressTest.php +++ b/components/Components/IpAddressTest.php @@ -15,15 +15,11 @@ use PHPUnit\Framework\TestCase; use Stringable; -/** - * @group host - * @coversDefaultClass \League\Uri\Components\Host - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Host::class)] +#[\PHPUnit\Framework\Attributes\Group('host')] final class IpAddressTest extends TestCase { - /** - * @dataProvider validIpAddressProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validIpAddressProvider')] public function testValidIpAddress( Stringable|int|string|null $host, bool $isDomain, @@ -125,9 +121,7 @@ public static function validIpAddressProvider(): array ]; } - /** - * @dataProvider createFromIpValid - */ + #[\PHPUnit\Framework\Attributes\DataProvider('createFromIpValid')] public function testCreateFromIp(string $input, string $version, string $expected): void { self::assertSame($expected, (string) Host::fromIp($input, $version)); @@ -146,9 +140,7 @@ public static function createFromIpValid(): array ]; } - /** - * @dataProvider createFromIpFailed - */ + #[\PHPUnit\Framework\Attributes\DataProvider('createFromIpFailed')] public function testCreateFromIpFailed(string $input): void { $this->expectException(SyntaxError::class); @@ -165,9 +157,7 @@ public static function createFromIpFailed(): array ]; } - /** - * @dataProvider withoutZoneIdentifierProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withoutZoneIdentifierProvider')] public function testWithoutZoneIdentifier(string $host, string $expected): void { self::assertSame($expected, (string) Host::new($host)->withoutZoneIdentifier()); @@ -183,9 +173,7 @@ public static function withoutZoneIdentifierProvider(): array ]; } - /** - * @dataProvider hasZoneIdentifierProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('hasZoneIdentifierProvider')] public function testHasZoneIdentifier(string $host, bool $expected): void { self::assertSame($expected, Host::new($host)->hasZoneIdentifier()); diff --git a/components/Components/PathTest.php b/components/Components/PathTest.php index 1dc3872a..df66b963 100644 --- a/components/Components/PathTest.php +++ b/components/Components/PathTest.php @@ -18,16 +18,12 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\UriInterface as Psr7UriInterface; -/** - * @group path - * @group defaultpath - * @coversDefaultClass \League\Uri\Components\Path - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Path::class)] +#[\PHPUnit\Framework\Attributes\Group('path')] +#[\PHPUnit\Framework\Attributes\Group('defaultpath')] final class PathTest extends TestCase { - /** - * @dataProvider validPathEncoding - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validPathEncoding')] public function testGetUriComponent(string $decoded, string $encoded): void { $path = Path::new($decoded); @@ -107,9 +103,8 @@ public function testConstructorThrowsExceptionWithInvalidData(): void /** * Test Removing Dot Segment. - * - * @dataProvider normalizeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('normalizeProvider')] public function testWithoutDotSegments(string $path, string $expected): void { self::assertSame($expected, Path::new($path)->withoutDotSegments()->toString()); @@ -129,9 +124,7 @@ public static function normalizeProvider(): array ]; } - /** - * @dataProvider trailingSlashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('trailingSlashProvider')] public function testHasTrailingSlash(string $path, bool $expected): void { self::assertSame($expected, Path::new($path)->hasTrailingSlash()); @@ -149,9 +142,7 @@ public static function trailingSlashProvider(): array ]; } - /** - * @dataProvider withTrailingSlashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withTrailingSlashProvider')] public function testWithTrailingSlash(string $path, string $expected): void { self::assertSame($expected, (string) Path::new($path)->withTrailingSlash()); @@ -169,9 +160,7 @@ public static function withTrailingSlashProvider(): array ]; } - /** - * @dataProvider withoutTrailingSlashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withoutTrailingSlashProvider')] public function testWithoutTrailingSlash(string $path, string $expected): void { self::assertSame($expected, (string) Path::new($path)->withoutTrailingSlash()); @@ -189,9 +178,7 @@ public static function withoutTrailingSlashProvider(): array ]; } - /** - * @dataProvider withLeadingSlashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withLeadingSlashProvider')] public function testWithLeadingSlash(string $path, string $expected): void { self::assertSame($expected, (string) Path::new($path)->withLeadingSlash()); @@ -209,9 +196,7 @@ public static function withLeadingSlashProvider(): array ]; } - /** - * @dataProvider withoutLeadingSlashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withoutLeadingSlashProvider')] public function testWithoutLeadingSlash(string $path, string $expected): void { self::assertSame($expected, (string) Path::new($path)->withoutLeadingSlash()); @@ -228,9 +213,7 @@ public static function withoutLeadingSlashProvider(): array ]; } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void { $path = Path::fromUri($uri); diff --git a/components/Components/PortTest.php b/components/Components/PortTest.php index 456e8b62..e66a826e 100644 --- a/components/Components/PortTest.php +++ b/components/Components/PortTest.php @@ -19,10 +19,8 @@ use Psr\Http\Message\UriInterface as Psr7UriInterface; use Stringable; -/** - * @group port - * @coversDefaultClass \League\Uri\Components\Port - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Port::class)] +#[\PHPUnit\Framework\Attributes\Group('port')] final class PortTest extends TestCase { public function testPortSetter(): void @@ -30,9 +28,7 @@ public function testPortSetter(): void self::assertSame('443', Port::new(443)->toString()); } - /** - * @dataProvider getToIntProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getToIntProvider')] public function testToInt( Stringable|int|string|null $input, ?int $expected, @@ -69,9 +65,7 @@ public function testFailedPortException(): void Port::new(-1); } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(UriInterface|Psr7UriInterface $uri, ?string $expected): void { $port = Port::fromUri($uri); diff --git a/components/Components/QueryTest.php b/components/Components/QueryTest.php index aa52e89e..ec38d89f 100644 --- a/components/Components/QueryTest.php +++ b/components/Components/QueryTest.php @@ -22,10 +22,8 @@ use function json_encode; -/** - * @group query - * @coversDefaultClass \League\Uri\Components\Query - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Query::class)] +#[\PHPUnit\Framework\Attributes\Group('query')] final class QueryTest extends TestCase { protected Query $query; @@ -121,9 +119,7 @@ public function testNormalization(): void self::assertSame($this->query, $this->query->withoutEmptyPairs()); } - /** - * @dataProvider validAppendValue - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validAppendValue')] public function testAppend(?string $query, Stringable|string|null $appendData, ?string $expected): void { self::assertSame($expected, Query::new($query)->append($appendData)->value()); @@ -197,9 +193,7 @@ public function testParams(): void self::assertNull($query->parameter('foo[]')); } - /** - * @dataProvider withoutKeyPairProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withoutKeyPairProvider')] public function testwithoutKeyPair(string $origin, array $without, string $result): void { self::assertSame($result, (string) Query::new($origin)->withoutPairByKey(...$without)); @@ -241,10 +235,9 @@ public function testwithoutKeyPairGetterMethod(): void } /** - * @dataProvider providePairsValuesToBeRemoved - * * @param list $values */ + #[\PHPUnit\Framework\Attributes\DataProvider('providePairsValuesToBeRemoved')] public function testWithoutPairByValue(string $query, array $values, string $expected): void { self::assertSame($expected, Query::fromRFC3986($query)->withoutPairByValue(...$values)->value()); @@ -296,10 +289,9 @@ public static function providePairsValuesToBeRemoved(): iterable } /** - * @dataProvider providePairsToBeRemoved - * * @param list{0:string, 1:Stringable|string|int|bool|null} $pair */ + #[\PHPUnit\Framework\Attributes\DataProvider('providePairsToBeRemoved')] public function testWithoutPairByKeyValue(string $query, array $pair, string $expected): void { self::assertSame($expected, Query::fromRFC3986($query)->withoutPairByKeyValue(...$pair)->value()); @@ -344,9 +336,7 @@ public static function providePairsToBeRemoved(): iterable ]; } - /** - * @dataProvider withoutParamProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withoutParamProvider')] public function testwithoutParam(array $origin, array $without, string $expected): void { self::assertSame($expected, Query::fromVariable($origin)->withoutParameters(...$without)->toString()); @@ -544,9 +534,7 @@ public static function testSort(): void self::assertNotEquals($sortedQuery, $query); } - /** - * @dataProvider sameQueryAfterSortingProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('sameQueryAfterSortingProvider')] public function testSortReturnSameInstance(?string $query): void { $query = Query::new($query); @@ -563,9 +551,7 @@ public static function sameQueryAfterSortingProvider(): array ]; } - /** - * @dataProvider provideWithPairData - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideWithPairData')] public function testWithPair(?string $query, string $key, string|null|bool $value, array $expected): void { self::assertSame($expected, Query::new($query)->withPair($key, $value)->getAll($key)); @@ -608,9 +594,7 @@ public function testWithPairBasic(): void self::assertSame('a=b&c=d&e=f', Query::new('a=b&c=d')->withPair('e', 'f')->toString()); } - /** - * @dataProvider mergeBasicProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('mergeBasicProvider')] public function testMergeBasic(string $src, Stringable|string|null $dest, string $expected): void { self::assertSame($expected, Query::new($src)->merge($dest)->toString()); @@ -682,9 +666,7 @@ public function testMergeGetterMethods(): void self::assertSame('a=4&first=4', $query->get('q')); } - /** - * @dataProvider provideWithoutDuplicatesData - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideWithoutDuplicatesData')] public function testWithoutDuplicates(?string $query, ?string $expected): void { self::assertSame($expected, Query::new($query)->withoutDuplicates()->value()); @@ -749,9 +731,7 @@ public function testAppendToWithGetter(): void self::assertSame('1', $newQuery->get('first')); } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(Psr7UriInterface|UriInterface $uri, ?string $expected): void { self::assertSame($expected, Query::fromUri($uri)->value()); diff --git a/components/Components/SchemeTest.php b/components/Components/SchemeTest.php index a0bfe32f..295101a0 100644 --- a/components/Components/SchemeTest.php +++ b/components/Components/SchemeTest.php @@ -19,10 +19,8 @@ use Psr\Http\Message\UriInterface as Psr7UriInterface; use Stringable; -/** - * @group scheme - * @coversDefaultClass \League\Uri\Components\Scheme - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\Scheme::class)] +#[\PHPUnit\Framework\Attributes\Group('scheme')] final class SchemeTest extends TestCase { public function testWithContent(): void @@ -30,9 +28,7 @@ public function testWithContent(): void self::assertEquals(Scheme::new('ftp'), Scheme::new('FtP')); } - /** - * @dataProvider validSchemeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validSchemeProvider')] public function testValidScheme( Stringable|string|null $scheme, string $toString, @@ -63,9 +59,7 @@ public function __toString(): string ]; } - /** - * @dataProvider invalidSchemeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidSchemeProvider')] public function testInvalidScheme(string $scheme): void { $this->expectException(SyntaxError::class); @@ -82,9 +76,7 @@ public static function invalidSchemeProvider(): array ]; } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(UriInterface|Psr7UriInterface $uri, ?string $expected): void { self::assertSame($expected, Scheme::fromUri($uri)->value()); diff --git a/components/Components/URLSearchParamsTest.php b/components/Components/URLSearchParamsTest.php index 9b53dddd..552d834a 100644 --- a/components/Components/URLSearchParamsTest.php +++ b/components/Components/URLSearchParamsTest.php @@ -163,9 +163,7 @@ public function testNewInstanceWithSequenceOfSequencesOfString(): void self::assertSame('d', $params->get('c')); } - /** - * @dataProvider providesInvalidSequenceOfSequencesOfString - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesInvalidSequenceOfSequencesOfString')] public function testNewInstanceWithSequenceOfSequencesOfStringFails(array $sequences): void { $this->expectException(SyntaxError::class); @@ -185,9 +183,7 @@ public static function providesInvalidSequenceOfSequencesOfString(): iterable ]; } - /** - * @dataProvider providesComplexConstructorData - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesComplexConstructorData')] public function testComplexConstructor(string $json): void { /** @var object{input: string, output: array, name: string} $res */ @@ -582,9 +578,7 @@ public function testNoNormalizationForCarriageReturnCharacters(): void self::assertSame($params->toString(), 'a%0Ab=c%0Dd&e%0A%0Df=g%0D%0Ah'); } - /** - * @dataProvider provideSortingPayload - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideSortingPayload')] public function testSorting(string $input, array $output): void { $params = new URLSearchParams($input); @@ -819,9 +813,8 @@ public function testFromParametersRespectURLSpecTypeConversion(): void /** * @see https://github.com/php/php-src/tree/master/ext/standard/tests/http/http_build_query - * - * @dataProvider providesParametersInput */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesParametersInput')] public function testFromParametersWithDifferentInput(object|array $data, string $expected): void { self::assertSame($expected, URLSearchParams::fromVariable($data)->toString()); diff --git a/components/Components/UserInfoTest.php b/components/Components/UserInfoTest.php index ab7e425c..a53862bf 100644 --- a/components/Components/UserInfoTest.php +++ b/components/Components/UserInfoTest.php @@ -20,15 +20,11 @@ use Psr\Http\Message\UriInterface as Psr7UriInterface; use Stringable; -/** - * @group userinfo - * @coversDefaultClass \League\Uri\Components\UserInfo - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\Components\UserInfo::class)] +#[\PHPUnit\Framework\Attributes\Group('userinfo')] final class UserInfoTest extends TestCase { - /** - * @dataProvider userInfoProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('userInfoProvider')] public function testConstructor( Stringable|string|null $user, Stringable|string|null $pass, @@ -153,9 +149,7 @@ public function testWithContentReturnSameInstance(): void ); } - /** - * @dataProvider withUserInfoProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('withUserInfoProvider')] public function testWithUserInfo(?string $user, ?string $pass, ?string $expected): void { self::assertSame($expected, UserInfo::new()->withUser($user)->withPass($pass)->toString()); @@ -187,9 +181,7 @@ public function testConstructorThrowsException(): void new UserInfo("\0"); } - /** - * @dataProvider getURIProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('getURIProvider')] public function testCreateFromUri(UriInterface|Psr7UriInterface $uri, ?string $expected): void { $userInfo = UserInfo::fromUri($uri); @@ -263,10 +255,9 @@ public function testItFailsToCreateANewInstanceWhenTheUsernameIsUndefined(): voi } /** - * @dataProvider providesUriToParse - * * @param array{user: ?string, pass: ?string} $components */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesUriToParse')] public function testNewInstanceFromUriParsing(string $uri, ?string $expected, array $components): void { $userInfo = UserInfo::fromComponents(UriString::parse($uri)); diff --git a/components/ModifierTest.php b/components/ModifierTest.php index deef6aeb..2ef69708 100644 --- a/components/ModifierTest.php +++ b/components/ModifierTest.php @@ -14,15 +14,15 @@ use GuzzleHttp\Psr7\Utils; use League\Uri\Components\DataPath; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use const PHP_QUERY_RFC3986; -/** - * @group host - * @group resolution - * @coversDefaultClass \League\Uri\UriModifier - */ +#[CoversClass(UriModifier::class)] /** @phpstan-ignore-line */ +#[Group('host')] +#[Group('resolution')] final class ModifierTest extends TestCase { private readonly string $uri; @@ -37,10 +37,7 @@ protected function setUp(): void /***************************** * QUERY MODIFIER METHOD TESTS ****************************/ - - /** - * @dataProvider validMergeQueryProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validMergeQueryProvider')] public function testMergeQuery(string $query, string $expected): void { self::assertSame($expected, $this->modifier->mergeQuery($query)->getUri()->getQuery()); @@ -54,9 +51,7 @@ public static function validMergeQueryProvider(): array ]; } - /** - * @dataProvider validMergeQueryPairsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validMergeQueryPairsProvider')] public function testMergeQueryPairs(iterable $pairs, string $expected): void { self::assertSame($expected, $this->modifier->mergeQueryPairs($pairs)->getUri()->getQuery()); @@ -76,9 +71,7 @@ public static function validMergeQueryPairsProvider(): array ]; } - /** - * @dataProvider validMergeQueryParametersProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validMergeQueryParametersProvider')] public function testMergeQueryParameters(iterable $parameters, string $expected): void { self::assertSame($expected, $this->modifier->mergeQueryParameters($parameters)->getUri()->getQuery()); @@ -102,9 +95,7 @@ public static function validMergeQueryParametersProvider(): array ]; } - /** - * @dataProvider validAppendQueryProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validAppendQueryProvider')] public function testAppendQuery(string $query, string $expected): void { self::assertSame($expected, $this->modifier->appendQuery($query)->getUri()->getQuery()); @@ -118,9 +109,7 @@ public static function validAppendQueryProvider(): array ]; } - /** - * @dataProvider validAppendQueryPairsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validAppendQueryPairsProvider')] public function testAppendQueryPairs(iterable $query, string $expected): void { self::assertSame($expected, $this->modifier->appendQueryPairs($query)->getUri()->getQuery()); @@ -140,9 +129,7 @@ public static function validAppendQueryPairsProvider(): array ]; } - /** - * @dataProvider validAppendQueryParametersProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validAppendQueryParametersProvider')] public function testAppendQueryParameters(iterable $query, string $expected): void { self::assertSame($expected, $this->modifier->appendQueryParameters($query)->getUri()->getQuery()); @@ -168,9 +155,7 @@ public function testKsortQuery(): void self::assertSame('foo=bar%20baz&kingkong=toto&kingkong=ape', Modifier::from($uri)->sortQuery()->getUri()->getQuery()); } - /** - * @dataProvider validWithoutQueryValuesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validWithoutQueryValuesProvider')] public function testWithoutQueryValuesProcess(array $input, string $expected): void { self::assertSame($expected, $this->modifier->removeQueryPairsByKey(...$input)->getUri()->getQuery()); @@ -184,9 +169,7 @@ public static function validWithoutQueryValuesProvider(): array ]; } - /** - * @dataProvider validWithoutQueryPairByValueProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validWithoutQueryPairByValueProvider')] public function testvalidWithoutQueryPairByValue(array $values, string $expected): void { self::assertSame($expected, $this->modifier->removeQueryPairsByValue(...$values)->getUri()->getQuery()); @@ -200,9 +183,7 @@ public static function validWithoutQueryPairByValueProvider(): array ]; } - /** - * @dataProvider validWithoutQueryPairByKeyValueProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validWithoutQueryPairByKeyValueProvider')] public function testvalidWithoutQueryPairByKeyValue(array $values, string $expected): void { self::assertSame($expected, $this->modifier->removeQueryPairsByKeyValue(...$values)->getUri()->getQuery()); @@ -217,9 +198,7 @@ public static function validWithoutQueryPairByKeyValueProvider(): array ]; } - /** - * @dataProvider removeParamsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('removeParamsProvider')] public function testWithoutQueryParams(string $uri, array $input, ?string $expected): void { self::assertSame($expected, Modifier::from($uri)->removeQueryParameters(...$input)->getUri()->getQuery()); @@ -246,9 +225,7 @@ public static function removeParamsProvider(): array ]; } - /** - * @dataProvider removeQueryParameterIndicesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('removeQueryParameterIndicesProvider')] public function testWithoutQueryParameterIndices(string $uri, string $expected): void { self::assertSame($expected, Modifier::from($uri)->removeQueryParameterIndices()->getUri()->getQuery()); @@ -272,9 +249,7 @@ public static function removeQueryParameterIndicesProvider(): array ]; } - /** - * @dataProvider removeEmptyPairsProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('removeEmptyPairsProvider')] public function testRemoveEmptyPairs(string $uri, ?string $expected): void { self::assertSame($expected, Modifier::from(Uri::fromBaseUri($uri))->removeEmptyQueryPairs()->getUri()->__toString()); @@ -327,26 +302,19 @@ public function testEncodeQuery(): void /***************************** * HOST MODIFIER METHOD TESTS ****************************/ - - /** - * @dataProvider validHostProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validHostProvider')] public function testPrependLabelProcess(string $label, int $key, string $prepend, string $append, string $replace): void { self::assertSame($prepend, $this->modifier->prependLabel($label)->getUri()->getHost()); } - /** - * @dataProvider validHostProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validHostProvider')] public function testAppendLabelProcess(string $label, int $key, string $prepend, string $append, string $replace): void { self::assertSame($append, $this->modifier->appendLabel($label)->getUri()->getHost()); } - /** - * @dataProvider validHostProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validHostProvider')] public function testReplaceLabelProcess(string $label, int $key, string $prepend, string $append, string $replace): void { self::assertSame($replace, $this->modifier->replaceLabel($key, $label)->getUri()->getHost()); @@ -435,9 +403,7 @@ public function testWithoutZoneIdentifierProcess(): void ); } - /** - * @dataProvider validwithoutLabelProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validwithoutLabelProvider')] public function testwithoutLabelProcess(array $keys, string $expected): void { self::assertSame($expected, $this->modifier->removeLabels(...$keys)->getUri()->getHost()); @@ -553,18 +519,13 @@ public function testIpv4NormalizeHostWithLeagueUri(): void /********************* * PATH MODIFIER TESTS *********************/ - - /** - * @dataProvider fileProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileProvider')] public function testToBinary(Uri $binary, Uri $ascii): void { self::assertSame($binary->toString(), Modifier::from($ascii)->dataPathToBinary()->getUriString()); } - /** - * @dataProvider fileProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileProvider')] public function testToAscii(Uri $binary, Uri $ascii): void { self::assertSame($ascii->toString(), Modifier::from($binary)->dataPathToAscii()->getUriString()); @@ -598,9 +559,7 @@ public function testDataUriWithParameters(): void ); } - /** - * @dataProvider appendSegmentProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('appendSegmentProvider')] public function testAppendProcess(string $segment, string $append): void { self::assertSame($append, $this->modifier->appendSegment($segment)->getUri()->getPath()); @@ -614,9 +573,7 @@ public static function appendSegmentProvider(): array ]; } - /** - * @dataProvider validAppendSegmentProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validAppendSegmentProvider')] public function testAppendProcessWithRelativePath(string $uri, string $segment, string $expected): void { self::assertSame($expected, (string) Modifier::from($uri)->appendSegment($segment)->getUri()); @@ -648,9 +605,7 @@ public static function validAppendSegmentProvider(): array ]; } - /** - * @dataProvider validBasenameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validBasenameProvider')] public function testBasename(string $path, string $uri, string $expected): void { self::assertSame($expected, (string) Modifier::from(Uri::new($uri))->replaceBasename($path)); @@ -673,9 +628,7 @@ public function testBasenameThrowException(): void Modifier::from(Uri::new('http://example.com'))->replaceBasename('foo/baz'); } - /** - * @dataProvider validDirnameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validDirnameProvider')] public function testDirname(string $path, string $uri, string $expected): void { self::assertSame($expected, (string) Modifier::from(Uri::new($uri))->replaceDirname($path)); @@ -691,9 +644,7 @@ public static function validDirnameProvider(): array ]; } - /** - * @dataProvider prependSegmentProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('prependSegmentProvider')] public function testPrependProcess(string $uri, string $segment, string $prepend): void { $uri = Uri::new($uri); @@ -726,9 +677,7 @@ public static function prependSegmentProvider(): array ]; } - /** - * @dataProvider replaceSegmentProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('replaceSegmentProvider')] public function testReplaceSegmentProcess(string $segment, int $key, string $append, string $prepend, string $replace): void { self::assertSame($replace, $this->modifier->replaceSegment($key, $segment)->getUri()->getPath()); @@ -742,9 +691,7 @@ public static function replaceSegmentProvider(): array ]; } - /** - * @dataProvider addBasepathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('addBasepathProvider')] public function testaddBasepath(string $basepath, string $expected): void { self::assertSame($expected, $this->modifier->addBasePath($basepath)->getUri()->getPath()); @@ -766,9 +713,7 @@ public function testaddBasepathWithRelativePath(): void self::assertSame('/base/path', Modifier::from($uri)->addBasePath('/base/path')->getUri()->getPath()); } - /** - * @dataProvider removeBasePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('removeBasePathProvider')] public function testRemoveBasePath(string $basepath, string $expected): void { self::assertSame($expected, $this->modifier->removeBasePath($basepath)->getUri()->getPath()); @@ -790,9 +735,7 @@ public function testRemoveBasePathWithRelativePath(): void self::assertSame('base/path', Modifier::from($uri)->removeBasePath('/base/path')->getUri()->getPath()); } - /** - * @dataProvider validwithoutSegmentProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validwithoutSegmentProvider')] public function testwithoutSegment(array $keys, string $expected): void { self::assertSame($expected, $this->modifier->removeSegments(...$keys)->getUri()->getPath()); @@ -827,9 +770,7 @@ public function testWithoutTrailingSlashProcess(): void self::assertSame('', Modifier::from($uri)->removeTrailingSlash()->getUri()->getPath()); } - /** - * @dataProvider validExtensionProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('validExtensionProvider')] public function testExtensionProcess(string $extension, string $expected): void { self::assertSame($expected, $this->modifier->replaceExtension($extension)->getUri()->getPath()); diff --git a/components/UriModifierTest.php b/components/UriModifierTest.php index 0d5ec37e..997d3b57 100644 --- a/components/UriModifierTest.php +++ b/components/UriModifierTest.php @@ -17,7 +17,7 @@ final class UriModifierTest extends TestCase { - /** @test */ + #[\PHPUnit\Framework\Attributes\Test] public function it_will_remove_empty_pairs_fix_issue_133(): void { $removeEmptyPairs = fn (string $str): ?string => UriModifier::removeEmptyPairs(Http::createFromString($str))->getQuery(); /* @phpstan-ignore-line */ diff --git a/composer.json b/composer.json index 4770bf75..11fbceb4 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "phpstan/phpstan-deprecation-rules": "^1.1.4", "phpstan/phpstan-phpunit": "^1.3.16", "phpstan/phpstan-strict-rules": "^1.5.3", - "phpunit/phpunit": "^10.5.17", + "phpunit/phpunit": "^10.5.17 || ^11.1.1", "psr/http-factory": "^1.0.2", "psr/http-message": "^1.1.0 || ^2.0", "symfony/var-dumper": "^6.4.6", @@ -84,5 +84,8 @@ }, "config": { "sort-packages": true + }, + "require-dev": { + "rector/rector": "^1.0.4" } } diff --git a/interfaces/IPv4/ConverterTest.php b/interfaces/IPv4/ConverterTest.php index 318cd420..698ad760 100644 --- a/interfaces/IPv4/ConverterTest.php +++ b/interfaces/IPv4/ConverterTest.php @@ -15,22 +15,16 @@ use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass \League\Uri\IPv4\Converter - */ +#[\PHPUnit\Framework\Attributes\CoversClass(\League\Uri\IPv4\Converter::class)] final class ConverterTest extends TestCase { - /** - * @dataProvider providerHost - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providerHost')] public function testParseWithAutoDetectCalculator(?string $input, ?string $expected): void { self::assertEquals($expected, Converter::fromEnvironment()->toDecimal($input) ?? $input); } - /** - * @dataProvider providerHost - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providerHost')] public function testConvertToDecimal(string $input, string $decimal, string $octal, string $hexadecimal): void { self::assertSame($octal, Converter::fromGMP()->toOctal($input)); @@ -64,9 +58,7 @@ public static function providerHost(): array ]; } - /** - * @dataProvider providerInvalidHost - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providerInvalidHost')] public function testParseWithInvalidHost(?string $input): void { self::assertNull(Converter::fromBCMath()->toHexadecimal($input)); diff --git a/interfaces/Idna/ConverterTest.php b/interfaces/Idna/ConverterTest.php index b5b06ea0..4ff4568c 100644 --- a/interfaces/Idna/ConverterTest.php +++ b/interfaces/Idna/ConverterTest.php @@ -13,17 +13,15 @@ namespace League\Uri\Idna; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Stringable; -/** - * @coversDefaultClass \League\Uri\Idna\Converter - */ +#[CoversClass(Converter::class)] final class ConverterTest extends TestCase { - /** - * @dataProvider invalidDomainProvider - */ + #[DataProvider('invalidDomainProvider')] public function testToAsciiThrowsException(string $domain): void { self::assertNotEmpty(Converter::toAscii($domain)->errors()); @@ -48,9 +46,7 @@ public function testToUnicodeThrowsException(): void self::assertNotEmpty(Converter::toUnicode('xn--a-ecp.ru')->errors()); } - /** - * @dataProvider toUnicodeProvider - */ + #[DataProvider('toUnicodeProvider')] public function testToIDN(Stringable|string $domain, string $expectedDomain): void { self::assertSame($expectedDomain, Converter::toUnicode($domain)->domain()); @@ -94,9 +90,7 @@ public function __toString(): string ]; } - /** - * @dataProvider toAsciiProvider - */ + #[DataProvider('toAsciiProvider')] public function testToAscii(Stringable|string $domain, string $expectedDomain): void { self::assertSame($expectedDomain, Converter::toAscii($domain)->domain()); @@ -142,9 +136,7 @@ public function testExceptionThrownOnConversionToAsciiIfTheDomainLabelIsTooLong( self::assertNotEmpty(Converter::toAscii('aa'.str_repeat('A', 64))->errors()); } - /** - * @dataProvider provideIDNUri - */ + #[DataProvider('provideIDNUri')] public function testHostIsIDN(Stringable|string|null $host, bool $expected): void { self::assertSame($expected, Converter::isIdn($host)); diff --git a/interfaces/QueryStringTest.php b/interfaces/QueryStringTest.php index a9b75702..72f2dcda 100644 --- a/interfaces/QueryStringTest.php +++ b/interfaces/QueryStringTest.php @@ -14,6 +14,7 @@ use ArrayIterator; use League\Uri\Components\Fragment; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Stringable; @@ -58,9 +59,7 @@ public function testBuildThrowsExceptionWithQueryBuilder(): void QueryString::build([['foo', 'boo' => 'bar']]); /* @phpstan-ignore-line */ } - /** - * @dataProvider extractQueryProvider - */ + #[DataProvider('extractQueryProvider')] public function testExtractQuery(Stringable|string|null|bool $query, array $expectedData): void { self::assertSame($expectedData, QueryString::extract($query)); @@ -148,10 +147,9 @@ public static function extractQueryProvider(): array } /** - * @dataProvider parserProvider - * * @param non-empty-string $separator */ + #[DataProvider('parserProvider')] public function testParse(Stringable|string|null|bool $query, string $separator, array $expected, int $encoding): void { self::assertSame($expected, QueryString::parse($query, $separator, $encoding)); @@ -300,9 +298,7 @@ public function __toString(): string ]; } - /** - * @dataProvider buildProvider - */ + #[DataProvider('buildProvider')] public function testBuild( iterable $pairs, ?string $expected_rfc1738, @@ -403,9 +399,7 @@ public static function buildProvider(): array ]; } - /** - * @dataProvider failedBuilderProvider - */ + #[DataProvider('failedBuilderProvider')] public function testBuildQueryThrowsException(iterable $pairs, string $separator, int $enc_type): void { $this->expectException(SyntaxError::class); @@ -448,9 +442,7 @@ public static function failedBuilderProvider(): array ]; } - /** - * @dataProvider queryProvider - */ + #[DataProvider('queryProvider')] public function testStringRepresentationComponent(string|array $input, string|null $expected): void { $query = is_array($input) ? QueryString::build($input) : QueryString::build(QueryString::parse($input)); diff --git a/interfaces/UriStringTest.php b/interfaces/UriStringTest.php index 2d253856..87fce8b5 100644 --- a/interfaces/UriStringTest.php +++ b/interfaces/UriStringTest.php @@ -12,6 +12,7 @@ namespace League\Uri; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Stringable; @@ -19,9 +20,7 @@ final class UriStringTest extends TestCase { - /** - * @dataProvider validUriProvider - */ + #[DataProvider('validUriProvider')] public function testParseSucced(Stringable|string|int $uri, array $expected): void { self::assertSame($expected, UriString::parse($uri)); @@ -740,9 +739,7 @@ public function __toString(): string ]; } - /** - * @dataProvider invalidUriProvider - */ + #[DataProvider('invalidUriProvider')] public function testParseFailed(string $uri): void { self::expectException(SyntaxError::class); @@ -778,9 +775,7 @@ public static function invalidUriProvider(): array ]; } - /** - * @dataProvider buildUriProvider - */ + #[DataProvider('buildUriProvider')] public function testBuild(string $uri, string $expected): void { self::assertSame($expected, UriString::build(UriString::parse($uri))); diff --git a/uri/BaseUriTest.php b/uri/BaseUriTest.php index 259826a8..81514c69 100644 --- a/uri/BaseUriTest.php +++ b/uri/BaseUriTest.php @@ -13,13 +13,14 @@ use GuzzleHttp\Psr7\Utils; use Nyholm\Psr7\Factory\Psr17Factory; +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 modifier - * @coversDefaultClass \League\Uri\BaseUri - */ +#[CoversClass(BaseUri::class)] +#[Group('modifier')] final class BaseUriTest extends TestCase { private const BASE_URI = 'http://a/b/c/d;p?q'; @@ -32,9 +33,7 @@ public function testItCanBeJsonSerialized(): void ); } - /** - * @dataProvider resolveProvider - */ + #[DataProvider('resolveProvider')] public function testCreateResolve(string $baseUri, string $uri, string $expected): void { $uriResolved = BaseUri::from($baseUri)->resolve($uri); @@ -100,9 +99,7 @@ public function testRelativizeIsNotMade(): void self::assertEquals($uri, BaseUri::from('https://example.com/path')->relativize($uri)->getUriString()); } - /** - * @dataProvider relativizeProvider - */ + #[DataProvider('relativizeProvider')] public function testRelativize(string $uri, string $resolved, string $expected): void { self::assertSame( @@ -154,9 +151,7 @@ public static function relativizeProvider(): array ]; } - /** - * @dataProvider relativizeAndResolveProvider - */ + #[DataProvider('relativizeAndResolveProvider')] public function testRelativizeAndResolve( string $baseUri, string $uri, @@ -187,10 +182,9 @@ public static function relativizeAndResolveProvider(): array } /** - * @dataProvider uriProvider - * * @param array $infos */ + #[DataProvider('uriProvider')] public function testInfo( Psr7UriInterface|Uri $uri, Psr7UriInterface|Uri|null $base_uri, @@ -263,9 +257,7 @@ public function testIsFunctionsThrowsTypeError(): void self::assertTrue(BaseUri::from('example.com#foobar')->isRelativePath()); } - /** - * @dataProvider sameValueAsProvider - */ + #[DataProvider('sameValueAsProvider')] public function testSameValueAs(Psr7UriInterface|Uri $uri1, Psr7UriInterface|Uri $uri2, bool $expected): void { self::assertSame($expected, BaseUri::from($uri2)->isSameDocument($uri1)); @@ -322,9 +314,7 @@ public static function sameValueAsProvider(): array ]; } - /** - * @dataProvider getOriginProvider - */ + #[DataProvider('getOriginProvider')] public function testGetOrigin(Psr7UriInterface|Uri|string $uri, ?string $expectedOrigin): void { self::assertSame($expectedOrigin, BaseUri::from($uri)->origin()?->__toString()); @@ -372,9 +362,7 @@ public static function getOriginProvider(): array ]; } - /** - * @dataProvider getCrossOriginExamples - */ + #[DataProvider('getCrossOriginExamples')] public function testIsCrossOrigin(string $original, string $modified, bool $expected): void { self::assertSame($expected, BaseUri::from($original)->isCrossOrigin($modified)); @@ -403,9 +391,7 @@ public static function getCrossOriginExamples(): array ]; } - /** - * @dataProvider resolveProvider - */ + #[DataProvider('resolveProvider')] public function testResolveWithPsr7Implementation(string $baseUri, string $uri, string $expected): void { $resolvedUri = BaseUri::from(Utils::uriFor($baseUri))->resolve($uri); @@ -414,9 +400,7 @@ public function testResolveWithPsr7Implementation(string $baseUri, string $uri, self::assertSame($expected, (string) $resolvedUri); } - /** - * @dataProvider relativizeProvider - */ + #[DataProvider('relativizeProvider')] public function testRelativizeWithPsr7Implementation(string $uriString, string $resolved, string $expected): void { $uri = Utils::uriFor($uriString); @@ -436,9 +420,7 @@ public function testRelativizeWithPsr7Implementation(string $uriString, string $ self::assertSame($expected, (string) $relativizeUri); } - /** - * @dataProvider getOriginProvider - */ + #[DataProvider('getOriginProvider')] public function testGetOriginWithPsr7Implementation(Psr7UriInterface|Uri|string $uri, ?string $expectedOrigin): void { $origin = BaseUri::from(Utils::uriFor((string) $uri), new \GuzzleHttp\Psr7\HttpFactory())->origin(); @@ -452,9 +434,7 @@ public function testGetOriginWithPsr7Implementation(Psr7UriInterface|Uri|string self::assertSame($expectedOrigin, $origin); } - /** - * @dataProvider provideIDNUri - */ + #[DataProvider('provideIDNUri')] public function testHostIsIDN(string $uri, bool $expected): void { self::assertSame($expected, BaseUri::from($uri)->hasIdn()); @@ -489,7 +469,7 @@ public static function provideIDNUri(): iterable ]; } - /** @dataProvider unixpathProvider */ + #[DataProvider('unixpathProvider')] public function testReturnsUnixPath(?string $expected, string $input): void { self::assertSame($expected, BaseUri::from($input)->unixPath()); @@ -526,7 +506,7 @@ public static function unixpathProvider(): array ]; } - /** @dataProvider windowLocalPathProvider */ + #[DataProvider('windowLocalPathProvider')] public function testReturnsWindowsPath(?string $expected, string $input): void { self::assertSame($expected, BaseUri::from($input)->windowsPath()); @@ -575,7 +555,7 @@ public static function windowLocalPathProvider(): array ]; } - /** @dataProvider rfc8089UriProvider */ + #[DataProvider('rfc8089UriProvider')] public function testReturnsRFC8089UriString(?string $expected, string $input): void { self::assertSame($expected, BaseUri::from($input)->toRfc8089()); diff --git a/uri/DataTest.php b/uri/DataTest.php index f7dde10d..0e708428 100644 --- a/uri/DataTest.php +++ b/uri/DataTest.php @@ -12,13 +12,14 @@ 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; -/** - * @group data - * @group uri - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(\League\Uri\Uri::class)] +#[Group('data')] +#[Group('uri')] final class DataTest extends TestCase { public function testDefaultConstructor(): void @@ -29,9 +30,7 @@ public function testDefaultConstructor(): void ); } - /** - * @dataProvider validUrlProvider - */ + #[DataProvider('validUrlProvider')] public function testCreateFromString(string $uri, string $path): void { self::assertSame($path, Uri::new($uri)->getPath()); @@ -63,9 +62,7 @@ public static function validUrlProvider(): array ]; } - /** - * @dataProvider invalidUrlProvider - */ + #[DataProvider('invalidUrlProvider')] public function testCreateFromStringFailed(string $uri): void { self::expectException(SyntaxError::class); @@ -80,9 +77,7 @@ public static function invalidUrlProvider(): array } - /** - * @dataProvider invalidComponentProvider - */ + #[DataProvider('invalidComponentProvider')] public function testCreateFromStringFailedWithWrongComponent(string $uri): void { self::expectException(SyntaxError::class); diff --git a/uri/FactoryTest.php b/uri/FactoryTest.php index cc2c9062..d7c167e8 100644 --- a/uri/FactoryTest.php +++ b/uri/FactoryTest.php @@ -13,18 +13,17 @@ use League\Uri\Exceptions\SyntaxError; use Nyholm\Psr7\Uri as NyholmUri; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Stringable; -/** - * @group factory - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(Uri::class)] +#[Group('factory')] final class FactoryTest extends TestCase { - /** - * @dataProvider invalidDataPath - */ + #[DataProvider('invalidDataPath')] public function testCreateFromPathFailed(string $path): void { self::expectException(SyntaxError::class); @@ -38,9 +37,7 @@ public static function invalidDataPath(): array ]; } - /** - * @dataProvider validFilePath - */ + #[DataProvider('validFilePath')] public function testCreateFromPath(string $path, string $expected): void { $context = stream_context_create([ @@ -62,7 +59,7 @@ public static function validFilePath(): array ]; } - /** @dataProvider provideValidData */ + #[DataProvider('provideValidData')] public function testFromData(string $data, string $mimetype, string $parameters, string $expected): void { self::assertSame($expected, Uri::fromData($data, $mimetype, $parameters)->toString()); @@ -141,9 +138,7 @@ public function testFromDataFailsWithMalformedParameters(): void Uri::fromData('Hello World!', 'text/plain', 'foobar'); } - /** - * @dataProvider unixpathProvider - */ + #[DataProvider('unixpathProvider')] public function testCreateFromUnixPath(string $uri, string $expected): void { self::assertSame($expected, Uri::fromUnixPath($uri)->toString()); @@ -175,9 +170,7 @@ public static function unixpathProvider(): array ]; } - /** - * @dataProvider windowLocalPathProvider - */ + #[DataProvider('windowLocalPathProvider')] public function testCreateFromWindowsLocalPath(string $uri, string $expected): void { self::assertSame($expected, Uri::fromWindowsPath($uri)->toString()); @@ -221,7 +214,7 @@ public static function windowLocalPathProvider(): array ]; } - /** @dataProvider rfc8089UriProvider */ + #[DataProvider('rfc8089UriProvider')] public function testCreateFromRfc8089(string $expected, string $uri): void { self::assertSame($expected, Uri::fromRfc8089($uri)->toString()); @@ -245,7 +238,7 @@ public static function rfc8089UriProvider(): iterable ]; } - /** @dataProvider invalidRfc8089UriProvider */ + #[DataProvider('invalidRfc8089UriProvider')] public function testIfFailsToGenerateAnUriFromRfc8089(string $invalidUri): void { $this->expectException(SyntaxError::class); @@ -281,9 +274,7 @@ public function testCreateFromUri(): void self::assertSame((string) $uribis, Uri::new($uribis)->toString()); } - /** - * @dataProvider validServerArray - */ + #[DataProvider('validServerArray')] public function testCreateFromServer(string $expected, array $input): void { self::assertSame($expected, Uri::fromServer($input)->toString()); @@ -459,9 +450,7 @@ public function testFailCreateFromServerWithoutInvalidUserInfo(): void ]); } - /** - * @dataProvider createProvider - */ + #[DataProvider('createProvider')] public function testCreateFromBaseUri(Stringable|string $baseUri, Stringable|string $uri, string $expected): void { self::assertSame($expected, Uri::fromBaseUri($uri, $baseUri)->toString()); diff --git a/uri/FileTest.php b/uri/FileTest.php index d2b00dde..7ee9d045 100644 --- a/uri/FileTest.php +++ b/uri/FileTest.php @@ -12,13 +12,14 @@ 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; -/** - * @group file - * @group uri - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(\League\Uri\Uri::class)] +#[Group('file')] +#[Group('uri')] final class FileTest extends TestCase { public function testDefaultConstructor(): void @@ -26,9 +27,7 @@ public function testDefaultConstructor(): void self::assertSame('', (string) Uri::new()); } - /** - * @dataProvider validUrlProvider - */ + #[DataProvider('validUrlProvider')] public function testCreateFromString(string $uri, string $expected): void { self::assertSame($expected, (string) Uri::new($uri)); @@ -80,9 +79,7 @@ public static function validUrlProvider(): array ]; } - /** - * @dataProvider invalidUrlProvider - */ + #[DataProvider('invalidUrlProvider')] public function testConstructorThrowsException(string $uri): void { self::expectException(SyntaxError::class); diff --git a/uri/FtpTest.php b/uri/FtpTest.php index f54efa68..9828ed78 100644 --- a/uri/FtpTest.php +++ b/uri/FtpTest.php @@ -12,18 +12,17 @@ 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; -/** - * @group ftp - * @group uri - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(Uri::class)] +#[Group('ftp')] +#[Group('uri')] final class FtpTest extends TestCase { - /** - * @dataProvider validUrlProvider - */ + #[DataProvider('validUrlProvider')] public function testCreateFromString(string $uri, string $expected): void { self::assertSame($expected, (string) Uri::new($uri)); @@ -59,11 +58,8 @@ public static function validUrlProvider(): array ]; } - /** - * - * @dataProvider invalidUrlProvider - */ + #[DataProvider('invalidUrlProvider')] public function testConstructorThrowInvalidArgumentException(string $uri): void { self::expectException(SyntaxError::class); @@ -89,9 +85,7 @@ public function testModificationFailedWithEmptyAuthority(): void ->withPath('//toto'); } - /** - * @dataProvider portProvider - */ + #[DataProvider('portProvider')] public function testPort(string $uri, ?int $port): void { self::assertSame($port, Uri::new($uri)->getPort()); diff --git a/uri/HttpTest.php b/uri/HttpTest.php index 8b18dc24..9ed3448b 100644 --- a/uri/HttpTest.php +++ b/uri/HttpTest.php @@ -13,13 +13,14 @@ use InvalidArgumentException; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\UriInterface; -/** - * @group http - * @coversDefaultClass \League\Uri\Http - */ +#[CoversClass(Http::class)] +#[Group('http')] final class HttpTest extends TestCase { public function createUri(string $uri): UriInterface @@ -107,9 +108,7 @@ public function testCreateFromUri(): void ); } - /** - * @dataProvider validUrlProvider - */ + #[DataProvider('validUrlProvider')] public function testCreateFromString(string $expected, string $uri): void { self::assertSame($expected, (string) Http::new($uri)); @@ -141,9 +140,7 @@ public static function validUrlProvider(): array ]; } - /** - * @dataProvider invalidUrlProvider - */ + #[DataProvider('invalidUrlProvider')] public function testIsValid(string $uri): void { self::expectException(SyntaxError::class); @@ -162,9 +159,7 @@ public static function invalidUrlProvider(): array ]; } - /** - * @dataProvider portProvider - */ + #[DataProvider('portProvider')] public function testValidPort(string $uri, ?int $port): void { self::assertSame($port, Http::new($uri)->getPort()); @@ -180,9 +175,7 @@ public static function portProvider(): array ]; } - /** - * @dataProvider invalidPathProvider - */ + #[DataProvider('invalidPathProvider')] public function testPathIsInvalid(string $path): void { self::expectException(SyntaxError::class); @@ -199,9 +192,7 @@ public static function invalidPathProvider(): array ]; } - /** - * @dataProvider invalidURI - */ + #[DataProvider('invalidURI')] public function testCreateFromInvalidUrlKO(string $uri): void { self::expectException(SyntaxError::class); diff --git a/uri/UriTemplate/ExpressionTest.php b/uri/UriTemplate/ExpressionTest.php index 9eb444fa..8c165ade 100644 --- a/uri/UriTemplate/ExpressionTest.php +++ b/uri/UriTemplate/ExpressionTest.php @@ -14,16 +14,14 @@ namespace League\Uri\UriTemplate; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass \League\Uri\UriTemplate\Expression - */ +#[CoversClass(Expression::class)] final class ExpressionTest extends TestCase { - /** - * @dataProvider providesValidNotation - */ + #[DataProvider('providesValidNotation')] public function testItCanBeInstantiatedWithAValidNotation(string $notation, array $variableNames): void { $expression = Expression::new($notation); @@ -55,9 +53,7 @@ public static function providesValidNotation(): iterable ]; } - /** - * @dataProvider providesInvalidExpression - */ + #[DataProvider('providesInvalidExpression')] public function testExpressionConstructFailsWithInvalidString(string $expression): void { self::expectException(SyntaxError::class); @@ -101,9 +97,7 @@ public static function providesInvalidExpression(): iterable ]; } - /** - * @dataProvider templateExpansionProvider - */ + #[DataProvider('templateExpansionProvider')] public function testExpandsUriTemplates(string $template, string $expectedUriString, array $variables): void { self::assertSame($expectedUriString, Expression::new($template)->expand(new VariableBag($variables))); @@ -226,9 +220,7 @@ public static function templateExpansionProvider(): iterable } } - /** - * @dataProvider invalidModifierToApply - */ + #[DataProvider('invalidModifierToApply')] public function testExpandThrowsExceptionIfTheModifierCanNotBeApplied(string $expression, array $variables): void { self::expectException(TemplateCanNotBeExpanded::class); diff --git a/uri/UriTemplate/TemplateTest.php b/uri/UriTemplate/TemplateTest.php index e849e075..ca9dae7c 100644 --- a/uri/UriTemplate/TemplateTest.php +++ b/uri/UriTemplate/TemplateTest.php @@ -15,15 +15,16 @@ use JsonException; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use RuntimeException; use Throwable; use const JSON_THROW_ON_ERROR; -/** - * @coversDefaultClass \League\Uri\UriTemplate\Template - */ +#[CoversClass(Template::class)] final class TemplateTest extends TestCase { private static string $rootPath = __DIR__.'/../../vendor/uri-templates/uritemplate-test'; @@ -35,10 +36,8 @@ final class TemplateTest extends TestCase 'extended-tests.json', ]; - /** - * @test - * @dataProvider uriTemplateSpecificationDataProvider - */ + #[DataProvider('uriTemplateSpecificationDataProvider')] + #[Test] public function testItCompliesWithUriTemplatesExpansionTests( array $variables, string $input, @@ -90,9 +89,7 @@ public static function uriTemplateSpecificationDataProvider(): iterable } } - /** - * @dataProvider providesValidNotation - */ + #[DataProvider('providesValidNotation')] public function testItCanBeInstantiatedWithAValidNotation(string $notation): void { self::assertSame($notation, Template::new($notation)->value); @@ -108,9 +105,7 @@ public static function providesValidNotation(): iterable ]; } - /** - * @dataProvider providesInvalidNotation - */ + #[DataProvider('providesInvalidNotation')] public function testItFailsToInstantiatedWithAnInvalidNotation(string $notation): void { self::expectException(SyntaxError::class); @@ -129,9 +124,7 @@ public static function providesInvalidNotation(): iterable ]; } - /** - * @dataProvider expectedVariableNames - */ + #[DataProvider('expectedVariableNames')] public function testGetVariableNames(string $template, array $expected): void { self::assertSame($expected, Template::new($template)->variableNames); @@ -159,9 +152,7 @@ public static function expectedVariableNames(): iterable ]; } - /** - * @dataProvider providesExpansion - */ + #[DataProvider('providesExpansion')] public function testItCanExpandVariables(string $notation, array $variables, string $expected): void { self::assertSame($expected, Template::new($notation)->expand($variables)); diff --git a/uri/UriTemplate/VarSpecifierTest.php b/uri/UriTemplate/VarSpecifierTest.php index b71bd90d..f18df78a 100644 --- a/uri/UriTemplate/VarSpecifierTest.php +++ b/uri/UriTemplate/VarSpecifierTest.php @@ -14,16 +14,14 @@ namespace League\Uri\UriTemplate; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass \League\Uri\UriTemplate\VarSpecifier - */ +#[CoversClass(VarSpecifier::class)] final class VarSpecifierTest extends TestCase { - /** - * @dataProvider providesValidNotation - */ + #[DataProvider('providesValidNotation')] public function testItCanBeInstantiatedWithAValidNotation(string $notation): void { self::assertSame($notation, VarSpecifier::new($notation)->toString()); @@ -43,9 +41,7 @@ public static function providesValidNotation(): iterable ]; } - /** - * @dataProvider providesInvalidNotation - */ + #[DataProvider('providesInvalidNotation')] public function testItFailsToInstantiatedWithAnInvalidNotationString(string $notation): void { self::expectException(SyntaxError::class); diff --git a/uri/UriTemplate/VariableBagTest.php b/uri/UriTemplate/VariableBagTest.php index 6c124356..b885729a 100644 --- a/uri/UriTemplate/VariableBagTest.php +++ b/uri/UriTemplate/VariableBagTest.php @@ -14,20 +14,19 @@ namespace League\Uri\UriTemplate; use ArrayIterator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; use TypeError; -/** - * @coversDefaultClass \League\Uri\UriTemplate\VariableBag - */ +#[CoversClass(VariableBag::class)] final class VariableBagTest extends TestCase { /** * @param array> $expected - * - * @dataProvider provideValidIterable */ + #[DataProvider('provideValidIterable')] public function testItCanBeInstantiatedWithAnIterable( iterable $iterable, array $expected, @@ -69,9 +68,8 @@ public static function provideValidIterable(): iterable /** * @param int|float|string|bool|array $value the value to be assigned to the name * @param string|array $expected - * - * @dataProvider provideValidAssignParameters */ + #[DataProvider('provideValidAssignParameters')] public function testItCanAssignNameAndValuesToTheBag( string $name, int|float|string|bool|array $value, diff --git a/uri/UriTemplateTest.php b/uri/UriTemplateTest.php index 3538f7e1..2d55944a 100644 --- a/uri/UriTemplateTest.php +++ b/uri/UriTemplateTest.php @@ -15,11 +15,11 @@ use League\Uri\Exceptions\SyntaxError; use League\Uri\UriTemplate\TemplateCanNotBeExpanded; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass \League\Uri\UriTemplate - */ +#[CoversClass(UriTemplate::class)] final class UriTemplateTest extends TestCase { public function testGetTemplate(): void @@ -84,9 +84,7 @@ public function testWithDefaultVariables(): void self::assertNotEquals($newTemplate->getDefaultVariables(), $uriTemplate->getDefaultVariables()); } - /** - * @dataProvider expectedVariableNames - */ + #[DataProvider('expectedVariableNames')] public function testGetVariableNames(string $template, array $expected): void { self::assertSame($expected, (new UriTemplate($template))->getVariableNames()); @@ -114,9 +112,7 @@ public static function expectedVariableNames(): iterable ]; } - /** - * @dataProvider templateExpansionProvider - */ + #[DataProvider('templateExpansionProvider')] public function testExpandsUriTemplates(string $template, string $expectedUriString, array $variables): void { self::assertSame($expectedUriString, (new UriTemplate($template))->expand($variables)->toString()); @@ -325,9 +321,7 @@ public function testExpandWithDefaultVariablesWithOverride(): void ); } - /** - * @dataProvider provideInvalidTemplate - */ + #[DataProvider('provideInvalidTemplate')] public function testInvalidUriTemplate(string $template): void { self::expectException(SyntaxError::class); diff --git a/uri/UriTest.php b/uri/UriTest.php index db72fa47..e5f762f5 100644 --- a/uri/UriTest.php +++ b/uri/UriTest.php @@ -14,13 +14,14 @@ use League\Uri\Components\HierarchicalPath; use League\Uri\Components\Port; use League\Uri\Exceptions\SyntaxError; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use TypeError; -/** - * @group uri - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(Uri::class)] +#[Group('uri')] class UriTest extends TestCase { private Uri $uri; @@ -205,9 +206,7 @@ public function testModificationFailedWithInvalidHost(): void Uri::new('http://example.com/path')->withHost('%23'); } - /** - * @dataProvider missingAuthorityProvider - */ + #[DataProvider('missingAuthorityProvider')] public function testModificationFailedWithMissingAuthority(string $path): void { self::expectException(SyntaxError::class); @@ -381,9 +380,7 @@ public function testUnreservedCharsInPathUnencoded(): void ); } - /** - * @dataProvider userInfoProvider - */ + #[DataProvider('userInfoProvider')] public function testWithUserInfoEncodesUsernameAndPassword(string $user, ?string $credential, string $expected): void { $uri = Uri::new('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); diff --git a/uri/WsTest.php b/uri/WsTest.php index 8a1945e7..c2820257 100644 --- a/uri/WsTest.php +++ b/uri/WsTest.php @@ -12,18 +12,17 @@ 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; -/** - * @group ws - * @group uri - * @coversDefaultClass \League\Uri\Uri - */ +#[CoversClass(\League\Uri\Uri::class)] +#[Group('ws')] +#[Group('uri')] class WsTest extends TestCase { - /** - * @dataProvider validUrlProvider - */ + #[DataProvider('validUrlProvider')] public function testCreateFromString(string $input, string $expected): void { self::assertSame($expected, (string) Uri::new($input)); @@ -59,9 +58,7 @@ public static function validUrlProvider(): array ]; } - /** - * @dataProvider invalidUrlProvider - */ + #[DataProvider('invalidUrlProvider')] public function testConstructorThrowInvalidArgumentException(string $uri): void { self::expectException(SyntaxError::class); @@ -86,9 +83,7 @@ public function testModificationFailedWithEmptyAuthority(): void ->withPath('//toto'); } - /** - * @dataProvider portProvider - */ + #[DataProvider('portProvider')] public function testPort(string $uri, ?int $port): void { self::assertSame($port, Uri::new($uri)->getPort());