From 8aa2425b36bea8b07663c0621a52261e44e1a427 Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Fri, 24 May 2024 17:48:31 -0700 Subject: [PATCH] code quality improvements for PHP 8.1+ using Rector --- src/core/Coroutine/Barrier.php | 2 +- src/core/Server/Admin.php | 2 +- src/core/Server/Helper.php | 8 +- tests/unit/ArrayObjectTest.php | 122 +++++++++--------- tests/unit/Coroutine/BarrierTest.php | 12 +- tests/unit/Coroutine/FunctionTest.php | 10 +- tests/unit/Coroutine/HttpFunctionTest.php | 18 +-- tests/unit/Coroutine/WaitGroupTest.php | 2 +- tests/unit/Curl/HandlerTest.php | 24 ++-- tests/unit/Database/PDOPoolTest.php | 2 +- tests/unit/Database/PDOStatementProxyTest.php | 6 +- tests/unit/FunctionTest.php | 4 +- tests/unit/MultibyteStringObjectTest.php | 16 +-- tests/unit/NameResolverTest.php | 16 +-- tests/unit/Process/ProcessManagerTest.php | 8 +- tests/unit/StringObjectTest.php | 50 +++---- 16 files changed, 151 insertions(+), 151 deletions(-) diff --git a/src/core/Coroutine/Barrier.php b/src/core/Coroutine/Barrier.php index a21ab02..d47173d 100644 --- a/src/core/Coroutine/Barrier.php +++ b/src/core/Coroutine/Barrier.php @@ -47,7 +47,7 @@ public static function make(): self /** * @throws Exception */ - public static function wait(Barrier &$barrier, float $timeout = -1) + public static function wait(Barrier &$barrier, float $timeout = -1): void { if ($barrier->cid !== -1) { throw new Exception('The barrier is waiting, cannot wait again.'); diff --git a/src/core/Server/Admin.php b/src/core/Server/Admin.php index 49e48c9..790eda8 100644 --- a/src/core/Server/Admin.php +++ b/src/core/Server/Admin.php @@ -67,7 +67,7 @@ class Admin private static string $accessToken = ''; - public static function init(Server $server) + public static function init(Server $server): void { $accepted_process_types = SWOOLE_SERVER_COMMAND_MASTER | SWOOLE_SERVER_COMMAND_MANAGER | diff --git a/src/core/Server/Helper.php b/src/core/Server/Helper.php index 4f2f482..bd7a000 100644 --- a/src/core/Server/Helper.php +++ b/src/core/Server/Helper.php @@ -201,7 +201,7 @@ class Helper 'admin_server' => true, ]; - public static function checkOptions(array $input_options) + public static function checkOptions(array $input_options): void { $const_options = self::GLOBAL_OPTIONS + self::SERVER_OPTIONS + self::PORT_OPTIONS + self::AIO_OPTIONS + self::COROUTINE_OPTIONS + self::HELPER_OPTIONS; @@ -215,7 +215,7 @@ public static function checkOptions(array $input_options) } } - public static function onBeforeStart(Server $server) + public static function onBeforeStart(Server $server): void { if (!empty($server->setting['admin_server'])) { Admin::init($server); @@ -230,7 +230,7 @@ public static function onBeforeShutdown(Server $server): void } } - public static function onWorkerStart(Server $server, int $workerId) + public static function onWorkerStart(Server $server, int $workerId): void { if (!empty($server->setting['stats_file']) and $workerId == 0) { $interval_ms = empty($server->setting['stats_timer_interval']) ? self::STATS_TIMER_INTERVAL_TIME : intval($server->setting['stats_timer_interval']); @@ -254,7 +254,7 @@ public static function onWorkerStart(Server $server, int $workerId) } } - public static function onWorkerExit(Server $server, int $workerId) + public static function onWorkerExit(Server $server, int $workerId): void { if ($server->stats_timer) { Timer::clear($server->stats_timer); diff --git a/tests/unit/ArrayObjectTest.php b/tests/unit/ArrayObjectTest.php index 52b43f1..e78e1b5 100644 --- a/tests/unit/ArrayObjectTest.php +++ b/tests/unit/ArrayObjectTest.php @@ -58,12 +58,12 @@ public function __construct(?string $name = null, array $data = [], $dataName = parent::__construct($name, $data, $dataName); } - public function testToArray() + public function testToArray(): void { $this->assertEquals($this->data->toArray(), $this->control_data); } - public function testMix() + public function testMix(): void { $datao = clone $this->data; $data = $datao->sort()->unique()->toArray(); @@ -75,12 +75,12 @@ public function testMix() $this->assertEquals($data, $expectResult); } - public function testSerialize() + public function testSerialize(): void { $this->assertEquals(serialize($this->data->toArray()), $this->data->serialize()); } - public function testUnique() + public function testUnique(): void { $data = $this->data->unique()->toArray(); $copy_data = $this->control_data; @@ -89,7 +89,7 @@ public function testUnique() $this->assertEquals($data, $expectResult); } - public function testTraverse() + public function testTraverse(): void { $newArray = []; foreach ($this->data as $value) { @@ -98,7 +98,7 @@ public function testTraverse() $this->assertEquals($this->control_data, $newArray); } - public function testRemove() + public function testRemove(): void { $data1 = swoole_array_list('hello', 'world', 'swoole'); $data2 = $data1->toArray(); @@ -109,7 +109,7 @@ public function testRemove() ); } - public function testFilter() + public function testFilter(): void { $data = $this->data->filter(fn ($v) => $v > 20); @@ -123,17 +123,17 @@ public function testFilter() $this->assertFalse($find); } - public function testOffsetExists() + public function testOffsetExists(): void { $this->assertEquals($this->data->offsetExists(9), isset($this->control_data[9])); } - public function testSearch() + public function testSearch(): void { $this->assertEquals($this->data_2->search('swoole'), 2); } - public function testValues() + public function testValues(): void { $this->assertEquals( $this->data_3->values()->toArray(), @@ -141,7 +141,7 @@ public function testValues() ); } - public function testMap() + public function testMap(): void { $arr1 = [1, 2, 3, 4, 5]; $arr2 = [6, 7, 8, 9, 10]; @@ -164,17 +164,17 @@ public function testMap() ]); } - public function testClear() + public function testClear(): void { $this->assertEquals((clone $this->data->clear())->toArray(), []); } - public function testReverse() + public function testReverse(): void { $this->assertEquals($this->data->reverse()->toArray(), array_reverse($this->control_data)); } - public function testDelete() + public function testDelete(): void { $data = clone $this->data_3; $expectData = $data->toArray(); @@ -186,13 +186,13 @@ public function testDelete() ); } - public function testContains() + public function testContains(): void { $this->assertTrue($this->data_2->contains('swoole')); $this->assertFalse($this->data_2->contains('aliyun')); } - public function testUnserialize() + public function testUnserialize(): void { $str = serialize($this->data->toArray()); $this->assertEquals( @@ -201,21 +201,21 @@ public function testUnserialize() ); } - public function testPushBack() + public function testPushBack(): void { $data = clone $this->data; $data->pushBack(999); $this->assertEquals($data->search(999), $data->count() - 1); } - public function testPushFront() + public function testPushFront(): void { $data = clone $this->data; $data->pushFront(999); $this->assertEquals($data->search(999), 0); } - public function testPopFront() + public function testPopFront(): void { $data = clone $this->data; $value = $data->popFront(); @@ -223,7 +223,7 @@ public function testPopFront() $this->assertEquals($data->count(), $this->data->count() - 1); } - public function testPopBack() + public function testPopBack(): void { $data = clone $this->data; $value = $data->popBack(); @@ -231,7 +231,7 @@ public function testPopBack() $this->assertEquals($data->count(), $this->data->count() - 1); } - public function testPop() + public function testPop(): void { $data = clone $this->data; $value = $data->pop(); @@ -239,14 +239,14 @@ public function testPop() $this->assertEquals($data->count(), $this->data->count() - 1); } - public function testPush() + public function testPush(): void { $data = clone $this->data; $data->pushBack(999); $this->assertEquals($data->search(999), $data->count() - 1); } - public function testAppend() + public function testAppend(): void { $data = clone $this->data; $data->append(999)->append(888); @@ -256,7 +256,7 @@ public function testAppend() $this->assertTrue($data->contains(30000)); } - public function testShuffle() + public function testShuffle(): void { $data1 = clone $this->data; $data2 = clone $this->data; @@ -265,7 +265,7 @@ public function testShuffle() $this->assertEquals($data1->values()->sort()->toArray(), $data2->values()->sort()->toArray()); } - public function testColumn() + public function testColumn(): void { $records = [ [ @@ -301,12 +301,12 @@ public function testColumn() ); } - public function testIndexOf() + public function testIndexOf(): void { $this->assertEquals($this->data->indexOf(23), 7); } - public function testProduct() + public function testProduct(): void { $value = 1; foreach ($this->control_data as $v) { @@ -315,7 +315,7 @@ public function testProduct() $this->assertEquals($this->data->product(), $value); } - public function testAsort() + public function testAsort(): void { $data1 = $this->data_4->toArray(); $data2 = clone $this->data_4; @@ -323,7 +323,7 @@ public function testAsort() $this->assertEquals($data1, $data2->asort()->toArray()); } - public function testArsort() + public function testArsort(): void { $data1 = $this->data_4->toArray(); $data2 = clone $this->data_4; @@ -331,7 +331,7 @@ public function testArsort() $this->assertEquals($data1, $data2->arsort()->toArray()); } - public function testKsort() + public function testKsort(): void { $data1 = $this->data_4->toArray(); $data2 = clone $this->data_4; @@ -339,7 +339,7 @@ public function testKsort() $this->assertEquals($data1, $data2->ksort()->toArray()); } - public function testKrsort() + public function testKrsort(): void { $data1 = $this->data_4->toArray(); $data2 = clone $this->data_4; @@ -347,7 +347,7 @@ public function testKrsort() $this->assertEquals($data1, $data2->krsort()->toArray()); } - public function testSort() + public function testSort(): void { $data1 = $this->data->toArray(); $data2 = clone $this->data; @@ -355,7 +355,7 @@ public function testSort() $this->assertEquals($data1, $data2->sort()->toArray()); } - public function testRsort() + public function testRsort(): void { $data1 = $this->data->toArray(); $data2 = clone $this->data; @@ -363,7 +363,7 @@ public function testRsort() $this->assertEquals($data1, $data2->rsort()->toArray()); } - public function testUasort() + public function testUasort(): void { $data1 = ['a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4]; $data2 = swoole_array($data1); @@ -372,7 +372,7 @@ public function testUasort() $this->assertEquals($data1, $data2->uasort($cmp)->toArray()); } - public function testNatsort() + public function testNatsort(): void { $data1 = ['img12.png', 'img10.png', 'img2.png', 'img1.png']; $data2 = swoole_array($data1); @@ -380,7 +380,7 @@ public function testNatsort() $this->assertEquals($data1, $data2->natsort()->toArray()); } - public function testNatcasesort() + public function testNatcasesort(): void { $data1 = ['IMG0.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG3.png']; $data2 = swoole_array($data1); @@ -388,7 +388,7 @@ public function testNatcasesort() $this->assertEquals($data1, $data2->natcasesort()->toArray()); } - public function testUsort() + public function testUsort(): void { $cmp = fn ($a, $b) => $a <=> $b; @@ -398,7 +398,7 @@ public function testUsort() $this->assertEquals($data1, $data2->usort($cmp)->toArray()); } - public function testUksort() + public function testUksort(): void { $cmp = function ($a, $b) { $a = preg_replace('@^(a|an|the) @', '', $a); @@ -412,17 +412,17 @@ public function testUksort() $this->assertEquals($data1, $data2->uksort($cmp)->toArray()); } - public function testCount() + public function testCount(): void { $this->assertEquals($this->data->count(), count($this->control_data)); } - public function testOffsetGet() + public function testOffsetGet(): void { $this->assertEquals($this->control_data[6], $this->data[6]); } - public function testReduce() + public function testReduce(): void { $this->assertEquals($this->data->product(), $this->data->reduce(function ($carry, $item) { $carry *= $item; @@ -430,7 +430,7 @@ public function testReduce() }, 1)); } - public function testOffsetSet() + public function testOffsetSet(): void { $value = 9999; $data = clone $this->data; @@ -438,20 +438,20 @@ public function testOffsetSet() $this->assertEquals($data->get(7), $value); } - public function testOffsetUnset() + public function testOffsetUnset(): void { $data = clone $this->data; unset($data[6]); $this->assertFalse($data->exists(6)); } - public function testIsEmpty() + public function testIsEmpty(): void { $this->assertFalse($this->data->isEmpty()); $this->assertTrue(swoole_array()->isEmpty()); } - public function testKeys() + public function testKeys(): void { $this->assertEquals( $this->data_4->keys()->toArray(), @@ -459,7 +459,7 @@ public function testKeys() ); } - public function testSet() + public function testSet(): void { $data = clone $this->data_3; $data->set('com', 'tal100'); @@ -467,35 +467,35 @@ public function testSet() $this->assertEquals($data->count(), $this->data_3->count() + 1); } - public function testInsert() + public function testInsert(): void { $data = clone $this->data; $data->insert(7, 888); $this->assertEquals($data->get(7), 888); } - public function testRandomGet() + public function testRandomGet(): void { $this->assertTrue($this->data->contains($this->data->randomGet())); } - public function testSum() + public function testSum(): void { $this->assertEquals($this->data->sum(), array_sum($this->control_data)); } - public function testFlip() + public function testFlip(): void { $result = $this->data_3->flip(); $this->assertEquals($result->toArray(), array_flip($this->data_3->toArray())); } - public function testJoin() + public function testJoin(): void { $this->assertEquals($this->data_2->join('-'), implode('-', $this->data_2->toArray())); } - public function testChunk() + public function testChunk(): void { $this->assertEquals( $this->data->chunk(2)->toArray(), @@ -503,7 +503,7 @@ public function testChunk() ); } - public function testSlice() + public function testSlice(): void { $this->assertEquals( $this->data->slice(2, 4)->toArray(), @@ -511,43 +511,43 @@ public function testSlice() ); } - public function testLastIndexOf() + public function testLastIndexOf(): void { $this->assertEquals($this->data->lastIndexOf(23), 9); } - public function testExists() + public function testExists(): void { $this->assertTrue($this->data_3->exists('swoole')); } - public function testFirst() + public function testFirst(): void { $this->assertEquals($this->data_4->first(), 'lemon'); } - public function testLast() + public function testLast(): void { $this->assertEquals($this->data_4->last(), 'apple'); } - public function testFirstKey() + public function testFirstKey(): void { $this->assertEquals($this->data_4->firstKey(), 'd'); } - public function testLastKey() + public function testLastKey(): void { $this->assertEquals($this->data_4->lastKey(), 'c'); } - public function testGetOr() + public function testGetOr(): void { $this->assertNull($this->data->getOr('undefined_key')); $this->assertSame('default_value', $this->data->getOr('undefined_key', 'default_value')); } - public function testFrom() + public function testFrom(): void { $arr = ArrayObject::from([1, 2, 3]); $this->assertInstanceOf(ArrayObject::class, $arr); diff --git a/tests/unit/Coroutine/BarrierTest.php b/tests/unit/Coroutine/BarrierTest.php index f66dc56..fadc4cc 100644 --- a/tests/unit/Coroutine/BarrierTest.php +++ b/tests/unit/Coroutine/BarrierTest.php @@ -21,7 +21,7 @@ #[CoversClass(Barrier::class)] class BarrierTest extends TestCase { - public function testWait() + public function testWait(): void { run(function () { $barrier = Barrier::make(); @@ -41,7 +41,7 @@ public function testWait() }); } - public function testWaitTimeout() + public function testWaitTimeout(): void { run(function () { $barrier = Barrier::make(); @@ -69,7 +69,7 @@ public function testWaitTimeout() /** * Test without execution switching between coroutines. */ - public function testNoCoroutineSwitching() + public function testNoCoroutineSwitching(): void { run(function () { $barrier = Barrier::make(); @@ -89,7 +89,7 @@ public function testNoCoroutineSwitching() /** * Test without any child coroutines created. Ideally we shouldn't use the Barrier class this way. */ - public function testWithoutAnyChildCoroutines() + public function testWithoutAnyChildCoroutines(): void { run(function () { $barrier = Barrier::make(); @@ -101,7 +101,7 @@ public function testWithoutAnyChildCoroutines() /** * Test with the Barrier object destroyed in a child coroutine. Ideally we shouldn't use the Barrier class this way. */ - public function testUnexpectedDestroy() + public function testUnexpectedDestroy(): void { run(function () { $barrier = Barrier::make(); @@ -119,7 +119,7 @@ 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. */ - public function testUnexpectedDestroyWithCoroutineSwitching() + public function testUnexpectedDestroyWithCoroutineSwitching(): void { run(function () { $barrier = Barrier::make(); diff --git a/tests/unit/Coroutine/FunctionTest.php b/tests/unit/Coroutine/FunctionTest.php index 2f9a8bc..867d3c3 100644 --- a/tests/unit/Coroutine/FunctionTest.php +++ b/tests/unit/Coroutine/FunctionTest.php @@ -25,7 +25,7 @@ #[CoversFunction('Swoole\Coroutine\map')] class FunctionTest extends TestCase { - public function testBatchTimeout() + public function testBatchTimeout(): void { run(function () { Runtime::setHookFlags(SWOOLE_HOOK_ALL); @@ -57,7 +57,7 @@ public function testBatchTimeout() }); } - public function testBatch() + public function testBatch(): void { run(function () { Runtime::setHookFlags(SWOOLE_HOOK_ALL); @@ -90,7 +90,7 @@ public function testBatch() }); } - public function testGo() + public function testGo(): void { run(function () { $cid = go(function () { @@ -100,7 +100,7 @@ public function testGo() }); } - public function testParallel() + public function testParallel(): void { run(function () { $start = microtime(true); @@ -121,7 +121,7 @@ public function testParallel() }); } - public function testMap() + public function testMap(): void { run(function () { $start = microtime(true); diff --git a/tests/unit/Coroutine/HttpFunctionTest.php b/tests/unit/Coroutine/HttpFunctionTest.php index 66328f7..70c578e 100644 --- a/tests/unit/Coroutine/HttpFunctionTest.php +++ b/tests/unit/Coroutine/HttpFunctionTest.php @@ -27,7 +27,7 @@ #[CoversFunction('Swoole\Coroutine\Http\post')] class HttpFunctionTest extends TestCase { - public function testGet() + public function testGet(): void { run(function () { Coroutine::create(function () { @@ -40,45 +40,45 @@ public function testGet() }); } - public function testPost() + public function testPost(): void { run(function () { $this->fun3(); }); } - public function testCurlGet() + public function testCurlGet(): void { swoole_library_set_option(Constant::OPTION_HTTP_CLIENT_DRIVER, 'curl'); $this->fun1(); $this->fun2(); } - public function testCurlPost() + public function testCurlPost(): void { swoole_library_set_option(Constant::OPTION_HTTP_CLIENT_DRIVER, 'curl'); $this->fun3(); } - public function testStreamGet() + public function testStreamGet(): void { swoole_library_set_option(Constant::OPTION_HTTP_CLIENT_DRIVER, 'stream'); $this->fun1(); $this->fun2(); } - public function testStreamPost() + public function testStreamPost(): void { swoole_library_set_option(Constant::OPTION_HTTP_CLIENT_DRIVER, 'stream'); $this->fun3(); } - private function fun1() + private function fun1(): void { self::assertSame(200, get('http://httpbin.org')->getStatusCode(), 'Test HTTP GET without query strings.'); } - private function fun2() + private function fun2(): void { $data = get('http://httpbin.org/get?hello=world'); $body = json_decode($data->getBody(), null, 512, JSON_THROW_ON_ERROR); @@ -86,7 +86,7 @@ private function fun2() self::assertSame('world', $body->args->hello); } - private function fun3() + private function fun3(): void { $random_data = base64_encode(random_bytes(128)); $data = post('http://httpbin.org/post?hello=world', ['random_data' => $random_data]); diff --git a/tests/unit/Coroutine/WaitGroupTest.php b/tests/unit/Coroutine/WaitGroupTest.php index 5ceaa62..dc1f2ae 100644 --- a/tests/unit/Coroutine/WaitGroupTest.php +++ b/tests/unit/Coroutine/WaitGroupTest.php @@ -20,7 +20,7 @@ #[CoversClass(WaitGroup::class)] class WaitGroupTest extends TestCase { - public function testWait() + public function testWait(): void { run(function () { $wg = new WaitGroup(4); diff --git a/tests/unit/Curl/HandlerTest.php b/tests/unit/Curl/HandlerTest.php index 756763b..8f89c85 100644 --- a/tests/unit/Curl/HandlerTest.php +++ b/tests/unit/Curl/HandlerTest.php @@ -46,7 +46,7 @@ public function setUp(): void self::setHookFlags(SWOOLE_HOOK_CURL); } - public function testRedirect() + public function testRedirect(): void { Coroutine\run(function () { $ch = curl_init('http://alturl.com/6xb2v'); @@ -61,7 +61,7 @@ public function testRedirect() }); } - public function testToString() + public function testToString(): void { Coroutine\run(function () { $ch = curl_init(); @@ -69,7 +69,7 @@ public function testToString() }); } - public function testCustomHost() + public function testCustomHost(): void { Coroutine\run(function () { $ip = Coroutine::gethostbyname('httpbin.org'); @@ -83,7 +83,7 @@ public function testCustomHost() }); } - public function testHeaderName() + public function testHeaderName(): void { Coroutine\run(function () { $ch = curl_init('http://httpbin.org/get'); @@ -99,7 +99,7 @@ public function testHeaderName() }); } - public function testWriteFunction() + public function testWriteFunction(): void { Coroutine\run(function () { $url = 'https://httpbin.org/get'; @@ -119,7 +119,7 @@ public function testWriteFunction() }); } - public function testResolve() + public function testResolve(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -141,7 +141,7 @@ public function testResolve() }); } - public function testInvalidResolve() + public function testInvalidResolve(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -161,7 +161,7 @@ public function testInvalidResolve() }); } - public function testResolve2() + public function testResolve2(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -182,7 +182,7 @@ public function testResolve2() }); } - public function testInvalidResolve2() + public function testInvalidResolve2(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -202,7 +202,7 @@ public function testInvalidResolve2() }); } - public function testInvalidResolve3() + public function testInvalidResolve3(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -222,7 +222,7 @@ public function testInvalidResolve3() }); } - public function testResolve3() + public function testResolve3(): void { Coroutine\run(function () { $host = 'httpbin.org'; @@ -243,7 +243,7 @@ public function testResolve3() }); } - public function testOptPrivate() + public function testOptPrivate(): void { Coroutine\run(function () { $url = 'https://httpbin.org/get'; diff --git a/tests/unit/Database/PDOPoolTest.php b/tests/unit/Database/PDOPoolTest.php index 7294e86..2d523fc 100644 --- a/tests/unit/Database/PDOPoolTest.php +++ b/tests/unit/Database/PDOPoolTest.php @@ -30,7 +30,7 @@ class PDOPoolTest extends DatabaseTestCase { use HookFlagsTrait; - public function testPutWhenErrorHappens() + public function testPutWhenErrorHappens(): void { self::saveHookFlags(); self::setHookFlags(SWOOLE_HOOK_ALL); diff --git a/tests/unit/Database/PDOStatementProxyTest.php b/tests/unit/Database/PDOStatementProxyTest.php index dd45b8f..8a4dcb3 100644 --- a/tests/unit/Database/PDOStatementProxyTest.php +++ b/tests/unit/Database/PDOStatementProxyTest.php @@ -22,7 +22,7 @@ #[CoversClass(PDOStatementProxy::class)] class PDOStatementProxyTest extends DatabaseTestCase { - public function testRun() + public function testRun(): void { Coroutine\run(function () { self::assertFalse( @@ -66,7 +66,7 @@ public static function dataSetFetchMode(): array } #[DataProvider('dataSetFetchMode')] - public function testSetFetchMode(array $expected, array $args, string $message) + public function testSetFetchMode(array $expected, array $args, string $message): void { Coroutine\run(function () use ($expected, $args, $message) { $stmt = self::getPdoMysqlPool()->get()->query( @@ -83,7 +83,7 @@ public function testSetFetchMode(array $expected, array $args, string $message) }); } - public function testBindParam() + public function testBindParam(): void { Coroutine\run(function () { $stmt = self::getPdoMysqlPool()->get()->prepare('SHOW TABLES like ?'); diff --git a/tests/unit/FunctionTest.php b/tests/unit/FunctionTest.php index 52ee566..434e095 100644 --- a/tests/unit/FunctionTest.php +++ b/tests/unit/FunctionTest.php @@ -22,14 +22,14 @@ #[CoversFunction('swoole_library_set_options')] class FunctionTest extends TestCase { - public function testOptions() + public function testOptions(): void { $options = [__METHOD__ => uniqid()]; swoole_library_set_options($options); $this->assertEquals($options, swoole_library_get_options()); } - public function testOption() + public function testOption(): void { $option = uniqid(); swoole_library_set_option(__METHOD__, $option); diff --git a/tests/unit/MultibyteStringObjectTest.php b/tests/unit/MultibyteStringObjectTest.php index 463ff9a..af84171 100644 --- a/tests/unit/MultibyteStringObjectTest.php +++ b/tests/unit/MultibyteStringObjectTest.php @@ -20,45 +20,45 @@ #[CoversClass(MultibyteStringObject::class)] class MultibyteStringObjectTest extends TestCase { - public function testLength() + public function testLength(): void { $str = 'hello world'; $length = swoole_mbstring($str)->length(); $this->assertEquals(strlen($str), $length); } - public function testIndexOf() + public function testIndexOf(): void { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->indexOf('swoole'), 6); } - public function testLastIndexOf() + public function testLastIndexOf(): void { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->lastIndexOf('hello'), 17); } - public function testPos() + public function testPos(): void { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->pos('and'), 13); } - public function testRPos() + public function testRPos(): void { $this->assertEquals(swoole_mbstring('hello swoole and hello world')->rpos('hello'), 17); } - public function testIPos() + public function testIPos(): void { $this->assertEquals(swoole_mbstring('hello swoole AND hello world')->ipos('and'), 13); } - public function testSubstr() + public function testSubstr(): void { $this->assertEquals(swoole_mbstring('hello swoole and hello world') ->substr(4, 8)->toString(), 'o swoole'); } - public function chunk() + public function chunk(): void { $r = swoole_mbstring('hello swoole and hello world')->chunk(5)->toArray(); $expectResult = [ diff --git a/tests/unit/NameResolverTest.php b/tests/unit/NameResolverTest.php index ebb72c9..d00a903 100644 --- a/tests/unit/NameResolverTest.php +++ b/tests/unit/NameResolverTest.php @@ -24,20 +24,20 @@ #[CoversClass(NameResolver\Redis::class)] class NameResolverTest extends TestCase { - public function testRedis() + public function testRedis(): void { $ns = new NameResolver\Redis(REDIS_SERVER_URL); $this->fun1($ns); } - public function testConsul() + public function testConsul(): void { swoole_library_set_option('http_client_driver', 'curl'); $ns = new NameResolver\Consul(CONSUL_AGENT_URL); $this->fun1($ns); } - public function testNacos() + public function testNacos(): void { if (GITHUB_ACTIONS) { $this->markTestSkipped('Nacos is not available.'); @@ -47,7 +47,7 @@ public function testNacos() $this->fun1($ns); } - public function testLookup() + public function testLookup(): void { if (!function_exists('swoole_name_resolver_lookup')) { $this->markTestSkipped('Swoole v4.9 or later is required.'); @@ -65,7 +65,7 @@ public function testLookup() $this->assertTrue(swoole_name_resolver_remove($ns)); } - public function testRedisCo() + public function testRedisCo(): void { run(function () { $ns = new NameResolver\Redis(REDIS_SERVER_URL); @@ -73,7 +73,7 @@ public function testRedisCo() }); } - public function testConsulCo() + public function testConsulCo(): void { run(function () { $ns = new NameResolver\Consul(CONSUL_AGENT_URL); @@ -81,7 +81,7 @@ public function testConsulCo() }); } - public function testNacosCo() + public function testNacosCo(): void { if (GITHUB_ACTIONS) { $this->markTestSkipped('Nacos is not available.'); @@ -92,7 +92,7 @@ public function testNacosCo() }); } - private function fun1(NameResolver $ns) + private function fun1(NameResolver $ns): void { $service_name = uniqid() . '.service'; $ip = '127.0.0.1'; diff --git a/tests/unit/Process/ProcessManagerTest.php b/tests/unit/Process/ProcessManagerTest.php index 4d126f2..473322f 100644 --- a/tests/unit/Process/ProcessManagerTest.php +++ b/tests/unit/Process/ProcessManagerTest.php @@ -22,7 +22,7 @@ #[CoversClass(ProcessManager::class)] class ProcessManagerTest extends TestCase { - public function testAdd() + public function testAdd(): void { $pm = new ProcessManager(); $atomic = new Atomic(0); @@ -42,7 +42,7 @@ public function testAdd() $pm->start(); } - public function testAddDisableCoroutine() + public function testAddDisableCoroutine(): void { $pm = new ProcessManager(); @@ -54,7 +54,7 @@ public function testAddDisableCoroutine() $pm->start(); } - public function testAddEnableCoroutine() + public function testAddEnableCoroutine(): void { $pm = new ProcessManager(); @@ -66,7 +66,7 @@ public function testAddEnableCoroutine() $pm->start(); } - public function testAddBatch() + public function testAddBatch(): void { $pm = new ProcessManager(); diff --git a/tests/unit/StringObjectTest.php b/tests/unit/StringObjectTest.php index 2ea3ca3..e9942e6 100644 --- a/tests/unit/StringObjectTest.php +++ b/tests/unit/StringObjectTest.php @@ -20,48 +20,48 @@ #[CoversClass(StringObject::class)] class StringObjectTest extends TestCase { - public function testReplace() + public function testReplace(): void { $str = swoole_string('hello world')->replace('ello', '____'); $this->assertEquals($str->toString(), 'h____ world'); } - public function testLtrim() + public function testLtrim(): void { $str = swoole_string(" \nhello world\n")->ltrim(); $this->assertEquals($str->toString(), "hello world\n"); } - public function testLength() + public function testLength(): void { $str = 'hello world'; $stro = swoole_string($str); $this->assertEquals(strlen($str), $stro->length()); } - public function testSubstr() + public function testSubstr(): void { $this->assertEquals(swoole_string('hello swoole and hello world') ->substr(4, 8)->toString(), 'o swoole'); } - public function testRtrim() + public function testRtrim(): void { $str = swoole_string(" \nhello world\n")->rtrim(); $this->assertEquals($str->toString(), " \nhello world"); } - public function testStartsWith() + public function testStartsWith(): void { $this->assertTrue(swoole_string('hello swoole and hello world')->startsWith('hello swoole')); } - public function testContains() + public function testContains(): void { $this->assertTrue(swoole_string('hello swoole and hello world')->contains('swoole')); } - public function chunk() + public function chunk(): void { $r = swoole_string('hello swoole and hello world')->chunk(5)->toArray(); $expectResult = [ @@ -75,19 +75,19 @@ public function chunk() $this->assertEquals($expectResult, $r); } - public function testUpper() + public function testUpper(): void { $str = 'HELLO world'; $result = swoole_string($str)->upper(); $this->assertEquals($result->toString(), 'HELLO WORLD'); } - public function testPos() + public function testPos(): void { $this->assertEquals(swoole_string('hello swoole and hello world')->pos('and'), 13); } - public function testChunkSplit() + public function testChunkSplit(): void { $str = 'hello swoole and hello world'; $r = swoole_string($str) @@ -97,7 +97,7 @@ public function testChunkSplit() $this->assertEquals($expectResult, $r); } - public function testRepeat() + public function testRepeat(): void { $this->assertEquals( swoole_string('ABC')->repeat(10), @@ -105,7 +105,7 @@ public function testRepeat() ); } - public function testAppend() + public function testAppend(): void { $this->assertEquals( swoole_string('ABC')->append(' hello'), @@ -118,7 +118,7 @@ public function testAppend() ); } - public function testChar() + public function testChar(): void { $str = swoole_string('ABC'); $this->assertEquals($str->char(1), 'B'); @@ -127,57 +127,57 @@ public function testChar() $this->assertEquals($str->char(100), ''); } - public function testTrim() + public function testTrim(): void { $str = swoole_string(" \nhello world\n")->trim(); $this->assertEquals($str->toString(), 'hello world'); } - public function testIpos() + public function testIpos(): void { $this->assertEquals(swoole_string('hello swoole AND hello world')->ipos('and'), 13); } - public function testLower() + public function testLower(): void { $str = 'HELLO WORLD'; $result = swoole_string($str)->lower(); $this->assertEquals($result->toString(), 'hello world'); } - public function testSplit() + public function testSplit(): void { $str = 'hello swoole and hello world'; $result = swoole_string($str)->split(' '); $this->assertEquals($result->toArray(), explode(' ', $str)); } - public function testLastIndexOf() + public function testLastIndexOf(): void { $this->assertEquals(swoole_string('hello swoole and hello world')->lastIndexOf('hello'), 17); } - public function testIndexOf() + public function testIndexOf(): void { $this->assertEquals(swoole_string('hello swoole and hello world')->indexOf('swoole'), 6); } - public function testRpos() + public function testRpos(): void { $this->assertEquals(swoole_string('hello swoole and hello world')->rpos('hello'), 17); } - public function testReverse() + public function testReverse(): void { $this->assertEquals(swoole_string('hello swoole')->reverse()->toString(), strrev('hello swoole')); } - public function testEndsWith() + public function testEndsWith(): void { $this->assertTrue(swoole_string('hello swoole and hello world')->endsWith('world')); } - public function testEquals() + public function testEquals(): void { $str = swoole_string('123456'); $this->assertTrue($str->equals('123456')); @@ -187,7 +187,7 @@ public function testEquals() $this->assertFalse($str->equals(123456, true)); } - public function testFrom() + public function testFrom(): void { $str = StringObject::from('string'); $this->assertInstanceOf(StringObject::class, $str);