From 459c6c7e5e8bece2605a9de91054d530ddaeaa91 Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Fri, 24 May 2024 17:34:44 -0700 Subject: [PATCH] upgrade PHPUnit to v10+ --- composer.json | 2 +- tests/unit/ArrayObjectTest.php | 23 +----- tests/unit/Coroutine/BarrierTest.php | 17 +--- tests/unit/Coroutine/FunctionTest.php | 5 ++ tests/unit/Coroutine/HttpFunctionTest.php | 3 + tests/unit/Coroutine/WaitGroupTest.php | 3 +- tests/unit/Curl/HandlerTest.php | 39 +--------- tests/unit/Database/PDOPoolTest.php | 3 +- tests/unit/Database/PDOStatementProxyTest.php | 17 +--- tests/unit/FastCGI/FrameParserTest.php | 3 +- tests/unit/FastCGI/HttpRequestTest.php | 4 +- tests/unit/FastCGI/HttpResponseTest.php | 24 ++---- .../unit/FastCGI/Record/AbortRequestTest.php | 3 +- .../unit/FastCGI/Record/BeginRequestTest.php | 3 +- tests/unit/FastCGI/Record/DataTest.php | 3 +- tests/unit/FastCGI/Record/EndRequestTest.php | 3 +- .../FastCGI/Record/GetValuesResultTest.php | 3 +- tests/unit/FastCGI/Record/GetValuesTest.php | 3 +- tests/unit/FastCGI/Record/ParamsTest.php | 3 +- tests/unit/FastCGI/Record/StderrTest.php | 3 +- tests/unit/FastCGI/Record/StdinTest.php | 3 +- tests/unit/FastCGI/Record/StdoutTest.php | 3 +- tests/unit/FastCGI/Record/UnknownTypeTest.php | 3 +- tests/unit/FastCGI/RecordTest.php | 3 +- tests/unit/FunctionTest.php | 11 +-- tests/unit/MultibyteStringObjectTest.php | 27 +------ tests/unit/NameResolverTest.php | 5 +- tests/unit/ObjectProxyTest.php | 17 ++-- tests/unit/Process/ProcessManagerTest.php | 17 +--- tests/unit/StringObjectTest.php | 78 +------------------ 30 files changed, 80 insertions(+), 254 deletions(-) diff --git a/composer.json b/composer.json index a1e2a54c..6e7e1447 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ext-json": "*", "ext-redis": "*", "ext-curl": "*", - "phpunit/phpunit": "~9.0 || ~10.0 || ~11.0", + "phpunit/phpunit": "~10.0 || ~11.0", "swoole/ide-helper": "dev-master" }, "suggest": { diff --git a/tests/unit/ArrayObjectTest.php b/tests/unit/ArrayObjectTest.php index 4594a90a..52b43f19 100644 --- a/tests/unit/ArrayObjectTest.php +++ b/tests/unit/ArrayObjectTest.php @@ -11,12 +11,13 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * @internal - * @coversNothing */ +#[CoversClass(ArrayObject::class)] class ArrayObjectTest extends TestCase { private ArrayObject $data; @@ -29,12 +30,6 @@ class ArrayObjectTest extends TestCase private array $control_data; - /** - * ArrayObjectTest constructor. - * @covers \Swoole\ArrayObject::each() - * @covers \Swoole\ArrayObject::split() - * @param string $dataName - */ public function __construct(?string $name = null, array $data = [], $dataName = '') { $_data = '11, 33, 22, 44,12,32,55, 23,19,23'; @@ -63,19 +58,11 @@ public function __construct(?string $name = null, array $data = [], $dataName = parent::__construct($name, $data, $dataName); } - /** - * @covers \Swoole\ArrayObject::toArray() - */ public function testToArray() { $this->assertEquals($this->data->toArray(), $this->control_data); } - /** - * @covers \Swoole\ArrayObject::each() - * @covers \Swoole\ArrayObject::sort() - * @covers \Swoole\ArrayObject::unique() - */ public function testMix() { $datao = clone $this->data; @@ -88,17 +75,11 @@ public function testMix() $this->assertEquals($data, $expectResult); } - /** - * @covers \Swoole\ArrayObject::serialize() - */ public function testSerialize() { $this->assertEquals(serialize($this->data->toArray()), $this->data->serialize()); } - /** - * @covers \Swoole\ArrayObject::unique() - */ public function testUnique() { $data = $this->data->unique()->toArray(); diff --git a/tests/unit/Coroutine/BarrierTest.php b/tests/unit/Coroutine/BarrierTest.php index fa4cb4b7..f66dc56c 100644 --- a/tests/unit/Coroutine/BarrierTest.php +++ b/tests/unit/Coroutine/BarrierTest.php @@ -11,18 +11,16 @@ namespace Swoole\Coroutine; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\Coroutine; /** * @internal - * @coversNothing */ +#[CoversClass(Barrier::class)] class BarrierTest extends TestCase { - /** - * @covers \Swoole\Coroutine\Barrier - */ public function testWait() { run(function () { @@ -43,9 +41,6 @@ public function testWait() }); } - /** - * @covers \Swoole\Coroutine\Barrier - */ public function testWaitTimeout() { run(function () { @@ -73,8 +68,6 @@ public function testWaitTimeout() /** * Test without execution switching between coroutines. - * - * @covers \Swoole\Coroutine\Barrier */ public function testNoCoroutineSwitching() { @@ -95,8 +88,6 @@ public function testNoCoroutineSwitching() /** * Test without any child coroutines created. Ideally we shouldn't use the Barrier class this way. - * - * @covers \Swoole\Coroutine\Barrier */ public function testWithoutAnyChildCoroutines() { @@ -109,8 +100,6 @@ public function testWithoutAnyChildCoroutines() /** * Test with the Barrier object destroyed in a child coroutine. Ideally we shouldn't use the Barrier class this way. - * - * @covers \Swoole\Coroutine\Barrier */ public function testUnexpectedDestroy() { @@ -129,8 +118,6 @@ public function testUnexpectedDestroy() /** * Test with the Barrier object destroyed in a child coroutine following by a coroutine switching. Ideally we shouldn't use the Barrier class this way. - * - * @covers \Swoole\Coroutine\Barrier */ public function testUnexpectedDestroyWithCoroutineSwitching() { diff --git a/tests/unit/Coroutine/FunctionTest.php b/tests/unit/Coroutine/FunctionTest.php index c496276b..2f9a8bcc 100644 --- a/tests/unit/Coroutine/FunctionTest.php +++ b/tests/unit/Coroutine/FunctionTest.php @@ -11,6 +11,7 @@ namespace Swoole\Coroutine; +use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\TestCase; use Swoole\Runtime; @@ -18,6 +19,10 @@ * @internal * @coversNothing */ +#[CoversFunction('Swoole\Coroutine\batch')] +#[CoversFunction('Swoole\Coroutine\go')] +#[CoversFunction('Swoole\Coroutine\parallel')] +#[CoversFunction('Swoole\Coroutine\map')] class FunctionTest extends TestCase { public function testBatchTimeout() diff --git a/tests/unit/Coroutine/HttpFunctionTest.php b/tests/unit/Coroutine/HttpFunctionTest.php index e4c1c84d..66328f79 100644 --- a/tests/unit/Coroutine/HttpFunctionTest.php +++ b/tests/unit/Coroutine/HttpFunctionTest.php @@ -11,6 +11,7 @@ namespace Swoole\Coroutine; +use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\TestCase; use Swoole\Constant; use Swoole\Coroutine; @@ -22,6 +23,8 @@ * @internal * @coversNothing */ +#[CoversFunction('Swoole\Coroutine\Http\get')] +#[CoversFunction('Swoole\Coroutine\Http\post')] class HttpFunctionTest extends TestCase { public function testGet() diff --git a/tests/unit/Coroutine/WaitGroupTest.php b/tests/unit/Coroutine/WaitGroupTest.php index 3ccaacf4..5ceaa621 100644 --- a/tests/unit/Coroutine/WaitGroupTest.php +++ b/tests/unit/Coroutine/WaitGroupTest.php @@ -11,12 +11,13 @@ namespace Swoole\Coroutine; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * @internal - * @coversNothing */ +#[CoversClass(WaitGroup::class)] class WaitGroupTest extends TestCase { public function testWait() diff --git a/tests/unit/Curl/HandlerTest.php b/tests/unit/Curl/HandlerTest.php index 313a5725..756763b9 100644 --- a/tests/unit/Curl/HandlerTest.php +++ b/tests/unit/Curl/HandlerTest.php @@ -11,6 +11,8 @@ namespace Swoole\Curl; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use PHPUnit\Framework\TestCase; use Swoole\Coroutine; use Swoole\Tests\HookFlagsTrait; @@ -19,9 +21,9 @@ * Class HandlerTest * * @internal - * @coversNothing - * @runTestsInSeparateProcesses */ +#[CoversClass(Handler::class)] +#[RunTestsInSeparateProcesses] class HandlerTest extends TestCase { use HookFlagsTrait; @@ -44,9 +46,6 @@ public function setUp(): void self::setHookFlags(SWOOLE_HOOK_CURL); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testRedirect() { Coroutine\run(function () { @@ -62,9 +61,6 @@ public function testRedirect() }); } - /** - * @covers \Swoole\Curl\Handler::__toString() - */ public function testToString() { Coroutine\run(function () { @@ -73,9 +69,6 @@ public function testToString() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testCustomHost() { Coroutine\run(function () { @@ -90,9 +83,6 @@ public function testCustomHost() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testHeaderName() { Coroutine\run(function () { @@ -109,9 +99,6 @@ public function testHeaderName() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testWriteFunction() { Coroutine\run(function () { @@ -132,9 +119,6 @@ public function testWriteFunction() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testResolve() { Coroutine\run(function () { @@ -157,9 +141,6 @@ public function testResolve() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testInvalidResolve() { Coroutine\run(function () { @@ -180,9 +161,6 @@ public function testInvalidResolve() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testResolve2() { Coroutine\run(function () { @@ -204,9 +182,6 @@ public function testResolve2() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testInvalidResolve2() { Coroutine\run(function () { @@ -227,9 +202,6 @@ public function testInvalidResolve2() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testInvalidResolve3() { Coroutine\run(function () { @@ -250,9 +222,6 @@ public function testInvalidResolve3() }); } - /** - * @covers \Swoole\Curl\Handler::execute() - */ public function testResolve3() { Coroutine\run(function () { diff --git a/tests/unit/Database/PDOPoolTest.php b/tests/unit/Database/PDOPoolTest.php index c3754c03..7294e86b 100644 --- a/tests/unit/Database/PDOPoolTest.php +++ b/tests/unit/Database/PDOPoolTest.php @@ -11,6 +11,7 @@ namespace Swoole\Database; +use PHPUnit\Framework\Attributes\CoversClass; use Swoole\Coroutine; use Swoole\Coroutine\WaitGroup; use Swoole\Tests\DatabaseTestCase; @@ -23,8 +24,8 @@ * Class PDOPoolTest * * @internal - * @coversNothing */ +#[CoversClass(PDOPool::class)] class PDOPoolTest extends DatabaseTestCase { use HookFlagsTrait; diff --git a/tests/unit/Database/PDOStatementProxyTest.php b/tests/unit/Database/PDOStatementProxyTest.php index 4a86ac82..dd45b8fe 100644 --- a/tests/unit/Database/PDOStatementProxyTest.php +++ b/tests/unit/Database/PDOStatementProxyTest.php @@ -11,20 +11,17 @@ namespace Swoole\Database; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use Swoole\Coroutine; use Swoole\Tests\DatabaseTestCase; /** - * Class PDOStatementProxyTest - * * @internal - * @coversNothing */ +#[CoversClass(PDOStatementProxy::class)] class PDOStatementProxyTest extends DatabaseTestCase { - /** - * @covers \Swoole\Database\PDOStatementProxy::__call() - */ public function testRun() { Coroutine\run(function () { @@ -68,10 +65,7 @@ public static function dataSetFetchMode(): array ]; } - /** - * @dataProvider dataSetFetchMode - * @covers \Swoole\Database\PDOStatementProxy::setFetchMode - */ + #[DataProvider('dataSetFetchMode')] public function testSetFetchMode(array $expected, array $args, string $message) { Coroutine\run(function () use ($expected, $args, $message) { @@ -89,9 +83,6 @@ public function testSetFetchMode(array $expected, array $args, string $message) }); } - /** - * @covers \Swoole\Database\PDOStatementProxy::bindParam() - */ public function testBindParam() { Coroutine\run(function () { diff --git a/tests/unit/FastCGI/FrameParserTest.php b/tests/unit/FastCGI/FrameParserTest.php index d88a8591..aecd9beb 100644 --- a/tests/unit/FastCGI/FrameParserTest.php +++ b/tests/unit/FastCGI/FrameParserTest.php @@ -11,14 +11,15 @@ namespace Swoole\FastCGI; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI\Record\BeginRequest; use Swoole\FastCGI\Record\Params; /** * @internal - * @coversNothing */ +#[CoversClass(FrameParser::class)] class FrameParserTest extends TestCase { public function testHasFrame(): void diff --git a/tests/unit/FastCGI/HttpRequestTest.php b/tests/unit/FastCGI/HttpRequestTest.php index 47ee5641..703a3c47 100644 --- a/tests/unit/FastCGI/HttpRequestTest.php +++ b/tests/unit/FastCGI/HttpRequestTest.php @@ -11,20 +11,20 @@ namespace Swoole\FastCGI; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\Coroutine; use Swoole\Coroutine\FastCGI\Client; /** * @internal - * @coversNothing */ +#[CoversClass(HttpRequest::class)] class HttpRequestTest extends TestCase { /** * To test the Keep-Alive header when sending multiple requests to a FastCGI server. * - * @covers \Swoole\FastCGI\HttpRequest * @see https://github.com/swoole/library/pull/169 Fix broken requests when keep-alive is turned on in the FastCGI client. */ public function testKeepAlive(): void diff --git a/tests/unit/FastCGI/HttpResponseTest.php b/tests/unit/FastCGI/HttpResponseTest.php index 5c85d369..bac20522 100644 --- a/tests/unit/FastCGI/HttpResponseTest.php +++ b/tests/unit/FastCGI/HttpResponseTest.php @@ -11,6 +11,8 @@ namespace Swoole\FastCGI; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Swoole\Coroutine; use Swoole\Coroutine\FastCGI\Client; @@ -19,8 +21,8 @@ /** * @internal - * @coversNothing */ +#[CoversClass(HttpResponse::class)] class HttpResponseTest extends TestCase { public static function dataHeaders(): array @@ -61,10 +63,7 @@ public static function dataHeaders(): array ]; } - /** - * @dataProvider dataHeaders - * @covers \Swoole\FastCGI\HttpResponse - */ + #[DataProvider('dataHeaders')] public function testHeaders(array $expectedHeaders, string $contentData, string $message): void { $contentData = str_replace("\n", "\r\n", $contentData); // Our files uses LF but not CRLF. @@ -115,10 +114,7 @@ public static function dataHeadersFromFPM(): array ]; } - /** - * @dataProvider dataHeadersFromFPM - * @covers \Swoole\FastCGI\HttpResponse - */ + #[DataProvider('dataHeadersFromFPM')] public function testHeadersFromFPM(array $expectedHeaders, string $filename, string $message): void { Coroutine\run( @@ -174,10 +170,7 @@ public static function dataStatus(): array ]; } - /** - * @dataProvider dataStatus - * @covers \Swoole\FastCGI\HttpResponse - */ + #[DataProvider('dataStatus')] public function testStatus(int $expectedStatusCode, string $expectedReasonPhrase, string $contentData): void { $contentData = str_replace("\n", "\r\n", $contentData); // Our files uses LF but not CRLF. @@ -216,10 +209,7 @@ public static function dataStatusFromFPM(): array ]; } - /** - * @dataProvider dataStatusFromFPM - * @covers \Swoole\FastCGI\HttpResponse - */ + #[DataProvider('dataStatusFromFPM')] public function testStatusFromFPM(int $expectedStatusCode, string $expectedReasonPhrase, string $filename): void { Coroutine\run( diff --git a/tests/unit/FastCGI/Record/AbortRequestTest.php b/tests/unit/FastCGI/Record/AbortRequestTest.php index 20599d07..5363449e 100644 --- a/tests/unit/FastCGI/Record/AbortRequestTest.php +++ b/tests/unit/FastCGI/Record/AbortRequestTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(AbortRequest::class)] class AbortRequestTest extends TestCase { protected static string $rawMessage = '0102000100000000'; diff --git a/tests/unit/FastCGI/Record/BeginRequestTest.php b/tests/unit/FastCGI/Record/BeginRequestTest.php index d958a957..5b804dd4 100644 --- a/tests/unit/FastCGI/Record/BeginRequestTest.php +++ b/tests/unit/FastCGI/Record/BeginRequestTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(BeginRequest::class)] class BeginRequestTest extends TestCase { protected static string $rawMessage = '01010001000800000001010000000000'; diff --git a/tests/unit/FastCGI/Record/DataTest.php b/tests/unit/FastCGI/Record/DataTest.php index d08f21db..c290d230 100644 --- a/tests/unit/FastCGI/Record/DataTest.php +++ b/tests/unit/FastCGI/Record/DataTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Data::class)] class DataTest extends TestCase { protected static string $rawMessage = '01080001000404007465737400000000'; diff --git a/tests/unit/FastCGI/Record/EndRequestTest.php b/tests/unit/FastCGI/Record/EndRequestTest.php index 501e159b..24dfe22e 100644 --- a/tests/unit/FastCGI/Record/EndRequestTest.php +++ b/tests/unit/FastCGI/Record/EndRequestTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(EndRequest::class)] class EndRequestTest extends TestCase { protected static string $rawMessage = '01030001000800000000006400000000'; diff --git a/tests/unit/FastCGI/Record/GetValuesResultTest.php b/tests/unit/FastCGI/Record/GetValuesResultTest.php index 23ec2b61..06d5e0fa 100644 --- a/tests/unit/FastCGI/Record/GetValuesResultTest.php +++ b/tests/unit/FastCGI/Record/GetValuesResultTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(GetValuesResult::class)] class GetValuesResultTest extends TestCase { protected static string $rawMessage = '010a0001001206000f01464347495f4d5058535f434f4e4e5331000000000000'; diff --git a/tests/unit/FastCGI/Record/GetValuesTest.php b/tests/unit/FastCGI/Record/GetValuesTest.php index 6c921ead..cb44eb88 100644 --- a/tests/unit/FastCGI/Record/GetValuesTest.php +++ b/tests/unit/FastCGI/Record/GetValuesTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(GetValues::class)] class GetValuesTest extends TestCase { protected static string $rawMessage = '01090001001107000f00464347495f4d5058535f434f4e4e5300000000000000'; diff --git a/tests/unit/FastCGI/Record/ParamsTest.php b/tests/unit/FastCGI/Record/ParamsTest.php index 418d43ba..054c27e9 100644 --- a/tests/unit/FastCGI/Record/ParamsTest.php +++ b/tests/unit/FastCGI/Record/ParamsTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Params::class)] class ParamsTest extends TestCase { protected static string $rawMessage =' diff --git a/tests/unit/FastCGI/Record/StderrTest.php b/tests/unit/FastCGI/Record/StderrTest.php index 44241234..7816ed09 100644 --- a/tests/unit/FastCGI/Record/StderrTest.php +++ b/tests/unit/FastCGI/Record/StderrTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Stderr::class)] class StderrTest extends TestCase { protected static string $rawMessage = '01070001000404007465737400000000'; diff --git a/tests/unit/FastCGI/Record/StdinTest.php b/tests/unit/FastCGI/Record/StdinTest.php index 9332a754..0fc9de49 100644 --- a/tests/unit/FastCGI/Record/StdinTest.php +++ b/tests/unit/FastCGI/Record/StdinTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Stdin::class)] class StdinTest extends TestCase { protected static string $rawMessage = '01050001000404007465737400000000'; diff --git a/tests/unit/FastCGI/Record/StdoutTest.php b/tests/unit/FastCGI/Record/StdoutTest.php index 68434d32..b9591cf2 100644 --- a/tests/unit/FastCGI/Record/StdoutTest.php +++ b/tests/unit/FastCGI/Record/StdoutTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Stdout::class)] class StdoutTest extends TestCase { protected static string $rawMessage = '01060001000404007465737400000000'; diff --git a/tests/unit/FastCGI/Record/UnknownTypeTest.php b/tests/unit/FastCGI/Record/UnknownTypeTest.php index 80fb2d4e..5720e0aa 100644 --- a/tests/unit/FastCGI/Record/UnknownTypeTest.php +++ b/tests/unit/FastCGI/Record/UnknownTypeTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI\Record; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(UnknownType::class)] class UnknownTypeTest extends TestCase { protected static string $rawMessage = '010b0001000800002a57544621000000'; diff --git a/tests/unit/FastCGI/RecordTest.php b/tests/unit/FastCGI/RecordTest.php index adecce7a..f35ab4de 100644 --- a/tests/unit/FastCGI/RecordTest.php +++ b/tests/unit/FastCGI/RecordTest.php @@ -11,13 +11,14 @@ namespace Swoole\FastCGI; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\FastCGI; /** * @internal - * @coversNothing */ +#[CoversClass(Record::class)] class RecordTest extends TestCase { // from the wireshark captured traffic diff --git a/tests/unit/FunctionTest.php b/tests/unit/FunctionTest.php index 09f90fa6..52ee5661 100644 --- a/tests/unit/FunctionTest.php +++ b/tests/unit/FunctionTest.php @@ -11,18 +11,17 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\TestCase; /** * @internal * @coversNothing */ +#[CoversFunction('swoole_library_get_options')] +#[CoversFunction('swoole_library_set_options')] class FunctionTest extends TestCase { - /** - * @covers ::swoole_library_get_options - * @covers ::swoole_library_set_options - */ public function testOptions() { $options = [__METHOD__ => uniqid()]; @@ -30,10 +29,6 @@ public function testOptions() $this->assertEquals($options, swoole_library_get_options()); } - /** - * @covers ::swoole_library_get_option - * @covers ::swoole_library_set_option - */ public function testOption() { $option = uniqid(); diff --git a/tests/unit/MultibyteStringObjectTest.php b/tests/unit/MultibyteStringObjectTest.php index 3ab022ae..463ff9a4 100644 --- a/tests/unit/MultibyteStringObjectTest.php +++ b/tests/unit/MultibyteStringObjectTest.php @@ -11,17 +11,15 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * @internal - * @coversNothing */ +#[CoversClass(MultibyteStringObject::class)] class MultibyteStringObjectTest extends TestCase { - /** - * @covers \Swoole\MultibyteStringObject::length() - */ public function testLength() { $str = 'hello world'; @@ -29,58 +27,37 @@ public function testLength() $this->assertEquals(strlen($str), $length); } - /** - * @covers \Swoole\MultibyteStringObject::indexOf() - */ public function testIndexOf() { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->indexOf('swoole'), 6); } - /** - * @covers \Swoole\MultibyteStringObject::lastIndexOf() - */ public function testLastIndexOf() { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->lastIndexOf('hello'), 17); } - /** - * @covers \Swoole\MultibyteStringObject::pos() - */ public function testPos() { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->pos('and'), 13); } - /** - * @covers \Swoole\MultibyteStringObject::rpos() - */ public function testRPos() { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->rpos('hello'), 17); } - /** - * @covers \Swoole\MultibyteStringObject::ipos() - */ public function testIPos() { $this->assertEquals(swoole_mbstring('hello swoole AND hello world')->ipos('and'), 13); } - /** - * @covers \Swoole\MultibyteStringObject::substr() - */ public function testSubstr() { $this->assertEquals(swoole_mbstring('hello swoole and hello world') ->substr(4, 8)->toString(), 'o swoole'); } - /** - * @covers \Swoole\MultibyteStringObject::chunk() - */ public function chunk() { $r = swoole_mbstring('hello swoole and hello world')->chunk(5)->toArray(); diff --git a/tests/unit/NameResolverTest.php b/tests/unit/NameResolverTest.php index 4312a025..ebb72c95 100644 --- a/tests/unit/NameResolverTest.php +++ b/tests/unit/NameResolverTest.php @@ -11,14 +11,17 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use function Swoole\Coroutine\run; /** * @internal - * @coversNothing */ +#[CoversClass(NameResolver\Consul::class)] +#[CoversClass(NameResolver\Nacos::class)] +#[CoversClass(NameResolver\Redis::class)] class NameResolverTest extends TestCase { public function testRedis() diff --git a/tests/unit/ObjectProxyTest.php b/tests/unit/ObjectProxyTest.php index f9d555ec..14dc9047 100644 --- a/tests/unit/ObjectProxyTest.php +++ b/tests/unit/ObjectProxyTest.php @@ -11,17 +11,18 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use Swoole\Database\MysqliProxy; use Swoole\Database\ObjectProxy; use Swoole\Database\PDOProxy; use Swoole\Tests\DatabaseTestCase; /** - * Class ObjectProxyTest - * * @internal - * @coversNothing */ +#[CoversClass(ObjectProxy::class)] class ObjectProxyTest extends DatabaseTestCase { /** @@ -42,9 +43,8 @@ public static function dataDatabaseObjectProxy(): array /** * @param class-string $expectedObjectClass * @param class-string|null $expectedProxyClass - * @dataProvider dataDatabaseObjectProxy - * @covers \Swoole\Database\ObjectProxy::__clone() */ + #[DataProvider('dataDatabaseObjectProxy')] public function testDatabaseObjectProxy(callable $callback, string $expectedObjectClass, ?string $expectedProxyClass = null): void { Coroutine\run(function () use ($callback, $expectedObjectClass, $expectedProxyClass): void { @@ -76,11 +76,8 @@ public static function dataUncloneableDatabaseProxyObject(): array ]; } - /** - * @depends testDatabaseObjectProxy - * @dataProvider dataUncloneableDatabaseProxyObject - * @covers \Swoole\Database\ObjectProxy::__clone() - */ + #[Depends('testDatabaseObjectProxy')] + #[DataProvider('dataUncloneableDatabaseProxyObject')] public function testUncloneableDatabaseProxyObject(callable $callback): void { Coroutine\run(function () use ($callback): void { diff --git a/tests/unit/Process/ProcessManagerTest.php b/tests/unit/Process/ProcessManagerTest.php index dfb122ba..4d126f2c 100644 --- a/tests/unit/Process/ProcessManagerTest.php +++ b/tests/unit/Process/ProcessManagerTest.php @@ -11,21 +11,17 @@ namespace Swoole\Process; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Swoole\Atomic; use Swoole\Coroutine; /** - * Class ProcessManagerTest - * * @internal - * @coversNothing */ +#[CoversClass(ProcessManager::class)] class ProcessManagerTest extends TestCase { - /** - * @covers \Swoole\Process\ProcessManager::add - */ public function testAdd() { $pm = new ProcessManager(); @@ -46,9 +42,6 @@ public function testAdd() $pm->start(); } - /** - * @covers \Swoole\Process\ProcessManager::add - */ public function testAddDisableCoroutine() { $pm = new ProcessManager(); @@ -61,9 +54,6 @@ public function testAddDisableCoroutine() $pm->start(); } - /** - * @covers \Swoole\Process\ProcessManager::add - */ public function testAddEnableCoroutine() { $pm = new ProcessManager(); @@ -76,9 +66,6 @@ public function testAddEnableCoroutine() $pm->start(); } - /** - * @covers \Swoole\Process\ProcessManager::addBatch - */ public function testAddBatch() { $pm = new ProcessManager(); diff --git a/tests/unit/StringObjectTest.php b/tests/unit/StringObjectTest.php index aff0898d..2ea3ca34 100644 --- a/tests/unit/StringObjectTest.php +++ b/tests/unit/StringObjectTest.php @@ -11,35 +11,27 @@ namespace Swoole; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * @internal - * @coversNothing */ +#[CoversClass(StringObject::class)] class StringObjectTest extends TestCase { - /** - * @covers \Swoole\StringObject::replace() - */ public function testReplace() { $str = swoole_string('hello world')->replace('ello', '____'); $this->assertEquals($str->toString(), 'h____ world'); } - /** - * @covers \Swoole\StringObject::ltrim() - */ public function testLtrim() { $str = swoole_string(" \nhello world\n")->ltrim(); $this->assertEquals($str->toString(), "hello world\n"); } - /** - * @covers \Swoole\StringObject::length() - */ public function testLength() { $str = 'hello world'; @@ -47,43 +39,28 @@ public function testLength() $this->assertEquals(strlen($str), $stro->length()); } - /** - * @covers \Swoole\StringObject::substr() - */ public function testSubstr() { $this->assertEquals(swoole_string('hello swoole and hello world') ->substr(4, 8)->toString(), 'o swoole'); } - /** - * @covers \Swoole\StringObject::rtrim() - */ public function testRtrim() { $str = swoole_string(" \nhello world\n")->rtrim(); $this->assertEquals($str->toString(), " \nhello world"); } - /** - * @covers \Swoole\StringObject::startsWith() - */ public function testStartsWith() { $this->assertTrue(swoole_string('hello swoole and hello world')->startsWith('hello swoole')); } - /** - * @covers \Swoole\StringObject::contains() - */ public function testContains() { $this->assertTrue(swoole_string('hello swoole and hello world')->contains('swoole')); } - /** - * @covers \Swoole\StringObject::contains() - */ public function chunk() { $r = swoole_string('hello swoole and hello world')->chunk(5)->toArray(); @@ -98,9 +75,6 @@ public function chunk() $this->assertEquals($expectResult, $r); } - /** - * @covers \Swoole\StringObject::upper() - */ public function testUpper() { $str = 'HELLO world'; @@ -108,17 +82,11 @@ public function testUpper() $this->assertEquals($result->toString(), 'HELLO WORLD'); } - /** - * @covers \Swoole\StringObject::pos() - */ public function testPos() { $this->assertEquals(swoole_string('hello swoole and hello world')->pos('and'), 13); } - /** - * @covers \Swoole\StringObject::chunkSplit() - */ public function testChunkSplit() { $str = 'hello swoole and hello world'; @@ -129,9 +97,6 @@ public function testChunkSplit() $this->assertEquals($expectResult, $r); } - /** - * @covers \Swoole\StringObject::repeat() - */ public function testRepeat() { $this->assertEquals( @@ -140,9 +105,6 @@ public function testRepeat() ); } - /** - * @covers \Swoole\StringObject::append() - */ public function testAppend() { $this->assertEquals( @@ -156,9 +118,6 @@ public function testAppend() ); } - /** - * @covers \Swoole\StringObject::char() - */ public function testChar() { $str = swoole_string('ABC'); @@ -168,26 +127,17 @@ public function testChar() $this->assertEquals($str->char(100), ''); } - /** - * @covers \Swoole\StringObject::trim() - */ public function testTrim() { $str = swoole_string(" \nhello world\n")->trim(); $this->assertEquals($str->toString(), 'hello world'); } - /** - * @covers \Swoole\StringObject::ipos() - */ public function testIpos() { $this->assertEquals(swoole_string('hello swoole AND hello world')->ipos('and'), 13); } - /** - * @covers \Swoole\StringObject::lower() - */ public function testLower() { $str = 'HELLO WORLD'; @@ -195,9 +145,6 @@ public function testLower() $this->assertEquals($result->toString(), 'hello world'); } - /** - * @covers \Swoole\StringObject::split() - */ public function testSplit() { $str = 'hello swoole and hello world'; @@ -205,49 +152,31 @@ public function testSplit() $this->assertEquals($result->toArray(), explode(' ', $str)); } - /** - * @covers \Swoole\StringObject::lastIndexOf() - */ public function testLastIndexOf() { $this->assertEquals(swoole_string('hello swoole and hello world')->lastIndexOf('hello'), 17); } - /** - * @covers \Swoole\StringObject::indexOf() - */ public function testIndexOf() { $this->assertEquals(swoole_string('hello swoole and hello world')->indexOf('swoole'), 6); } - /** - * @covers \Swoole\StringObject::rpos() - */ public function testRpos() { $this->assertEquals(swoole_string('hello swoole and hello world')->rpos('hello'), 17); } - /** - * @covers \Swoole\StringObject::reverse() - */ public function testReverse() { $this->assertEquals(swoole_string('hello swoole')->reverse()->toString(), strrev('hello swoole')); } - /** - * @covers \Swoole\StringObject::endsWith() - */ public function testEndsWith() { $this->assertTrue(swoole_string('hello swoole and hello world')->endsWith('world')); } - /** - * @covers \Swoole\StringObject::equals() - */ public function testEquals() { $str = swoole_string('123456'); @@ -258,9 +187,6 @@ public function testEquals() $this->assertFalse($str->equals(123456, true)); } - /** - * @covers \Swoole\StringObject::from() - */ public function testFrom() { $str = StringObject::from('string');