From 893a10acc9e12d6521a1230113fbae5e404ff863 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Sun, 31 May 2026 18:30:55 +0930 Subject: [PATCH] test: migrate to phpunit 11 convert test annotations to PHP attributes The XML schema is the same for PHPunit 10 and 11, so that does not need to be migrated. --- composer.json | 2 +- tests/HTTP/FunctionsTest.php | 11 +++++------ tests/HTTP/NegotiateTest.php | 5 +++-- tests/HTTP/SapiTest.php | 20 +++++++++----------- tests/HTTP/URLUtilTest.php | 17 ++++++----------- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 8d450c9..37f91e9 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-strict-rules": "^2.0", "phpstan/extension-installer": "^1.4", - "phpunit/phpunit" : "^10.5", + "phpunit/phpunit" : "^11.5", "rector/rector": "^2.4" }, "suggest" : { diff --git a/tests/HTTP/FunctionsTest.php b/tests/HTTP/FunctionsTest.php index d120911..74af10e 100644 --- a/tests/HTTP/FunctionsTest.php +++ b/tests/HTTP/FunctionsTest.php @@ -4,15 +4,16 @@ namespace Sabre\HTTP; +use PHPUnit\Framework\Attributes\DataProvider; + class FunctionsTest extends \PHPUnit\Framework\TestCase { /** - * @dataProvider getHeaderValuesDataOnValues2 - * * @param array $result * @param array $values1 * @param array $values2 */ + #[DataProvider('getHeaderValuesDataOnValues2')] public function testGetHeaderValuesOnValues2(array $result, array $values1, array $values2): void { self::assertEquals($result, getHeaderValues($values1, $values2)); @@ -38,11 +39,10 @@ public static function getHeaderValuesDataOnValues2(): array } /** - * @dataProvider getHeaderValuesData - * * @param string $input * @param array $output */ + #[DataProvider('getHeaderValuesData')] public function testGetHeaderValues($input, array $output): void { self::assertEquals( @@ -81,11 +81,10 @@ public static function getHeaderValuesData(): array } /** - * @dataProvider preferData - * * @param string $input * @param array $output */ + #[DataProvider('preferData')] public function testPrefer($input, array $output): void { self::assertEquals( diff --git a/tests/HTTP/NegotiateTest.php b/tests/HTTP/NegotiateTest.php index 639865a..1a2e069 100644 --- a/tests/HTTP/NegotiateTest.php +++ b/tests/HTTP/NegotiateTest.php @@ -4,13 +4,14 @@ namespace Sabre\HTTP; +use PHPUnit\Framework\Attributes\DataProvider; + class NegotiateTest extends \PHPUnit\Framework\TestCase { /** - * @dataProvider negotiateData - * * @param array $available */ + #[DataProvider('negotiateData')] public function testNegotiate(?string $acceptHeader, array $available, ?string $expected): void { self::assertEquals( diff --git a/tests/HTTP/SapiTest.php b/tests/HTTP/SapiTest.php index 7c77132..9eb2008 100644 --- a/tests/HTTP/SapiTest.php +++ b/tests/HTTP/SapiTest.php @@ -4,6 +4,9 @@ namespace Sabre\HTTP; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; + class SapiTest extends \PHPUnit\Framework\TestCase { public function testConstructFromServerArray(): void @@ -144,9 +147,8 @@ public function testSend(): void /** * @runInSeparateProcess - * - * @depends testSend */ + #[Depends('testSend')] public function testSendLimitedByContentLengthString(): void { $response = new Response(200); @@ -180,9 +182,8 @@ public function testRecognizeHttp2(): void /** * @runInSeparateProcess - * - * @depends testSend */ + #[Depends('testSend')] public function testSendLimitedByContentLengthStream(): void { $response = new Response(200, ['Content-Length' => 19]); @@ -205,17 +206,15 @@ public function testSendLimitedByContentLengthStream(): void /** * @runInSeparateProcess - * - * @depends testSend - * - * @dataProvider sendContentRangeStreamData */ + #[Depends('testSend')] + #[DataProvider('sendContentRangeStreamData')] public function testSendContentRangeStream( string $ignoreAtStart, string $sendText, int $multiplier, string $ignoreAtEnd, - ?int $contentLength): void + ?int $contentLength = null): void { $partial = str_repeat($sendText, $multiplier); $ignoreAtStartLength = strlen($ignoreAtStart); @@ -281,9 +280,8 @@ public static function sendContentRangeStreamData(): array /** * @runInSeparateProcess - * - * @depends testSend */ + #[Depends('testSend')] public function testSendWorksWithCallbackAsBody(): void { $response = new Response(200, [], function (): void { diff --git a/tests/HTTP/URLUtilTest.php b/tests/HTTP/URLUtilTest.php index 94f2118..0ec6564 100644 --- a/tests/HTTP/URLUtilTest.php +++ b/tests/HTTP/URLUtilTest.php @@ -4,6 +4,8 @@ namespace Sabre\HTTP; +use PHPUnit\Framework\Attributes\Depends; + class URLUtilTest extends \PHPUnit\Framework\TestCase { public function testEncodePath(): void @@ -61,9 +63,7 @@ public function testDecode(): void self::assertEquals('Hello Test+Test2.txt', $newStr); } - /** - * @depends testDecode - */ + #[Depends('testDecode')] public function testDecodeUmlaut(): void { $str = 'Hello%C3%BC.txt'; @@ -71,9 +71,7 @@ public function testDecodeUmlaut(): void self::assertEquals("Hello\xC3\xBC.txt", $newStr); } - /** - * @depends testDecode - */ + #[Depends('testDecode')] public function testDecodeSlavicWords(): void { $words = [ @@ -90,9 +88,7 @@ public function testDecodeSlavicWords(): void } } - /** - * @depends testDecodeUmlaut - */ + #[Depends('testDecodeUmlaut')] public function testDecodeUmlautLatin1(): void { $str = 'Hello%FC.txt'; @@ -102,9 +98,8 @@ public function testDecodeUmlautLatin1(): void /** * This testcase was sent by a bug reporter. - * - * @depends testDecode */ + #[Depends('testDecode')] public function testDecodeAccentsWindows7(): void { $str = '/webdav/%C3%A0fo%C3%B3';