diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5fd17f72..263d49b5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -317,11 +317,33 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -341,11 +363,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -355,6 +429,14 @@ + + + + + + + + @@ -363,11 +445,34 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -398,6 +503,18 @@ + + + + + + + + + + + + @@ -406,6 +523,20 @@ + + + + + + + + + + + + + + diff --git a/test/CallbackStreamTest.php b/test/CallbackStreamTest.php index da993622..007cc5e6 100644 --- a/test/CallbackStreamTest.php +++ b/test/CallbackStreamTest.php @@ -5,12 +5,12 @@ namespace LaminasTest\Diactoros; use Laminas\Diactoros\CallbackStream; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RuntimeException; -/** - * @covers \Laminas\Diactoros\CallbackStream - */ +#[CoversClass(CallbackStream::class)] final class CallbackStreamTest extends TestCase { public function testToString(): void @@ -188,10 +188,10 @@ public static function phpCallbacksForStreams(): array } /** - * @dataProvider phpCallbacksForStreams * @param callable(): string $callback * @param non-empty-string $expected */ + #[DataProvider('phpCallbacksForStreams')] public function testAllowsArbitraryPhpCallbacks(callable $callback, string $expected): void { $stream = new CallbackStream($callback); diff --git a/test/HeaderSecurityTest.php b/test/HeaderSecurityTest.php index b5d922c2..0a9d24f0 100644 --- a/test/HeaderSecurityTest.php +++ b/test/HeaderSecurityTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Laminas\Diactoros\HeaderSecurity; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; final class HeaderSecurityTest extends TestCase @@ -34,11 +36,11 @@ public static function getFilterValues(): array } /** - * @dataProvider getFilterValues - * @group ZF2015-04 * @param non-empty-string $value * @param non-empty-string $expected */ + #[DataProvider('getFilterValues')] + #[Group('ZF2015-04')] public function testFiltersValuesPerRfc7230(string $value, string $expected): void { $this->assertSame($expected, HeaderSecurity::filter($value)); @@ -67,10 +69,10 @@ public static function validateValues(): array } /** - * @dataProvider validateValues - * @group ZF2015-04 * @param non-empty-string $value */ + #[DataProvider('validateValues')] + #[Group('ZF2015-04')] public function testValidatesValuesPerRfc7230(string $value, bool $expected): void { self::assertSame($expected, HeaderSecurity::isValid($value)); @@ -95,10 +97,10 @@ public static function assertValues(): array } /** - * @dataProvider assertValues - * @group ZF2015-04 * @param non-empty-string $value */ + #[DataProvider('assertValues')] + #[Group('ZF2015-04')] public function testAssertValidRaisesExceptionForInvalidValue(string $value): void { $this->expectException(InvalidArgumentException::class); @@ -121,9 +123,9 @@ public static function assertNames(): array } /** - * @dataProvider assertNames * @param non-empty-string $value */ + #[DataProvider('assertNames')] public function testAssertValidNameRaisesExceptionForInvalidName(string $value): void { $this->expectException(InvalidArgumentException::class); diff --git a/test/MessageTraitTest.php b/test/MessageTraitTest.php index 972fcf05..ba6ad9c5 100644 --- a/test/MessageTraitTest.php +++ b/test/MessageTraitTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Request; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\StreamInterface; @@ -45,7 +47,7 @@ public static function invalidProtocolVersionProvider(): array ]; } - /** @dataProvider invalidProtocolVersionProvider */ + #[DataProvider('invalidProtocolVersionProvider')] public function testWithProtocolVersionRaisesExceptionForInvalidVersion(string $version): void { $request = new Request(); @@ -64,9 +66,7 @@ public static function validProtocolVersionProvider(): array ]; } - /** - * @dataProvider validProtocolVersionProvider - */ + #[DataProvider('validProtocolVersionProvider')] public function testWithProtocolVersionDoesntRaiseExceptionForValidVersion(string $version): void { $request = (new Request())->withProtocolVersion($version); @@ -180,9 +180,7 @@ public static function invalidGeneralHeaderValues(): array ]; } - /** - * @dataProvider invalidGeneralHeaderValues - */ + #[DataProvider('invalidGeneralHeaderValues')] public function testWithHeaderRaisesExceptionForInvalidNestedHeaderValue(mixed $value): void { $this->expectException(InvalidArgumentException::class); @@ -203,9 +201,7 @@ public static function invalidHeaderValues(): array ]; } - /** - * @dataProvider invalidHeaderValues - */ + #[DataProvider('invalidHeaderValues')] public function testWithHeaderRaisesExceptionForInvalidValueType(mixed $value): void { $this->expectException(InvalidArgumentException::class); @@ -223,9 +219,7 @@ public function testWithHeaderReplacesDifferentCapitalization(): void $this->assertSame(['X-foo' => ['bar']], $new->getHeaders()); } - /** - * @dataProvider invalidGeneralHeaderValues - */ + #[DataProvider('invalidGeneralHeaderValues')] public function testWithAddedHeaderRaisesExceptionForNonStringNonArrayValue(mixed $value): void { $this->expectException(InvalidArgumentException::class); @@ -283,11 +277,11 @@ public static function headersWithInjectionVectors(): array } /** - * @dataProvider headersWithInjectionVectors - * @group ZF2015-04 * @param string $name * @param string|array{string} $value */ + #[DataProvider('headersWithInjectionVectors')] + #[Group('ZF2015-04')] public function testDoesNotAllowCRLFInjectionWhenCallingWithHeader($name, $value): void { $this->expectException(InvalidArgumentException::class); @@ -296,11 +290,11 @@ public function testDoesNotAllowCRLFInjectionWhenCallingWithHeader($name, $value } /** - * @dataProvider headersWithInjectionVectors - * @group ZF2015-04 * @param string $name * @param string|array{string} $value */ + #[DataProvider('headersWithInjectionVectors')] + #[Group('ZF2015-04')] public function testDoesNotAllowCRLFInjectionWhenCallingWithAddedHeader($name, $value): void { $this->expectException(InvalidArgumentException::class); @@ -332,9 +326,7 @@ public static function headersWithWhitespace(): array ]; } - /** - * @dataProvider headersWithWhitespace - */ + #[DataProvider('headersWithWhitespace')] public function testWithHeaderTrimsWhitespace(string $value): void { $message = $this->message->withHeader('X-Foo-Bar', $value); @@ -350,9 +342,7 @@ public static function headersWithContinuation(): array ]; } - /** - * @dataProvider headersWithContinuation - */ + #[DataProvider('headersWithContinuation')] public function testWithHeaderNormalizesContinuationToNotContainNewlines(string $value): void { $message = $this->message->withHeader('X-Foo-Bar', $value); @@ -373,12 +363,12 @@ public static function numericHeaderValuesProvider(): array } /** - * @dataProvider numericHeaderValuesProvider - * @group 99 * @psalm-suppress InvalidArgument this test * explicitly verifies that pre-type-declaration implicit type * conversion semantics still apply, for BC Compliance */ + #[DataProvider('numericHeaderValuesProvider')] + #[Group('99')] public function testWithHeaderShouldAllowIntegersAndFloats(float $value): void { $message = $this->message @@ -410,10 +400,8 @@ public static function invalidArrayHeaderValues(): array return $values; } - /** - * @dataProvider invalidArrayHeaderValues - * @group 99 - */ + #[DataProvider('invalidArrayHeaderValues')] + #[Group('99')] public function testWithHeaderShouldRaiseExceptionForInvalidHeaderValuesInArrays(mixed $value): void { $this->expectException(InvalidArgumentException::class); @@ -423,10 +411,8 @@ public function testWithHeaderShouldRaiseExceptionForInvalidHeaderValuesInArrays $this->message->withHeader('X-Test-Array', [$value]); } - /** - * @dataProvider invalidHeaderValueTypes - * @group 99 - */ + #[DataProvider('invalidHeaderValueTypes')] + #[Group('99')] public function testWithHeaderShouldRaiseExceptionForInvalidHeaderScalarValues(mixed $value): void { $this->expectException(InvalidArgumentException::class); diff --git a/test/RelativeStreamTest.php b/test/RelativeStreamTest.php index 4802a4f4..db31dc15 100644 --- a/test/RelativeStreamTest.php +++ b/test/RelativeStreamTest.php @@ -6,14 +6,13 @@ use Laminas\Diactoros\RelativeStream; use Laminas\Diactoros\Stream; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RuntimeException; use const SEEK_SET; -/** - * @covers \Laminas\Diactoros\RelativeStream - */ +#[CoversClass(RelativeStream::class)] class RelativeStreamTest extends TestCase { public function testToString(): void diff --git a/test/Request/SerializerTest.php b/test/Request/SerializerTest.php index aa5a0e5d..d4ee45f8 100644 --- a/test/Request/SerializerTest.php +++ b/test/Request/SerializerTest.php @@ -10,6 +10,7 @@ use Laminas\Diactoros\Request\Serializer; use Laminas\Diactoros\Stream; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; @@ -83,11 +84,11 @@ public static function originForms(): array } /** - * @dataProvider originForms * @param non-empty-string $line * @param non-empty-string $requestTarget * @param array $expectations */ + #[DataProvider('originForms')] public function testCanDeserializeRequestWithOriginForm( string $line, string $requestTarget, @@ -172,11 +173,11 @@ public static function absoluteForms(): array // @codingStandardsIgnoreStart if we split these line, phpcs can't associate parameter name and docblock anymore (phpcs limitation) /** - * @dataProvider absoluteForms * @param non-empty-string $line * @param non-empty-string $requestTarget * @param array{getScheme?: non-empty-string, getUserInfo?: non-empty-string, getHost?: non-empty-string, getPort?: positive-int, getPath?: non-empty-string, getQuery?: non-empty-string} $expectations */ + #[DataProvider('absoluteForms')] public function testCanDeserializeRequestWithAbsoluteForm( string $line, string $requestTarget, @@ -234,9 +235,9 @@ public static function invalidRequestLines(): array } /** - * @dataProvider invalidRequestLines * @param non-empty-string $line */ + #[DataProvider('invalidRequestLines')] public function testRaisesExceptionDuringDeserializationForInvalidRequestLine(string $line): void { $message = $line . "\r\nX-Foo-Bar: Baz\r\n\r\nContent"; @@ -269,9 +270,9 @@ public static function headersWithContinuationLines(): array } /** - * @dataProvider headersWithContinuationLines * @param non-empty-string $text */ + #[DataProvider('headersWithContinuationLines')] public function testCanDeserializeRequestWithHeaderContinuations(string $text): void { $request = Serializer::fromString($text); @@ -295,9 +296,7 @@ public static function headersWithWhitespace(): array ]; } - /** - * @dataProvider headersWithWhitespace - */ + #[DataProvider('headersWithWhitespace')] public function testDeserializationRemovesWhitespaceAroundValues(string $text): void { $request = Serializer::fromString($text); @@ -327,10 +326,10 @@ public static function messagesWithInvalidHeaders(): array } /** - * @dataProvider messagesWithInvalidHeaders * @param non-empty-string $message * @param non-empty-string $exceptionMessage */ + #[DataProvider('messagesWithInvalidHeaders')] public function testDeserializationRaisesExceptionForMalformedHeaders( string $message, string $exceptionMessage diff --git a/test/RequestTest.php b/test/RequestTest.php index 2b957019..c5432fc8 100644 --- a/test/RequestTest.php +++ b/test/RequestTest.php @@ -8,6 +8,8 @@ use Laminas\Diactoros\Request; use Laminas\Diactoros\Stream; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; @@ -41,9 +43,7 @@ public static function invalidMethod(): array ]; } - /** - * @dataProvider invalidMethod - */ + #[DataProvider('invalidMethod')] public function testWithInvalidMethod(mixed $method): void { $this->expectException(InvalidArgumentException::class); @@ -116,9 +116,9 @@ public static function invalidRequestMethod(): array } /** - * @dataProvider invalidRequestMethod * @param non-empty-string $method */ + #[DataProvider('invalidRequestMethod')] public function testConstructorRaisesExceptionForInvalidMethod(string $method): void { $this->expectException(InvalidArgumentException::class); @@ -146,10 +146,10 @@ public static function customRequestMethods(): array } /** - * @dataProvider customRequestMethods - * @group 29 * @param non-empty-string $method */ + #[DataProvider('customRequestMethods')] + #[Group('29')] public function testAllowsCustomRequestMethodsThatFollowSpec(string $method): void { $request = new Request(null, $method); @@ -169,9 +169,7 @@ public static function invalidRequestBody(): array ]; } - /** - * @dataProvider invalidRequestBody - */ + #[DataProvider('invalidRequestBody')] public function testConstructorRaisesExceptionForInvalidBody(mixed $body): void { $this->expectException(InvalidArgumentException::class); @@ -194,10 +192,10 @@ public static function invalidHeaderTypes(): array } /** - * @dataProvider invalidHeaderTypes - * @group 99 * @param non-empty-string $contains */ + #[DataProvider('invalidHeaderTypes')] + #[Group('99')] public function testConstructorRaisesExceptionForInvalidHeaders( mixed $headers, string $contains = 'header value type' @@ -253,9 +251,9 @@ public static function requestsWithUri(): array } /** - * @dataProvider requestsWithUri * @param non-empty-string $expected */ + #[DataProvider('requestsWithUri')] public function testReturnsRequestTargetWhenUriIsPresent(RequestInterface $request, string $expected): void { $this->assertSame($expected, $request->getRequestTarget()); @@ -275,9 +273,9 @@ public static function validRequestTargets(): array } /** - * @dataProvider validRequestTargets * @param non-empty-string $requestTarget */ + #[DataProvider('validRequestTargets')] public function testCanProvideARequestTarget(string $requestTarget): void { $request = (new Request())->withRequestTarget($requestTarget); @@ -310,9 +308,7 @@ public function testSettingNewUriResetsRequestTarget(): void $this->assertNotSame($request->getRequestTarget(), $newRequest->getRequestTarget()); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHeadersContainsHostHeaderIfUriWithHostIsPresent(): void { $request = new Request('http://example.com'); @@ -321,9 +317,7 @@ public function testGetHeadersContainsHostHeaderIfUriWithHostIsPresent(): void $this->assertStringContainsString('example.com', $headers['Host'][0]); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHeadersContainsHostHeaderIfUriWithHostIsDeleted(): void { $request = (new Request('http://example.com'))->withoutHeader('host'); @@ -332,9 +326,7 @@ public function testGetHeadersContainsHostHeaderIfUriWithHostIsDeleted(): void $this->assertContains('example.com', $headers['Host']); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHeadersContainsNoHostHeaderIfNoUriPresent(): void { $request = new Request(); @@ -342,9 +334,7 @@ public function testGetHeadersContainsNoHostHeaderIfNoUriPresent(): void $this->assertArrayNotHasKey('Host', $headers); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHeadersContainsNoHostHeaderIfUriDoesNotContainHost(): void { $request = new Request(new Uri()); @@ -352,9 +342,7 @@ public function testGetHeadersContainsNoHostHeaderIfUriDoesNotContainHost(): voi $this->assertArrayNotHasKey('Host', $headers); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderReturnsUriHostWhenPresent(): void { $request = new Request('http://example.com'); @@ -362,9 +350,7 @@ public function testGetHostHeaderReturnsUriHostWhenPresent(): void $this->assertSame(['example.com'], $header); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderReturnsUriHostWhenHostHeaderDeleted(): void { $request = (new Request('http://example.com'))->withoutHeader('host'); @@ -372,27 +358,21 @@ public function testGetHostHeaderReturnsUriHostWhenHostHeaderDeleted(): void $this->assertSame(['example.com'], $header); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderReturnsEmptyArrayIfNoUriPresent(): void { $request = new Request(); $this->assertSame([], $request->getHeader('host')); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderReturnsEmptyArrayIfUriDoesNotContainHost(): void { $request = new Request(new Uri()); $this->assertSame([], $request->getHeader('host')); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderLineReturnsUriHostWhenPresent(): void { $request = new Request('http://example.com'); @@ -400,18 +380,14 @@ public function testGetHostHeaderLineReturnsUriHostWhenPresent(): void $this->assertStringContainsString('example.com', $header); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderLineReturnsEmptyStringIfNoUriPresent(): void { $request = new Request(); $this->assertEmpty($request->getHeaderLine('host')); } - /** - * @group 39 - */ + #[Group('39')] public function testGetHostHeaderLineReturnsEmptyStringIfUriDoesNotContainHost(): void { $request = new Request(new Uri()); @@ -486,10 +462,10 @@ public static function headersWithInjectionVectors(): array } /** - * @dataProvider headersWithInjectionVectors * @param non-empty-string $name * @param non-empty-string|array{non-empty-string} $value */ + #[DataProvider('headersWithInjectionVectors')] public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $name, $value): void { $this->expectException(InvalidArgumentException::class); @@ -521,9 +497,9 @@ public static function hostHeaderKeys(): array } /** - * @dataProvider hostHeaderKeys * @param non-empty-string $hostKey */ + #[DataProvider('hostHeaderKeys')] public function testWithUriAndNoPreserveHostWillOverwriteHostHeaderRegardlessOfOriginalCase(string $hostKey): void { $request = (new Request()) diff --git a/test/Response/HtmlResponseTest.php b/test/Response/HtmlResponseTest.php index c5f72d1e..3e414698 100644 --- a/test/Response/HtmlResponseTest.php +++ b/test/Response/HtmlResponseTest.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Laminas\Diactoros\Response\HtmlResponse; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Message\StreamInterface; @@ -68,9 +69,7 @@ public static function invalidHtmlContent(): array ]; } - /** - * @dataProvider invalidHtmlContent - */ + #[DataProvider('invalidHtmlContent')] public function testRaisesExceptionForNonStringNonStreamBodyContent(mixed $body): void { $this->expectException(InvalidArgumentException::class); diff --git a/test/Response/JsonResponseTest.php b/test/Response/JsonResponseTest.php index dd129dcc..a59f3435 100644 --- a/test/Response/JsonResponseTest.php +++ b/test/Response/JsonResponseTest.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Laminas\Diactoros\Response\JsonResponse; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; @@ -57,9 +58,7 @@ public static function scalarValuesForJSON() ]; } - /** - * @dataProvider scalarValuesForJSON - */ + #[DataProvider('scalarValuesForJSON')] public function testScalarValuePassedToConstructorJsonEncodesDirectly(mixed $value): void { $response = new JsonResponse($value); @@ -131,10 +130,10 @@ public static function valuesToJsonEncode(): array } /** - * @dataProvider valuesToJsonEncode * @param non-empty-string $value * @param non-empty-string $key */ + #[DataProvider('valuesToJsonEncode')] public function testUsesSaneDefaultJsonEncodingFlags(string $value, string $key): void { $defaultFlags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_SLASHES; diff --git a/test/Response/RedirectResponseTest.php b/test/Response/RedirectResponseTest.php index 115d89a8..151c03db 100644 --- a/test/Response/RedirectResponseTest.php +++ b/test/Response/RedirectResponseTest.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use Laminas\Diactoros\Response\RedirectResponse; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class RedirectResponseTest extends TestCase @@ -62,9 +63,7 @@ public static function invalidUris(): array ]; } - /** - * @dataProvider invalidUris - */ + #[DataProvider('invalidUris')] public function testConstructorRaisesExceptionOnInvalidUri(mixed $uri): void { $this->expectException(InvalidArgumentException::class); diff --git a/test/Response/SerializerTest.php b/test/Response/SerializerTest.php index a9a2cfcd..ab56e1ea 100644 --- a/test/Response/SerializerTest.php +++ b/test/Response/SerializerTest.php @@ -7,6 +7,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Response; use Laminas\Diactoros\Response\Serializer; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -109,9 +111,9 @@ public static function headersWithContinuationLines(): array } /** - * @dataProvider headersWithContinuationLines * @param non-empty-string $text */ + #[DataProvider('headersWithContinuationLines')] public function testCanDeserializeResponseWithHeaderContinuations(string $text): void { $response = Serializer::fromString($text); @@ -135,9 +137,7 @@ public static function headersWithWhitespace(): array ]; } - /** - * @dataProvider headersWithWhitespace - */ + #[DataProvider('headersWithWhitespace')] public function testDeserializationRemovesWhitespaceAroundValues(string $text): void { $response = Serializer::fromString($text); @@ -218,10 +218,10 @@ public static function messagesWithInvalidHeaders(): array } /** - * @dataProvider messagesWithInvalidHeaders * @param non-empty-string $message * @param non-empty-string $exceptionMessage */ + #[DataProvider('messagesWithInvalidHeaders')] public function testDeserializationRaisesExceptionForMalformedHeaders( string $message, string $exceptionMessage @@ -262,9 +262,7 @@ public function testFromStreamThrowsExceptionWhenStreamIsNotSeekable(): void Serializer::fromStream($stream); } - /** - * @group 113 - */ + #[Group('113')] public function testDeserializeCorrectlyCastsStatusCodeToInteger(): void { $response = Response\Serializer::fromString('HTTP/1.0 204'); diff --git a/test/Response/TextResponseTest.php b/test/Response/TextResponseTest.php index ffbd5ee4..6fa0a6f7 100644 --- a/test/Response/TextResponseTest.php +++ b/test/Response/TextResponseTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Response\TextResponse; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\StreamInterface; @@ -68,9 +70,7 @@ public static function invalidContent(): array ]; } - /** - * @dataProvider invalidContent - */ + #[DataProvider('invalidContent')] public function testRaisesExceptionForNonStringNonStreamBodyContent(mixed $body): void { $this->expectException(InvalidArgumentException::class); @@ -79,9 +79,7 @@ public function testRaisesExceptionForNonStringNonStreamBodyContent(mixed $body) new TextResponse($body); } - /** - * @group 115 - */ + #[Group('115')] public function testConstructorRewindsBodyStream(): void { $text = 'test data'; diff --git a/test/Response/XmlResponseTest.php b/test/Response/XmlResponseTest.php index d39c7a14..84556e38 100644 --- a/test/Response/XmlResponseTest.php +++ b/test/Response/XmlResponseTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Response\XmlResponse; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Http\Message\StreamInterface; @@ -70,9 +72,7 @@ public static function invalidContent(): array ]; } - /** - * @dataProvider invalidContent - */ + #[DataProvider('invalidContent')] public function testRaisesExceptionforNonStringNonStreamBodyContent(mixed $body): void { $this->expectException(InvalidArgumentException::class); @@ -81,9 +81,7 @@ public function testRaisesExceptionforNonStringNonStreamBodyContent(mixed $body) new XmlResponse($body); } - /** - * @group 115 - */ + #[Group('115')] public function testConstructorRewindsBodyStream(): void { $body = '' . PHP_EOL . 'Valid XML'; diff --git a/test/ResponseTest.php b/test/ResponseTest.php index 1ed1da1a..1b09ce69 100644 --- a/test/ResponseTest.php +++ b/test/ResponseTest.php @@ -9,6 +9,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Response; use Laminas\Diactoros\Stream; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function curl_close; @@ -168,9 +170,9 @@ public static function ianaCodesReasonPhrasesProvider(): array } /** - * @dataProvider ianaCodesReasonPhrasesProvider * @param non-empty-string $reasonPhrase */ + #[DataProvider('ianaCodesReasonPhrasesProvider')] public function testReasonPhraseDefaultsAgainstIana(int $code, string $reasonPhrase): void { $response = $this->response->withStatus($code); @@ -205,9 +207,7 @@ public function testConstructorCanAcceptAllMessageParts(): void $this->assertSame($headers, $response->getHeaders()); } - /** - * @dataProvider validStatusCodes - */ + #[DataProvider('validStatusCodes')] public function testCreateWithValidStatusCodes(int $code): void { $response = $this->response->withStatus($code); @@ -227,9 +227,7 @@ public static function validStatusCodes(): array ]; } - /** - * @dataProvider invalidStatusCodes - */ + #[DataProvider('invalidStatusCodes')] public function testCannotSetInvalidStatusCode(mixed $code): void { $this->expectException(InvalidArgumentException::class); @@ -260,9 +258,7 @@ public static function invalidResponseBody(): array ]; } - /** - * @dataProvider invalidResponseBody - */ + #[DataProvider('invalidResponseBody')] public function testConstructorRaisesExceptionForInvalidBody(mixed $body): void { $this->expectException(InvalidArgumentException::class); @@ -285,11 +281,11 @@ public static function invalidHeaderTypes(): array } /** - * @dataProvider invalidHeaderTypes - * @group 99 * @param array $headers * @param non-empty-string $contains */ + #[DataProvider('invalidHeaderTypes')] + #[Group('99')] public function testConstructorRaisesExceptionForInvalidHeaders( array $headers, string $contains = 'header value type' @@ -327,9 +323,9 @@ public static function headersWithInjectionVectors(): array } /** - * @dataProvider headersWithInjectionVectors * @param string|non-empty-list $value */ + #[DataProvider('headersWithInjectionVectors')] public function testConstructorRaisesExceptionForHeadersWithCRLFVectors(string $name, $value): void { $this->expectException(InvalidArgumentException::class); diff --git a/test/ServerRequestFactoryTest.php b/test/ServerRequestFactoryTest.php index 16deca70..eaf00204 100644 --- a/test/ServerRequestFactoryTest.php +++ b/test/ServerRequestFactoryTest.php @@ -9,6 +9,11 @@ use Laminas\Diactoros\ServerRequestFilter\DoNotFilter; use Laminas\Diactoros\ServerRequestFilter\FilterServerRequestInterface; use Laminas\Diactoros\UploadedFile; +use PHPUnit\Framework\Attributes\BackupGlobals; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\PreserveGlobalState; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use UnexpectedValueException; @@ -19,9 +24,7 @@ use function Laminas\Diactoros\normalizeUploadedFiles; use function str_replace; -/** - * @backupGlobals enabled - */ +#[BackupGlobals(true)] final class ServerRequestFactoryTest extends TestCase { public function testReturnsServerValueUnchangedIfHttpAuthorizationHeaderIsPresent(): void @@ -190,10 +193,8 @@ public function testFromGlobalsUsesCookieHeaderInsteadOfCookieSuperGlobal(): voi $this->assertSame(['foo_bar' => 'baz'], $request->getCookieParams()); } - /** - * @runInSeparateProcess - * @preserveGlobalState - */ + #[PreserveGlobalState(true)] + #[RunInSeparateProcess] public function testCreateFromGlobalsShouldPreserveKeysWhenCreatedWithAZeroValue(): void { $_SERVER['HTTP_ACCEPT'] = '0'; @@ -204,10 +205,8 @@ public function testCreateFromGlobalsShouldPreserveKeysWhenCreatedWithAZeroValue $this->assertSame('0', $request->getHeaderLine('content-length')); } - /** - * @runInSeparateProcess - * @preserveGlobalState - */ + #[PreserveGlobalState(true)] + #[RunInSeparateProcess] public function testCreateFromGlobalsShouldNotPreserveKeysWhenCreatedWithAnEmptyValue(): void { $_SERVER['HTTP_ACCEPT'] = ''; @@ -219,10 +218,8 @@ public function testCreateFromGlobalsShouldNotPreserveKeysWhenCreatedWithAnEmpty $this->assertFalse($request->hasHeader('content-length')); } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - */ + #[PreserveGlobalState(false)] + #[RunInSeparateProcess] public function testFromGlobalsUsesCookieSuperGlobalWhenCookieHeaderIsNotSet(): void { $_COOKIE = [ @@ -265,10 +262,10 @@ public static function cookieHeaderValues(): array } /** - * @dataProvider cookieHeaderValues * @param non-empty-string $cookieHeader * @param array $expectedCookies */ + #[DataProvider('cookieHeaderValues')] public function testCookieHeaderVariations(string $cookieHeader, array $expectedCookies): void { $_SERVER['HTTP_COOKIE'] = $cookieHeader; @@ -302,10 +299,8 @@ public function testNormalizeServerReturnsArrayUnalteredIfApacheHeadersDoNotCont $this->assertSame($expected, $server); } - /** - * @group 57 - * @group 56 - */ + #[Group('57')] + #[Group('56')] public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContainsNestedAssociativeArrays(): void { $files = [ @@ -336,10 +331,10 @@ public function testMarshalProtocolReturnsDefaultValueIfHeaderIsNotPresent(): vo } /** - * @dataProvider marshalProtocolVersionProvider * @param non-empty-string $protocol * @param non-empty-string $expected */ + #[DataProvider('marshalProtocolVersionProvider')] public function testMarshalProtocolVersionReturnsHttpVersions(string $protocol, string $expected): void { $version = marshalProtocolVersionFromSapi(['SERVER_PROTOCOL' => $protocol]); @@ -451,9 +446,9 @@ public static function serverContentMap(): iterable } /** - * @dataProvider serverContentMap * @psalm-param array $server */ + #[DataProvider('serverContentMap')] public function testDoesNotMarshalAllContentPrefixedServerVarsAsHeaders( array $server, string $key, @@ -540,9 +535,7 @@ public static function invalidHostHeaders(): iterable ]; } - /** - * @dataProvider invalidHostHeaders - */ + #[DataProvider('invalidHostHeaders')] public function testRejectsDuplicatedHostHeader(string $host): void { $server = [ diff --git a/test/ServerRequestFilter/FilterUsingXForwardedHeadersTest.php b/test/ServerRequestFilter/FilterUsingXForwardedHeadersTest.php index b06f35fa..604199ad 100644 --- a/test/ServerRequestFilter/FilterUsingXForwardedHeadersTest.php +++ b/test/ServerRequestFilter/FilterUsingXForwardedHeadersTest.php @@ -8,6 +8,7 @@ use Laminas\Diactoros\Exception\InvalidProxyAddressException; use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\ServerRequestFilter\FilterUsingXForwardedHeaders; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FilterUsingXForwardedHeadersTest extends TestCase @@ -97,7 +98,7 @@ public static function trustedProxyList(): iterable yield 'private-class-c-subnet' => ['192.168.1.1']; } - /** @dataProvider trustedProxyList */ + #[DataProvider('trustedProxyList')] public function testTrustingProxyListWithoutExplicitTrustedHeadersTrustsAllForwardedRequestsForTrustedProxies( string $remoteAddr ): void { @@ -125,7 +126,7 @@ public function testTrustingProxyListWithoutExplicitTrustedHeadersTrustsAllForwa $this->assertSame('https', $filteredUri->getScheme()); } - /** @dataProvider trustedProxyList */ + #[DataProvider('trustedProxyList')] public function testTrustingProxyListWithSpecificTrustedHeadersTrustsOnlyThoseHeaders(string $remoteAddr): void { $request = new ServerRequest( @@ -162,7 +163,7 @@ public static function untrustedProxyList(): iterable yield 'private-class-c-subnet' => ['192.168.168.1']; } - /** @dataProvider untrustedProxyList */ + #[DataProvider('untrustedProxyList')] public function testFilterDoesNothingWhenAddressNotInTrustedProxyList(string $remoteAddr): void { $request = new ServerRequest( @@ -268,7 +269,7 @@ public static function trustedReservedNetworkList(): iterable yield 'ipv6-local-link' => ['fe80:0000:0000:0000:abcd:abcd:abcd:abcd']; } - /** @dataProvider trustedReservedNetworkList */ + #[DataProvider('trustedReservedNetworkList')] public function testTrustReservedSubnetsProducesFilterThatAcceptsAddressesFromThoseSubnets( string $remoteAddr ): void { @@ -308,7 +309,7 @@ public static function unreservedNetworkAddressList(): iterable yield 'ipv6-not-local-link' => ['ef80:0000:0000:0000:abcd:abcd:abcd:abcd']; } - /** @dataProvider unreservedNetworkAddressList */ + #[DataProvider('unreservedNetworkAddressList')] public function testTrustReservedSubnetsProducesFilterThatRejectsAddressesNotFromThoseSubnets( string $remoteAddr ): void { @@ -345,7 +346,7 @@ public static function xForwardedProtoValues(): iterable yield 'empty' => ['', 'http']; } - /** @dataProvider xForwardedProtoValues */ + #[DataProvider('xForwardedProtoValues')] public function testOnlyHonorsXForwardedProtoIfValueResolvesToHTTPS( string $xForwarededProto, string $expectedScheme diff --git a/test/ServerRequestFilter/IPRangeTest.php b/test/ServerRequestFilter/IPRangeTest.php index 928e0607..2f22271c 100644 --- a/test/ServerRequestFilter/IPRangeTest.php +++ b/test/ServerRequestFilter/IPRangeTest.php @@ -5,6 +5,7 @@ namespace LaminasTest\Diactoros\ServerRequestFilter; use Laminas\Diactoros\ServerRequestFilter\IPRange; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IPRangeTest extends TestCase @@ -35,9 +36,7 @@ public static function IPv4Data(): array ]; } - /** - * @dataProvider IPv4Data - */ + #[DataProvider('IPv4Data')] public function testIPv4(bool $result, string $remoteAddr, string $cidr): void { $this->assertSame($result, IPRange::matchesIPv4($remoteAddr, $cidr)); @@ -68,9 +67,7 @@ public static function IPv6Data(): array // @codingStandardsIgnoreEnd } - /** - * @dataProvider IPv6Data - */ + #[DataProvider('IPv6Data')] public function testIPv6(bool $result, string $remoteAddr, string $cidr): void { $this->assertSame($result, IPRange::matchesIPv6($remoteAddr, $cidr)); @@ -96,7 +93,7 @@ public static function combinedData(): iterable } } - /** @dataProvider combinedData */ + #[DataProvider('combinedData')] public function testCombinedIPv4AndIPv6Pool(bool $result, string $remoteAddr, string $cidr): void { $this->assertSame($result, IPRange::matches($remoteAddr, $cidr)); diff --git a/test/ServerRequestTest.php b/test/ServerRequestTest.php index 26976a9c..447fd81a 100644 --- a/test/ServerRequestTest.php +++ b/test/ServerRequestTest.php @@ -8,6 +8,9 @@ use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\UploadedFile; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -79,9 +82,7 @@ public function testSingleAttributesWhenEmptyByDefault(): void $this->assertEmpty($this->request->getAttribute('does-not-exist')); } - /** - * @depends testAttributesAreEmptyByDefault - */ + #[Depends('testAttributesAreEmptyByDefault')] public function testAttributeMutatorReturnsCloneWithChanges(): ServerRequest { $request = $this->request->withAttribute('foo', 'bar'); @@ -90,9 +91,7 @@ public function testAttributeMutatorReturnsCloneWithChanges(): ServerRequest return $request; } - /** - * @depends testAttributeMutatorReturnsCloneWithChanges - */ + #[Depends('testAttributeMutatorReturnsCloneWithChanges')] public function testRemovingAttributeReturnsCloneWithoutAttribute(ServerRequest $request): void { $new = $request->withoutAttribute('foo'); @@ -111,10 +110,10 @@ public static function provideMethods(): array } /** - * @dataProvider provideMethods * @param non-empty-string|null $parameterMethod * @param non-empty-string $methodReturned */ + #[DataProvider('provideMethods')] public function testUsesProvidedConstructorArguments(?string $parameterMethod, string $methodReturned): void { $server = [ @@ -171,9 +170,7 @@ public function testUsesProvidedConstructorArguments(?string $parameterMethod, s $this->assertSame('php://memory', $stream); } - /** - * @group 46 - */ + #[Group('46')] public function testCookieParamsAreAnEmptyArrayAtInitialization(): void { $request = new ServerRequest(); @@ -181,9 +178,7 @@ public function testCookieParamsAreAnEmptyArrayAtInitialization(): void $this->assertCount(0, $request->getCookieParams()); } - /** - * @group 46 - */ + #[Group('46')] public function testQueryParamsAreAnEmptyArrayAtInitialization(): void { $request = new ServerRequest(); @@ -191,9 +186,7 @@ public function testQueryParamsAreAnEmptyArrayAtInitialization(): void $this->assertCount(0, $request->getQueryParams()); } - /** - * @group 46 - */ + #[Group('46')] public function testParsedBodyIsNullAtInitialization(): void { $request = new ServerRequest(); diff --git a/test/StreamTest.php b/test/StreamTest.php index ab73feb8..4802f934 100644 --- a/test/StreamTest.php +++ b/test/StreamTest.php @@ -10,6 +10,7 @@ use Laminas\Diactoros\Exception\InvalidArgumentException as DiactorosInvalidArgumentException; use Laminas\Diactoros\Stream; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use ReflectionProperty; use RuntimeException; @@ -169,9 +170,7 @@ public function testCloseDoesNothingAfterDetach(): void $this->assertSame($resource, $detached); } - /** - * @group 42 - */ + #[Group('42')] public function testSizeReportsNullWhenNoResourcePresent(): void { $this->stream->detach(); @@ -629,9 +628,7 @@ public function testGetMetadataReturnsNullIfNoDataExistsForKey(): void $this->assertNull($this->stream->getMetadata('TOTALLY_MADE_UP')); } - /** - * @group 42 - */ + #[Group('42')] public function testGetSizeReturnsStreamSize(): void { $resource = fopen(__FILE__, 'r'); @@ -640,9 +637,7 @@ public function testGetSizeReturnsStreamSize(): void $this->assertSame($expected['size'], $stream->getSize()); } - /** - * @group 67 - */ + #[Group('67')] public function testRaisesExceptionOnConstructionForNonStreamResources(): void { $resource = $this->getResourceFor67(); @@ -656,9 +651,7 @@ public function testRaisesExceptionOnConstructionForNonStreamResources(): void new Stream($resource); } - /** - * @group 67 - */ + #[Group('67')] public function testRaisesExceptionOnAttachForNonStreamResources(): void { $resource = $this->getResourceFor67(); @@ -709,9 +702,7 @@ public function testCanReadContentFromNotSeekableResource(): void $this->assertSame('FOO BAR', $stream->__toString()); } - /** - * @group 42 - */ + #[Group('42')] public function testSizeReportsNullForPhpInputStreams(): void { $resource = fopen('php://input', 'r'); diff --git a/test/UploadedFileTest.php b/test/UploadedFileTest.php index fd4b8d18..2b1d7bdd 100644 --- a/test/UploadedFileTest.php +++ b/test/UploadedFileTest.php @@ -7,6 +7,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Stream; use Laminas\Diactoros\UploadedFile; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use ReflectionProperty; use RuntimeException; @@ -74,9 +76,7 @@ public static function invalidStreams(): array ]; } - /** - * @dataProvider invalidStreams - */ + #[DataProvider('invalidStreams')] public function testRaisesExceptionOnInvalidStreamOrFile(mixed $streamOrFile): void { $this->expectException(InvalidArgumentException::class); @@ -100,9 +100,7 @@ public static function invalidErrorStatuses(): array ]; } - /** - * @dataProvider invalidErrorStatuses - */ + #[DataProvider('invalidErrorStatuses')] public function testRaisesExceptionOnInvalidErrorStatus(int $status): void { $this->expectException(InvalidArgumentException::class); @@ -175,9 +173,7 @@ public static function invalidMovePaths(): array ]; } - /** - * @dataProvider invalidMovePaths - */ + #[DataProvider('invalidMovePaths')] public function testMoveRaisesExceptionForInvalidPath(mixed $path): void { $stream = new Stream('php://temp', 'wb+'); @@ -238,20 +234,16 @@ public static function nonOkErrorStatus(): array ]; } - /** - * @dataProvider nonOkErrorStatus - * @group 60 - */ + #[DataProvider('nonOkErrorStatus')] + #[Group('60')] public function testConstructorDoesNotRaiseExceptionForInvalidStreamWhenErrorStatusPresent(int $status): void { $uploadedFile = new UploadedFile('not ok', 0, $status); $this->assertSame($status, $uploadedFile->getError()); } - /** - * @dataProvider nonOkErrorStatus - * @group 60 - */ + #[DataProvider('nonOkErrorStatus')] + #[Group('60')] public function testMoveToRaisesExceptionWhenErrorStatusPresent(int $status): void { $uploadedFile = new UploadedFile('not ok', 0, $status); @@ -262,10 +254,8 @@ public function testMoveToRaisesExceptionWhenErrorStatusPresent(int $status): vo $uploadedFile->moveTo(__DIR__ . '/' . uniqid()); } - /** - * @dataProvider nonOkErrorStatus - * @group 60 - */ + #[DataProvider('nonOkErrorStatus')] + #[Group('60')] public function testGetStreamRaisesExceptionWhenErrorStatusPresent(int $status): void { $uploadedFile = new UploadedFile('not ok', 0, $status); @@ -276,9 +266,7 @@ public function testGetStreamRaisesExceptionWhenErrorStatusPresent(int $status): $uploadedFile->getStream(); } - /** - * @group 82 - */ + #[Group('82')] public function testMoveToCreatesStreamIfOnlyAFilenameWasProvided(): void { $this->orgFile = tempnam(sys_get_temp_dir(), 'ORG'); @@ -306,7 +294,7 @@ public static function errorConstantsAndMessages(): iterable } } - /** @dataProvider errorConstantsAndMessages */ + #[DataProvider('errorConstantsAndMessages')] public function testGetStreamRaisesExceptionWithAppropriateMessageWhenUploadErrorDetected( int $constant, string $message @@ -317,9 +305,7 @@ public function testGetStreamRaisesExceptionWithAppropriateMessageWhenUploadErro $uploadedFile->getStream(); } - /** - * @dataProvider errorConstantsAndMessages - */ + #[DataProvider('errorConstantsAndMessages')] public function testMoveToRaisesExceptionWithAppropriateMessageWhenUploadErrorDetected( int $constant, string $message diff --git a/test/UriFactoryTest.php b/test/UriFactoryTest.php index d6be9f8f..2468dc64 100644 --- a/test/UriFactoryTest.php +++ b/test/UriFactoryTest.php @@ -6,6 +6,7 @@ use Laminas\Diactoros\Uri; use Laminas\Diactoros\UriFactory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function array_shift; @@ -161,9 +162,9 @@ public static function httpsParamProvider(): array } /** - * @dataProvider httpsParamProvider * @param non-empty-string $param */ + #[DataProvider('httpsParamProvider')] public function testMarshalUriDetectsHttpsSchemeFromServerValue(string $param): void { $server = [ @@ -191,10 +192,10 @@ public static function httpsDisableParamProvider(): iterable } /** - * @dataProvider httpsDisableParamProvider * @param non-empty-string $param * @param 'off'|'OFF' $value */ + #[DataProvider('httpsDisableParamProvider')] public function testMarshalUriUsesHttpSchemeIfHttpsServerValueEqualsOff(string $param, string $value): void { $server = [ diff --git a/test/UriTest.php b/test/UriTest.php index 04df4df0..51515d62 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Laminas\Diactoros\Uri; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use ReflectionObject; @@ -95,11 +97,11 @@ public static function userInfoProvider(): array } /** - * @dataProvider userInfoProvider * @param non-empty-string $user * @param non-empty-string $credential * @param non-empty-string $expected */ + #[DataProvider('userInfoProvider')] public function testWithUserInfoEncodesUsernameAndPassword(string $user, string $credential, string $expected): void { $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); @@ -136,9 +138,9 @@ public static function validPorts(): array } /** - * @dataProvider validPorts * @param null|positive-int|numeric-string $port */ + #[DataProvider('validPorts')] public function testWithPortReturnsNewInstanceWithProvidedPort($port): void { $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); @@ -170,9 +172,7 @@ public static function invalidPorts(): array ]; } - /** - * @dataProvider invalidPorts - */ + #[DataProvider('invalidPorts')] public function testWithPortRaisesExceptionForInvalidPorts(mixed $port): void { $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); @@ -211,9 +211,7 @@ public static function invalidPaths(): array ]; } - /** - * @dataProvider invalidPaths - */ + #[DataProvider('invalidPaths')] public function testWithPathRaisesExceptionForInvalidPaths(mixed $path): void { $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); @@ -242,9 +240,7 @@ public static function invalidQueryStrings(): array ]; } - /** - * @dataProvider invalidQueryStrings - */ + #[DataProvider('invalidQueryStrings')] public function testWithQueryRaisesExceptionForInvalidQueryStrings(mixed $query): void { $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz'); @@ -286,10 +282,10 @@ public static function authorityInfo(): array } /** - * @dataProvider authorityInfo * @param non-empty-string $url * @param non-empty-string $expected */ + #[DataProvider('authorityInfo')] public function testRetrievingAuthorityReturnsExpectedValues(string $url, string $expected): void { $uri = new Uri($url); @@ -362,9 +358,9 @@ public static function invalidSchemes(): array } /** - * @dataProvider invalidSchemes * @param non-empty-string $scheme */ + #[DataProvider('invalidSchemes')] public function testConstructWithUnsupportedSchemeRaisesAnException(string $scheme): void { $this->expectException(InvalidArgumentException::class); @@ -374,9 +370,9 @@ public function testConstructWithUnsupportedSchemeRaisesAnException(string $sche } /** - * @dataProvider invalidSchemes * @param non-empty-string $scheme */ + #[DataProvider('invalidSchemes')] public function testMutatingWithUnsupportedSchemeRaisesAnException(string $scheme): void { $uri = new Uri('http://example.com'); @@ -425,10 +421,10 @@ public static function standardSchemePortCombinations(): array } /** - * @dataProvider standardSchemePortCombinations * @param non-empty-string $scheme * @param positive-int $port */ + #[DataProvider('standardSchemePortCombinations')] public function testAuthorityOmitsPortForStandardSchemePortCombinations(string $scheme, int $port): void { $uri = (new Uri()) @@ -453,10 +449,10 @@ public static function mutations(): array } /** - * @dataProvider mutations * @param 'withScheme'|'withUserInfo'|'withHost'|'withPort'|'withPath'|'withQuery'|'withFragment' $method * @param non-empty-string|positive-int $value */ + #[DataProvider('mutations')] public function testMutationResetsUriStringPropertyInClone(string $method, $value): void { $uri = new Uri('http://example.com/path?query=string#fragment'); @@ -474,9 +470,7 @@ public function testMutationResetsUriStringPropertyInClone(string $method, $valu $this->assertSame($string, $p->getValue($uri)); } - /** - * @group 40 - */ + #[Group('40')] public function testPathIsProperlyEncoded(): void { $uri = (new Uri())->withPath('/foo^bar'); @@ -504,10 +498,10 @@ public static function queryStringsForEncoding(): array } /** - * @dataProvider queryStringsForEncoding * @param non-empty-string $query * @param non-empty-string $expected */ + #[DataProvider('queryStringsForEncoding')] public function testQueryIsProperlyEncoded(string $query, string $expected): void { $uri = (new Uri())->withQuery($query); @@ -515,19 +509,17 @@ public function testQueryIsProperlyEncoded(string $query, string $expected): voi } /** - * @dataProvider queryStringsForEncoding * @param non-empty-string $query * @param non-empty-string $expected */ + #[DataProvider('queryStringsForEncoding')] public function testQueryIsNotDoubleEncoded(string $query, string $expected): void { $uri = (new Uri())->withQuery($expected); $this->assertSame($expected, $uri->getQuery()); } - /** - * @group 40 - */ + #[Group('40')] public function testFragmentIsProperlyEncoded(): void { $uri = (new Uri())->withFragment('/p^th?key^=`bar#b@z'); @@ -535,9 +527,7 @@ public function testFragmentIsProperlyEncoded(): void $this->assertSame($expected, $uri->getFragment()); } - /** - * @group 40 - */ + #[Group('40')] public function testFragmentIsNotDoubleEncoded(): void { $expected = '/p%5Eth?key%5E=%60bar%23b@z'; @@ -553,10 +543,10 @@ public function testUtf8Uri(): void } /** - * @dataProvider utf8PathsDataProvider * @param non-empty-string $url * @param non-empty-string $result */ + #[DataProvider('utf8PathsDataProvider')] public function testUtf8Path(string $url, string $result): void { $uri = new Uri($url); @@ -576,10 +566,10 @@ public static function utf8PathsDataProvider(): array } /** - * @dataProvider utf8QueryStringsDataProvider * @param non-empty-string $url * @param non-empty-string $result */ + #[DataProvider('utf8QueryStringsDataProvider')] public function testUtf8Query(string $url, string $result): void { $uri = new Uri($url);