From 7a14542bc134fb5e5ae02be23deffb7503634344 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Fri, 12 Apr 2024 09:47:34 +0200 Subject: [PATCH] Add support for PHPUnit 10 and PHPUnit 11 --- BaseUriTest.php | 62 +++++++++++--------------------- DataTest.php | 23 +++++------- FactoryTest.php | 47 ++++++++++-------------- FileTest.php | 19 +++++----- FtpTest.php | 24 +++++-------- HttpTest.php | 29 ++++++--------- UriTemplate/ExpressionTest.php | 22 ++++-------- UriTemplate/TemplateTest.php | 29 ++++++--------- UriTemplate/VarSpecifierTest.php | 14 +++----- UriTemplate/VariableBagTest.php | 12 +++---- UriTemplateTest.php | 18 ++++------ UriTest.php | 17 ++++----- WsTest.php | 23 +++++------- 13 files changed, 124 insertions(+), 215 deletions(-) diff --git a/BaseUriTest.php b/BaseUriTest.php index 259826a89..be04edc86 100644 --- a/BaseUriTest.php +++ b/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()); @@ -505,11 +485,11 @@ public static function unixpathProvider(): array ], 'absolute path' => [ 'expected' => '/path', - 'inout' => 'file:///path', + 'input' => 'file:///path', ], 'path with empty char' => [ 'expected' => '/path empty/bar', - 'inout' => 'file:///path%20empty/bar', + 'input' => 'file:///path%20empty/bar', ], 'relative path with dot segments' => [ 'expected' => 'path/./relative', @@ -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/DataTest.php b/DataTest.php index f7dde10d1..0e708428e 100644 --- a/DataTest.php +++ b/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/FactoryTest.php b/FactoryTest.php index cc2c9062d..e89e2b388 100644 --- a/FactoryTest.php +++ b/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,12 +138,10 @@ public function testFromDataFailsWithMalformedParameters(): void Uri::fromData('Hello World!', 'text/plain', 'foobar'); } - /** - * @dataProvider unixpathProvider - */ - public function testCreateFromUnixPath(string $uri, string $expected): void + #[DataProvider('unixpathProvider')] + public function testCreateFromUnixPath(string $input, string $expected): void { - self::assertSame($expected, Uri::fromUnixPath($uri)->toString()); + self::assertSame($expected, Uri::fromUnixPath($input)->toString()); } public static function unixpathProvider(): array @@ -175,12 +170,10 @@ public static function unixpathProvider(): array ]; } - /** - * @dataProvider windowLocalPathProvider - */ - public function testCreateFromWindowsLocalPath(string $uri, string $expected): void + #[DataProvider('windowLocalPathProvider')] + public function testCreateFromWindowsLocalPath(string $input, string $expected): void { - self::assertSame($expected, Uri::fromWindowsPath($uri)->toString()); + self::assertSame($expected, Uri::fromWindowsPath($input)->toString()); } public static function windowLocalPathProvider(): array @@ -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/FileTest.php b/FileTest.php index d2b00dde6..7ee9d0451 100644 --- a/FileTest.php +++ b/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/FtpTest.php b/FtpTest.php index f54efa681..9828ed780 100644 --- a/FtpTest.php +++ b/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/HttpTest.php b/HttpTest.php index 8b18dc246..9ed3448b1 100644 --- a/HttpTest.php +++ b/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/UriTemplate/ExpressionTest.php b/UriTemplate/ExpressionTest.php index 9eb444fa1..8c165ade0 100644 --- a/UriTemplate/ExpressionTest.php +++ b/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/UriTemplate/TemplateTest.php b/UriTemplate/TemplateTest.php index e849e075c..ca9dae7ce 100644 --- a/UriTemplate/TemplateTest.php +++ b/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/UriTemplate/VarSpecifierTest.php b/UriTemplate/VarSpecifierTest.php index b71bd90db..f18df78a0 100644 --- a/UriTemplate/VarSpecifierTest.php +++ b/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/UriTemplate/VariableBagTest.php b/UriTemplate/VariableBagTest.php index 6c1243566..b885729a2 100644 --- a/UriTemplate/VariableBagTest.php +++ b/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/UriTemplateTest.php b/UriTemplateTest.php index 3538f7e19..2d55944a5 100644 --- a/UriTemplateTest.php +++ b/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/UriTest.php b/UriTest.php index db72fa47b..e5f762f54 100644 --- a/UriTest.php +++ b/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/WsTest.php b/WsTest.php index 8a1945e72..c28202576 100644 --- a/WsTest.php +++ b/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());