From 00e901507de4d7f50f426757af1aab66ecc5204a Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 14:56:01 +1000 Subject: [PATCH 1/8] chore: Update Rector --- Makefile | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b1a19e0..4baf80e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ build: .PHONY: tests tests: - docker-compose run --rm php vendor/bin/phpunit --no-progress + docker-compose run --rm php vendor/bin/phpunit .PHONY: infection infection: diff --git a/composer.json b/composer.json index a5e9623..082eadc 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "friendsofphp/php-cs-fixer": "^3.90", "infection/infection": "^0.33", "phpunit/phpunit": "^13.0", - "rector/rector": "^1.2", + "rector/rector": "^2.4", "vimeo/psalm": "^6.10" }, "autoload": { From 42e78f71fbcabe73cd6bb0d44a342d40ef736edb Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 16:20:12 +1000 Subject: [PATCH 2/8] tests: Fix test cases --- .../AbstractMasterCoverageTest.php | 2 +- .../ConcurrencyIntegrationTest.php | 44 +++++++--- .../LoadBalancingIntegrationTest.php | 32 ++++++-- .../Integration/MasterHttpIntegrationTest.php | 26 ++++-- .../MasterLifecycleIntegrationTest.php | 14 ++-- .../WorkerCrashIntegrationTest.php | 21 ++++- .../WorkerPoolNotificationIntegrationTest.php | 4 +- tests/Unit/IPC/FdPasserCoverageTest.php | 2 +- tests/Unit/IPC/FdPasserFullCoverageTest.php | 12 ++- tests/Unit/IPC/UnixSocketChannelTest.php | 2 +- tests/Unit/IPC/UnixSocketChannelUnitTest.php | 2 +- .../Master/CentralizedMasterCallbackTest.php | 6 +- .../Master/CentralizedMasterEventTest.php | 2 +- tests/Unit/Master/CentralizedMasterFdTest.php | 4 +- .../Unit/Master/CentralizedMasterFullTest.php | 4 +- .../Master/CentralizedMasterRestartTest.php | 2 +- .../Master/CentralizedMasterStartTest.php | 2 +- tests/Unit/Master/CentralizedMasterTest.php | 10 +-- tests/Unit/Master/ConnectionRouterTest.php | 4 +- .../Unit/Master/ConnectionRouterUnitTest.php | 4 +- tests/Unit/Master/NonBlockingRestartTest.php | 2 - .../Master/SharedSocketMasterCallbackTest.php | 2 - .../Master/SharedSocketMasterSocketTest.php | 2 +- .../Master/SharedSocketMasterStartTest.php | 2 +- .../Unit/Master/SocketManagerCoverageTest.php | 4 +- tests/Unit/Master/SocketManagerTest.php | 10 +-- tests/Unit/Master/WorkerManagerUnitTest.php | 2 +- tests/Unit/Signal/SignalManagerTest.php | 12 +-- tests/Unit/Socket/SocketWrapperTest.php | 4 - .../Worker/EventDrivenWorkerInterfaceTest.php | 15 +--- .../Worker/HttpWorkerAdapterCoverageTest.php | 10 +-- tests/Unit/Worker/HttpWorkerAdapterTest.php | 80 ++++++++++++------- 32 files changed, 208 insertions(+), 136 deletions(-) diff --git a/tests/Integration/AbstractMasterCoverageTest.php b/tests/Integration/AbstractMasterCoverageTest.php index 56730c6..47be3c6 100644 --- a/tests/Integration/AbstractMasterCoverageTest.php +++ b/tests/Integration/AbstractMasterCoverageTest.php @@ -121,7 +121,7 @@ public function handle(mixed $clientSocket, array $metadata): void {} $waitRef = new ReflectionMethod($master, 'waitForWorkers'); $waitRef->invoke($master); - $this->assertTrue(true); + $this->assertCount(1, $master->getWorkers()); } #[Test] diff --git a/tests/Integration/ConcurrencyIntegrationTest.php b/tests/Integration/ConcurrencyIntegrationTest.php index 5880ec5..9570d37 100644 --- a/tests/Integration/ConcurrencyIntegrationTest.php +++ b/tests/Integration/ConcurrencyIntegrationTest.php @@ -73,7 +73,7 @@ public function handle(mixed $clientSocket, array $metadata): void $requestId = self::$counter; - usleep(10000); // Simulate some work + usleep(10000); $response = "HTTP/1.1 200 OK\r\n\r\nRequest: $requestId"; socket_write($clientSocket, $response); @@ -92,7 +92,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -105,14 +105,18 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $concurrentRequests; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_set_nonblock($client); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; $attempts = 0; while ($attempts < 100) { - $chunk = @socket_read($client, 1024); + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); if ($chunk) { $response .= $chunk; } @@ -128,6 +132,8 @@ public function handle(mixed $clientSocket, array $metadata): void } socket_close($client); + } else { + error_reporting($previousEr); } usleep(5000); @@ -195,7 +201,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -207,11 +213,19 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < 4; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; - while ($chunk = @socket_read($client, 1024)) { + while (true) { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { + break; + } $response .= $chunk; } @@ -220,6 +234,8 @@ public function handle(mixed $clientSocket, array $metadata): void } socket_close($client); + } else { + error_reporting($previousEr); } usleep(50000); @@ -275,7 +291,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -287,22 +303,28 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < 50; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_write($client, "GET / HTTP/1.1\r\n\r\n"); - $response = @socket_read($client, 1024); + $previousEr = error_reporting(0); + $response = socket_read($client, 1024); + error_reporting($previousEr); if ($response && str_contains($response, 'HTTP')) { ++$successCount; } socket_close($client); + } else { + error_reporting($previousEr); } } posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); - if ($successCount === 0) { + if (0 === $successCount) { $this->markTestSkipped('No successful rapid connections'); } diff --git a/tests/Integration/LoadBalancingIntegrationTest.php b/tests/Integration/LoadBalancingIntegrationTest.php index 75b6e18..52aa8a5 100644 --- a/tests/Integration/LoadBalancingIntegrationTest.php +++ b/tests/Integration/LoadBalancingIntegrationTest.php @@ -88,7 +88,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -101,15 +101,25 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $requestCount; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; - while ($chunk = @socket_read($client, 1024)) { + while (true) { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { + break; + } $response .= $chunk; } $responses[] = $response; socket_close($client); + } else { + error_reporting($previousEr); } usleep(10000); @@ -168,7 +178,7 @@ public function handles_multiple_concurrent_connections(): void $callback = new class implements WorkerCallbackInterface { public function handle(mixed $clientSocket, array $metadata): void { - usleep(50000); // Simulate work + usleep(50000); $response = "HTTP/1.1 200 OK\r\n\r\nOK"; socket_write($clientSocket, $response); @@ -187,7 +197,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -200,22 +210,28 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $concurrentRequests; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); - $response = @socket_read($client, 1024); + $previousEr = error_reporting(0); + $response = socket_read($client, 1024); + error_reporting($previousEr); if ($response && str_contains($response, 'HTTP/1.1 200 OK')) { ++$successfulConnections; } socket_close($client); + } else { + error_reporting($previousEr); } } posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); - if ($successfulConnections === 0) { + if (0 === $successfulConnections) { $this->markTestSkipped('No successful connections'); } diff --git a/tests/Integration/MasterHttpIntegrationTest.php b/tests/Integration/MasterHttpIntegrationTest.php index 13ded92..c690fd4 100644 --- a/tests/Integration/MasterHttpIntegrationTest.php +++ b/tests/Integration/MasterHttpIntegrationTest.php @@ -80,7 +80,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -90,7 +90,9 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - $connected = @socket_connect($client, '127.0.0.1', $port); + $previousEr = error_reporting(0); + $connected = socket_connect($client, '127.0.0.1', $port); + error_reporting($previousEr); if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; @@ -98,8 +100,10 @@ public function handle(mixed $clientSocket, array $metadata): void $response = ''; while (true) { - $chunk = @socket_read($client, 1024); - if ($chunk === false || $chunk === '') { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -157,7 +161,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -170,14 +174,20 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + $connected = socket_connect($client, '127.0.0.1', $port); + error_reporting($previousEr); + + if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; socket_write($client, $request); $response = ''; while (true) { - $chunk = @socket_read($client, 1024); - if ($chunk === false || $chunk === '') { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; diff --git a/tests/Integration/MasterLifecycleIntegrationTest.php b/tests/Integration/MasterLifecycleIntegrationTest.php index 40b5d6d..1a8a522 100644 --- a/tests/Integration/MasterLifecycleIntegrationTest.php +++ b/tests/Integration/MasterLifecycleIntegrationTest.php @@ -87,7 +87,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -97,7 +97,9 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - $connected = @socket_connect($client, '127.0.0.1', $port); + $previousEr = error_reporting(0); + $connected = socket_connect($client, '127.0.0.1', $port); + error_reporting($previousEr); if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; @@ -105,8 +107,10 @@ public function handle(mixed $clientSocket, array $metadata): void $response = ''; while (true) { - $chunk = @socket_read($client, 1024); - if ($chunk === false || $chunk === '') { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -165,7 +169,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } diff --git a/tests/Integration/WorkerCrashIntegrationTest.php b/tests/Integration/WorkerCrashIntegrationTest.php index 956c6c9..90e2829 100644 --- a/tests/Integration/WorkerCrashIntegrationTest.php +++ b/tests/Integration/WorkerCrashIntegrationTest.php @@ -144,7 +144,7 @@ public function handle(mixed $clientSocket, array $metadata): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { $master->start(); exit(0); } @@ -153,25 +153,38 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; - while ($chunk = @socket_read($client, 1024)) { + while (true) { + $previousEr = error_reporting(0); + $chunk = socket_read($client, 1024); + error_reporting($previousEr); + if (false === $chunk || '' === $chunk) { + break; + } $response .= $chunk; } socket_close($client); $this->assertStringContainsString('HTTP/1.1 200 OK', $response); + } else { + error_reporting($previousEr); } posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); - if (!@socket_connect($client, '127.0.0.1', $port)) { + $previousEr = error_reporting(0); + if (!socket_connect($client, '127.0.0.1', $port)) { + error_reporting($previousEr); $this->markTestSkipped('Could not connect to server'); } + error_reporting($previousEr); } private function findFreePort(): int diff --git a/tests/Integration/WorkerPoolNotificationIntegrationTest.php b/tests/Integration/WorkerPoolNotificationIntegrationTest.php index 5e58776..a90aded 100644 --- a/tests/Integration/WorkerPoolNotificationIntegrationTest.php +++ b/tests/Integration/WorkerPoolNotificationIntegrationTest.php @@ -150,7 +150,7 @@ public function run(int $workerId, ServerInterface $server): void public function shared_socket_master_notification_enabled_in_run_event_driven_worker_method(): void { $reflection = new ReflectionClass(SharedSocketMaster::class); - $method = $reflection->getMethod('runEventDrivenWorker'); + $reflection->getMethod('runEventDrivenWorker'); $source = file_get_contents(__DIR__ . '/../../src/Master/SharedSocketMaster.php'); @@ -163,7 +163,7 @@ public function shared_socket_master_notification_enabled_in_run_event_driven_wo public function centralized_master_notification_enabled_in_run_event_driven_worker_method(): void { $reflection = new ReflectionClass(CentralizedMaster::class); - $method = $reflection->getMethod('runEventDrivenWorker'); + $reflection->getMethod('runEventDrivenWorker'); $source = file_get_contents(__DIR__ . '/../../src/Master/CentralizedMaster.php'); diff --git a/tests/Unit/IPC/FdPasserCoverageTest.php b/tests/Unit/IPC/FdPasserCoverageTest.php index a95a663..3bba616 100644 --- a/tests/Unit/IPC/FdPasserCoverageTest.php +++ b/tests/Unit/IPC/FdPasserCoverageTest.php @@ -67,7 +67,7 @@ public function sendFdWithUnixSocketPair(): void socket_close($sock1); socket_close($sock2); if ($fdToSend instanceof Socket) { - @socket_close($fdToSend); + socket_close($fdToSend); } } diff --git a/tests/Unit/IPC/FdPasserFullCoverageTest.php b/tests/Unit/IPC/FdPasserFullCoverageTest.php index 8b0ad97..ac2e525 100644 --- a/tests/Unit/IPC/FdPasserFullCoverageTest.php +++ b/tests/Unit/IPC/FdPasserFullCoverageTest.php @@ -66,7 +66,9 @@ public function sendFdAttemptsToSend(): void socket_close($sender); socket_close($receiver); - @socket_close($fdToSend); + if ($fdToSend instanceof Socket) { + socket_close($fdToSend); + } } #[Test] @@ -83,7 +85,9 @@ public function sendFdWithEmptyMetadata(): void $this->assertIsBool($result); socket_close($sender); - @socket_close($fdToSend); + if ($fdToSend instanceof Socket) { + socket_close($fdToSend); + } } #[Test] @@ -114,6 +118,8 @@ public function sendFdReturnsBoolAfterAttempt(): void $this->assertIsBool($result); socket_close($sender); - @socket_close($fdToSend); + if ($fdToSend instanceof Socket) { + socket_close($fdToSend); + } } } diff --git a/tests/Unit/IPC/UnixSocketChannelTest.php b/tests/Unit/IPC/UnixSocketChannelTest.php index fe23e30..32f47c2 100644 --- a/tests/Unit/IPC/UnixSocketChannelTest.php +++ b/tests/Unit/IPC/UnixSocketChannelTest.php @@ -37,7 +37,7 @@ protected function tearDown(): void parent::tearDown(); if (file_exists($this->socketPath)) { - @unlink($this->socketPath); + unlink($this->socketPath); } } diff --git a/tests/Unit/IPC/UnixSocketChannelUnitTest.php b/tests/Unit/IPC/UnixSocketChannelUnitTest.php index aeb791a..5132d1e 100644 --- a/tests/Unit/IPC/UnixSocketChannelUnitTest.php +++ b/tests/Unit/IPC/UnixSocketChannelUnitTest.php @@ -47,7 +47,7 @@ protected function setUp(): void protected function tearDown(): void { if (file_exists($this->socketPath)) { - @unlink($this->socketPath); + unlink($this->socketPath); } parent::tearDown(); } diff --git a/tests/Unit/Master/CentralizedMasterCallbackTest.php b/tests/Unit/Master/CentralizedMasterCallbackTest.php index 683a5a0..4171f25 100644 --- a/tests/Unit/Master/CentralizedMasterCallbackTest.php +++ b/tests/Unit/Master/CentralizedMasterCallbackTest.php @@ -164,7 +164,7 @@ public function run_callback_worker_handles_null_callback(): void $runCallbackWorker = new ReflectionMethod($master, 'runCallbackWorker'); $runCallbackWorker->invoke($master, 1, $pair[0]); - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } #[Test] @@ -200,7 +200,7 @@ public function accept_connections_returns_early_without_socket_manager(): void $acceptConnections = new ReflectionMethod($master, 'acceptConnections'); $acceptConnections->invoke($master); - $this->assertTrue(true); + $this->assertTrue($master->isRunning()); } #[Test] @@ -236,6 +236,6 @@ public function distribute_connections_returns_early_without_queue(): void $distributeConnections = new ReflectionMethod($master, 'distributeConnections'); $distributeConnections->invoke($master); - $this->assertTrue(true); + $this->assertTrue($master->isRunning()); } } diff --git a/tests/Unit/Master/CentralizedMasterEventTest.php b/tests/Unit/Master/CentralizedMasterEventTest.php index 614cfe8..b843d95 100644 --- a/tests/Unit/Master/CentralizedMasterEventTest.php +++ b/tests/Unit/Master/CentralizedMasterEventTest.php @@ -140,7 +140,7 @@ public function run_event_driven_worker_creates_server_and_fiber(): void $runEventDrivenWorker->invoke($master, 1, $sockets[0]); - $this->assertTrue(true); + $this->assertNotNull($this->capturedServer); } #[Test] diff --git a/tests/Unit/Master/CentralizedMasterFdTest.php b/tests/Unit/Master/CentralizedMasterFdTest.php index 8c57de0..6e1541b 100644 --- a/tests/Unit/Master/CentralizedMasterFdTest.php +++ b/tests/Unit/Master/CentralizedMasterFdTest.php @@ -78,7 +78,7 @@ protected function setUp(): void #[Test] public function run_callback_worker_receives_fd_and_calls_handle(): void { - if (!function_exists('socket_sendmsg')) { + if (false === function_exists('socket_sendmsg')) { $this->markTestSkipped('socket_sendmsg not available'); } @@ -151,7 +151,7 @@ public function handle(mixed $clientSocket, array $metadata): void #[Test] public function run_callback_worker_no_callback_logs_warning(): void { - if (!function_exists('socket_sendmsg')) { + if (false === function_exists('socket_sendmsg')) { $this->markTestSkipped('socket_sendmsg not available'); } diff --git a/tests/Unit/Master/CentralizedMasterFullTest.php b/tests/Unit/Master/CentralizedMasterFullTest.php index 324d0fa..cda5254 100644 --- a/tests/Unit/Master/CentralizedMasterFullTest.php +++ b/tests/Unit/Master/CentralizedMasterFullTest.php @@ -265,7 +265,7 @@ public function accept_connections_skips_when_not_configured(): void $acceptConnections = new ReflectionMethod($master, 'acceptConnections'); $acceptConnections->invoke($master); - $this->assertTrue(true); + $this->assertTrue($master->isRunning()); } #[Test] @@ -289,7 +289,7 @@ public function distribute_connections_skips_when_no_queue(): void $distributeConnections = new ReflectionMethod($master, 'distributeConnections'); $distributeConnections->invoke($master); - $this->assertTrue(true); + $this->assertTrue($master->isRunning()); } #[Test] diff --git a/tests/Unit/Master/CentralizedMasterRestartTest.php b/tests/Unit/Master/CentralizedMasterRestartTest.php index 963e22b..b5cd836 100644 --- a/tests/Unit/Master/CentralizedMasterRestartTest.php +++ b/tests/Unit/Master/CentralizedMasterRestartTest.php @@ -261,7 +261,7 @@ public function accept_connections_queue_full_rejects(): void #[Test] public function run_event_driven_worker_receives_fd_in_fiber(): void { - if (!function_exists('socket_sendmsg')) { + if (false === function_exists('socket_sendmsg')) { $this->markTestSkipped('socket_sendmsg not available'); } diff --git a/tests/Unit/Master/CentralizedMasterStartTest.php b/tests/Unit/Master/CentralizedMasterStartTest.php index 19a7abf..4992634 100644 --- a/tests/Unit/Master/CentralizedMasterStartTest.php +++ b/tests/Unit/Master/CentralizedMasterStartTest.php @@ -417,7 +417,7 @@ public function distribute_connections_with_empty_queue(): void $distributeConnections = new ReflectionMethod($master, 'distributeConnections'); $distributeConnections->invoke($master); - $this->assertTrue(true); + $this->assertCount(0, $master->getWorkers()); } #[Test] diff --git a/tests/Unit/Master/CentralizedMasterTest.php b/tests/Unit/Master/CentralizedMasterTest.php index f3f2f09..1f5e5a1 100644 --- a/tests/Unit/Master/CentralizedMasterTest.php +++ b/tests/Unit/Master/CentralizedMasterTest.php @@ -89,7 +89,7 @@ public function creates_centralized_master_with_config(): void #[Group('pcntl')] public function spawns_configured_number_of_workers(): void { - if (!function_exists('pcntl_fork')) { + if (false === function_exists('pcntl_fork')) { $this->markTestSkipped('pcntl_fork not available'); } @@ -97,16 +97,16 @@ public function spawns_configured_number_of_workers(): void $pid = pcntl_fork(); - if ($pid === -1) { + if (-1 === $pid) { $this->fail('Failed to fork'); } - if ($pid === 0) { + if (0 === $pid) { sleep(1); exit(0); } - $this->assertTrue(true); + $this->assertGreaterThan(0, $pid); pcntl_waitpid($pid, $status); } @@ -129,7 +129,7 @@ public function stops_all_workers_on_stop(): void $master->stop(); - $this->assertTrue(true); + $this->assertFalse($master->isRunning()); } #[Test] diff --git a/tests/Unit/Master/ConnectionRouterTest.php b/tests/Unit/Master/ConnectionRouterTest.php index 93e8939..95a2762 100644 --- a/tests/Unit/Master/ConnectionRouterTest.php +++ b/tests/Unit/Master/ConnectionRouterTest.php @@ -57,7 +57,7 @@ public function route_returns_false_when_no_workers_available(): void { $clientSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if ($clientSocket === false) { + if (false === $clientSocket) { $this->markTestSkipped('Cannot create socket'); } @@ -75,7 +75,7 @@ public function route_returns_false_when_worker_socket_not_found(): void { $clientSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if ($clientSocket === false) { + if (false === $clientSocket) { $this->markTestSkipped('Cannot create socket'); } diff --git a/tests/Unit/Master/ConnectionRouterUnitTest.php b/tests/Unit/Master/ConnectionRouterUnitTest.php index f621138..0c791b8 100644 --- a/tests/Unit/Master/ConnectionRouterUnitTest.php +++ b/tests/Unit/Master/ConnectionRouterUnitTest.php @@ -114,7 +114,7 @@ public function get_balancer_returns_correct_instance(): void #[Test] public function route_passes_fd_to_alive_worker(): void { - if (!function_exists('socket_sendmsg') || !defined('SCM_RIGHTS')) { + if (false === function_exists('socket_sendmsg') || false === defined('SCM_RIGHTS')) { $this->markTestSkipped('SCM_RIGHTS not available'); } @@ -133,7 +133,7 @@ public function route_passes_fd_to_alive_worker(): void #[Test] public function route_returns_false_on_fd_pass_error(): void { - if (!function_exists('socket_sendmsg') || !defined('SCM_RIGHTS')) { + if (false === function_exists('socket_sendmsg') || false === defined('SCM_RIGHTS')) { $this->markTestSkipped('SCM_RIGHTS not available'); } diff --git a/tests/Unit/Master/NonBlockingRestartTest.php b/tests/Unit/Master/NonBlockingRestartTest.php index ccfd268..2f610cd 100644 --- a/tests/Unit/Master/NonBlockingRestartTest.php +++ b/tests/Unit/Master/NonBlockingRestartTest.php @@ -315,7 +315,6 @@ private function setPendingRestarts(TestableAbstractMaster $master, array $pendi $ref->setValue($master, $pending); } - /** @return array */ private function getPendingRestarts(TestableAbstractMaster $master): array { $ref = new ReflectionProperty(AbstractMaster::class, 'pendingRestarts'); @@ -331,7 +330,6 @@ private function callProcessPendingRestarts(TestableAbstractMaster $master): voi final class TestableAbstractMaster extends AbstractMaster { - /** @var list */ public array $spawnedWorkers = []; #[Override] diff --git a/tests/Unit/Master/SharedSocketMasterCallbackTest.php b/tests/Unit/Master/SharedSocketMasterCallbackTest.php index 2f85ff9..24b655a 100644 --- a/tests/Unit/Master/SharedSocketMasterCallbackTest.php +++ b/tests/Unit/Master/SharedSocketMasterCallbackTest.php @@ -162,7 +162,5 @@ public function run_event_driven_worker_with_null_worker_throws(): void $eventDrivenWorkerProp = new ReflectionProperty(AbstractMaster::class, 'eventDrivenWorker'); $this->assertNull($eventDrivenWorkerProp->getValue($master)); - - $this->assertTrue(true); } } diff --git a/tests/Unit/Master/SharedSocketMasterSocketTest.php b/tests/Unit/Master/SharedSocketMasterSocketTest.php index 7e195f2..977d2df 100644 --- a/tests/Unit/Master/SharedSocketMasterSocketTest.php +++ b/tests/Unit/Master/SharedSocketMasterSocketTest.php @@ -173,7 +173,7 @@ public function run_executes_one_iteration_then_exits(): void pcntl_signal(SIGALRM, SIG_DFL); - $this->assertTrue($master->isRunning() === false); + $this->assertFalse($master->isRunning()); } #[Test] diff --git a/tests/Unit/Master/SharedSocketMasterStartTest.php b/tests/Unit/Master/SharedSocketMasterStartTest.php index b3e66a1..221cf68 100644 --- a/tests/Unit/Master/SharedSocketMasterStartTest.php +++ b/tests/Unit/Master/SharedSocketMasterStartTest.php @@ -106,7 +106,7 @@ public function start_spawns_workers_and_runs(): void $uninstallSigchld = new ReflectionMethod(AbstractMaster::class, 'uninstallSigchldHandler'); $uninstallSigchld->invoke($master); - $this->assertTrue(true); + $this->expectNotToPerformAssertions(); } #[Test] diff --git a/tests/Unit/Master/SocketManagerCoverageTest.php b/tests/Unit/Master/SocketManagerCoverageTest.php index 2058853..2b17a31 100644 --- a/tests/Unit/Master/SocketManagerCoverageTest.php +++ b/tests/Unit/Master/SocketManagerCoverageTest.php @@ -77,7 +77,7 @@ public function disableAutoClosePreventsDestructorClose(): void unset($manager); - $this->assertTrue(true); + $this->assertNotNull($socket); } #[Test] @@ -121,7 +121,5 @@ public function destructorClosesSocket(): void $this->assertTrue($manager->isListening()); unset($manager); - - $this->assertTrue(true); } } diff --git a/tests/Unit/Master/SocketManagerTest.php b/tests/Unit/Master/SocketManagerTest.php index a223bc2..9333095 100644 --- a/tests/Unit/Master/SocketManagerTest.php +++ b/tests/Unit/Master/SocketManagerTest.php @@ -131,20 +131,22 @@ public function accepts_connection(): void socket_set_nonblock($clientSocket); - @socket_connect($clientSocket, $host, $port); + $previousEr = error_reporting(0); + socket_connect($clientSocket, $host, $port); + error_reporting($previousEr); usleep(10000); $accepted = $manager->accept(); - if ($accepted !== null) { + if (null !== $accepted) { socket_close($accepted); } socket_close($clientSocket); $manager->close(); - $this->assertTrue(true); + $this->assertFalse($manager->isListening()); } #[Test] @@ -173,8 +175,6 @@ public function cleans_up_on_destruct(): void $this->assertNotNull($socket); unset($manager); - - $this->assertTrue(true); } private function findFreePort(): int diff --git a/tests/Unit/Master/WorkerManagerUnitTest.php b/tests/Unit/Master/WorkerManagerUnitTest.php index a6b75d7..8512a3f 100644 --- a/tests/Unit/Master/WorkerManagerUnitTest.php +++ b/tests/Unit/Master/WorkerManagerUnitTest.php @@ -228,6 +228,6 @@ public function spawn_child_path_executes_callback_and_exits(): void $this->assertFileExists($tempFile); $this->assertSame('callback_executed', file_get_contents($tempFile)); - @unlink($tempFile); + unlink($tempFile); } } diff --git a/tests/Unit/Signal/SignalManagerTest.php b/tests/Unit/Signal/SignalManagerTest.php index ab28cb5..6fc14de 100644 --- a/tests/Unit/Signal/SignalManagerTest.php +++ b/tests/Unit/Signal/SignalManagerTest.php @@ -51,7 +51,7 @@ protected function tearDown(): void #[Test] public function sets_up_master_signals(): void { - if (!$this->handler->isSignalsSupported()) { + if (false === $this->handler->isSignalsSupported()) { $this->markTestSkipped('Signals not supported'); } @@ -75,7 +75,7 @@ public function sets_up_master_signals(): void #[Test] public function sets_up_worker_signals(): void { - if (!$this->handler->isSignalsSupported()) { + if (false === $this->handler->isSignalsSupported()) { $this->markTestSkipped('Signals not supported'); } @@ -120,7 +120,7 @@ public function tracks_reload_request(): void #[Test] public function resets_signal_handlers(): void { - if (!$this->handler->isSignalsSupported()) { + if (false === $this->handler->isSignalsSupported()) { $this->markTestSkipped('Signals not supported'); } @@ -141,7 +141,7 @@ public function resets_signal_handlers(): void #[Test] public function resets_only_flags(): void { - if (!$this->handler->isSignalsSupported()) { + if (false === $this->handler->isSignalsSupported()) { $this->markTestSkipped('Signals not supported'); } @@ -162,13 +162,13 @@ public function dispatch_calls_handler_dispatch(): void { $this->manager->dispatch(); - $this->assertTrue(true); + $this->assertFalse($this->manager->isShutdownRequested()); } #[Test] public function handles_multiple_setups(): void { - if (!$this->handler->isSignalsSupported()) { + if (false === $this->handler->isSignalsSupported()) { $this->markTestSkipped('Signals not supported'); } diff --git a/tests/Unit/Socket/SocketWrapperTest.php b/tests/Unit/Socket/SocketWrapperTest.php index bc77aaf..5478b54 100644 --- a/tests/Unit/Socket/SocketWrapperTest.php +++ b/tests/Unit/Socket/SocketWrapperTest.php @@ -230,8 +230,6 @@ public function closes_socket_without_error(): void $this->assertInstanceOf(Socket::class, $socket); $this->wrapper->close($socket); - - $this->assertTrue(true); } #[Test] @@ -242,8 +240,6 @@ public function sets_nonblocking_mode(): void $this->wrapper->setNonBlock($socket); - $this->assertTrue(true); - socket_close($socket); } diff --git a/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php b/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php index a380aa2..4bc1e1c 100644 --- a/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php +++ b/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php @@ -75,15 +75,13 @@ public function __construct( public function run(int $workerId, ServerInterface $server): void { - // NOTE: Do NOT call $server->start() in Worker Pool mode! - // Server is marked as running when setWorkerId() is called. $this->hasRequestCalled = $server->hasRequest(); } }; $config = new ServerConfig(host: '127.0.0.1', port: 8081); $this->server = new Server($config); - $this->server->setWorkerId(1); // This marks server as running + $this->server->setWorkerId(1); $worker->run(1, $this->server); @@ -108,7 +106,6 @@ public function run(int $workerId, ServerInterface $server): void $config = new ServerConfig(host: '127.0.0.1', port: 8082); - // Simulate multiple workers for ($i = 1; $i <= 5; $i++) { if (null !== $this->server) { $this->server->reset(); @@ -161,15 +158,11 @@ public function __construct( public function run(int $workerId, ServerInterface $server): void { - // Just verify we can call server methods without errors - // NOTE: Do NOT call $server->start() in Worker Pool mode! - - // Check for requests (none expected in this test) $hasRequest = $server->hasRequest(); if ($hasRequest) { $request = $server->getRequest(); - if ($request !== null) { + if (null !== $request) { $response = new Response(200, [], 'OK'); $server->respond($response); $this->requestHandled = true; @@ -180,12 +173,10 @@ public function run(int $workerId, ServerInterface $server): void $config = new ServerConfig(host: '127.0.0.1', port: 8084); $this->server = new Server($config); - $this->server->setWorkerId(1); // Mark as running in Worker Pool mode + $this->server->setWorkerId(1); $worker->run(1, $this->server); - // Request was not handled because we didn't send any - // This is just testing the interface works correctly $this->assertFalse($requestHandled); } diff --git a/tests/Unit/Worker/HttpWorkerAdapterCoverageTest.php b/tests/Unit/Worker/HttpWorkerAdapterCoverageTest.php index b841830..05d9c63 100644 --- a/tests/Unit/Worker/HttpWorkerAdapterCoverageTest.php +++ b/tests/Unit/Worker/HttpWorkerAdapterCoverageTest.php @@ -55,7 +55,7 @@ public function handleConnectionWithValidGetRequest(): void $start = microtime(true); while (microtime(true) - $start < 1.0) { $chunk = socket_read($clientSocket, 4096); - if ($chunk === false || $chunk === '') { + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -86,7 +86,7 @@ public function handleConnectionWithPostRequest(): void $start = microtime(true); while (microtime(true) - $start < 1.0) { $chunk = socket_read($clientSocket, 4096); - if ($chunk === false || $chunk === '') { + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -114,7 +114,7 @@ public function handleConnectionWithMetadata(): void $start = microtime(true); while (microtime(true) - $start < 1.0) { $chunk = socket_read($clientSocket, 4096); - if ($chunk === false || $chunk === '') { + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -142,7 +142,7 @@ public function handleConnectionWithMultipleHeaders(): void $start = microtime(true); while (microtime(true) - $start < 1.0) { $chunk = socket_read($clientSocket, 4096); - if ($chunk === false || $chunk === '') { + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; @@ -169,7 +169,7 @@ public function handleConnectionWithIncompleteHeaders(): void $start = microtime(true); while (microtime(true) - $start < 1.0) { $chunk = socket_read($clientSocket, 4096); - if ($chunk === false || $chunk === '') { + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; diff --git a/tests/Unit/Worker/HttpWorkerAdapterTest.php b/tests/Unit/Worker/HttpWorkerAdapterTest.php index 7ce98c1..62a41f9 100644 --- a/tests/Unit/Worker/HttpWorkerAdapterTest.php +++ b/tests/Unit/Worker/HttpWorkerAdapterTest.php @@ -60,7 +60,7 @@ public function handles_simple_http_request(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); try { @@ -75,13 +75,15 @@ public function handles_simple_http_request(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); @@ -111,7 +113,7 @@ public function reads_request_with_body(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -120,13 +122,15 @@ public function reads_request_with_body(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -145,7 +149,7 @@ public function closes_socket_after_handling(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -155,12 +159,14 @@ public function closes_socket_after_handling(): void sleep(1); - $read = @socket_read($clientSocket, 1); + $previousEr = error_reporting(0); + socket_read($clientSocket, 1); + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); - $this->assertTrue(true); + $this->assertTrue(pcntl_wifexited($status)); } #[Test] @@ -173,7 +179,7 @@ public function handles_empty_request(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -182,13 +188,15 @@ public function handles_empty_request(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -207,7 +215,7 @@ public function handles_invalid_http_request(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -216,13 +224,15 @@ public function handles_invalid_http_request(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -247,7 +257,7 @@ public function handles_request_with_metadata(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, $metadata); exit(0); @@ -256,13 +266,15 @@ public function handles_request_with_metadata(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -289,7 +301,7 @@ public function handles_request_with_multiple_headers(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -298,13 +310,15 @@ public function handles_request_with_multiple_headers(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -332,7 +346,7 @@ public function handles_chunked_request_body(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -341,13 +355,15 @@ public function handles_chunked_request_body(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -366,7 +382,7 @@ public function handles_partial_headers(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -375,13 +391,15 @@ public function handles_partial_headers(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -399,7 +417,7 @@ public function handles_malformed_request_line(): void $pid = pcntl_fork(); - if ($pid === 0) { + if (0 === $pid) { socket_close($clientSocket); $this->adapter->handleConnection($serverSocket, []); exit(0); @@ -408,13 +426,15 @@ public function handles_malformed_request_line(): void socket_close($serverSocket); $response = ''; + $previousEr = error_reporting(0); while (true) { - $chunk = @socket_read($clientSocket, 1024); - if ($chunk === false || $chunk === '') { + $chunk = socket_read($clientSocket, 1024); + if (false === $chunk || '' === $chunk) { break; } $response .= $chunk; } + error_reporting($previousEr); socket_close($clientSocket); pcntl_waitpid($pid, $status); From 57d2e4fa5d7b79a5d3d08590a92fbfb2f8e2ac7a Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 16:26:52 +1000 Subject: [PATCH 3/8] chore: Fix after rector --- tests/Integration/CentralizedMasterCoverageTest.php | 2 +- tests/Integration/CentralizedMasterSocketResourceTest.php | 2 +- tests/Integration/ConcurrencyIntegrationTest.php | 2 +- tests/Integration/ForkBasedMasterTest.php | 2 +- tests/Integration/LoadBalancingIntegrationTest.php | 2 +- tests/Integration/MasterHttpIntegrationTest.php | 2 +- tests/Integration/MasterLifecycleIntegrationTest.php | 2 +- tests/Integration/SharedSocketMasterCoverageTest.php | 2 +- tests/Integration/SharedSocketMasterSocketResourceTest.php | 2 +- tests/Integration/WorkerCrashIntegrationTest.php | 2 +- tests/Integration/WorkerPoolNotificationIntegrationTest.php | 2 +- tests/Performance/ThroughputBaselineTest.php | 2 +- tests/Unit/Master/CentralizedMasterEventTest.php | 2 +- tests/Unit/Master/CentralizedMasterRestartTest.php | 2 +- tests/Unit/Master/SharedSocketMasterEventTest.php | 2 +- tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php | 2 +- tests/Unit/Worker/HttpWorkerAdapterTest.php | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/Integration/CentralizedMasterCoverageTest.php b/tests/Integration/CentralizedMasterCoverageTest.php index 99e0786..edab045 100644 --- a/tests/Integration/CentralizedMasterCoverageTest.php +++ b/tests/Integration/CentralizedMasterCoverageTest.php @@ -65,7 +65,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/CentralizedMasterSocketResourceTest.php b/tests/Integration/CentralizedMasterSocketResourceTest.php index e6a8211..ed1b3cb 100644 --- a/tests/Integration/CentralizedMasterSocketResourceTest.php +++ b/tests/Integration/CentralizedMasterSocketResourceTest.php @@ -54,7 +54,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/ConcurrencyIntegrationTest.php b/tests/Integration/ConcurrencyIntegrationTest.php index 9570d37..48b2e90 100644 --- a/tests/Integration/ConcurrencyIntegrationTest.php +++ b/tests/Integration/ConcurrencyIntegrationTest.php @@ -35,7 +35,7 @@ final class ConcurrencyIntegrationTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/ForkBasedMasterTest.php b/tests/Integration/ForkBasedMasterTest.php index e55aff8..199e4c6 100644 --- a/tests/Integration/ForkBasedMasterTest.php +++ b/tests/Integration/ForkBasedMasterTest.php @@ -61,7 +61,7 @@ final class ForkBasedMasterTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/LoadBalancingIntegrationTest.php b/tests/Integration/LoadBalancingIntegrationTest.php index 52aa8a5..e152d13 100644 --- a/tests/Integration/LoadBalancingIntegrationTest.php +++ b/tests/Integration/LoadBalancingIntegrationTest.php @@ -34,7 +34,7 @@ final class LoadBalancingIntegrationTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/MasterHttpIntegrationTest.php b/tests/Integration/MasterHttpIntegrationTest.php index c690fd4..84d16e9 100644 --- a/tests/Integration/MasterHttpIntegrationTest.php +++ b/tests/Integration/MasterHttpIntegrationTest.php @@ -38,7 +38,7 @@ class MasterHttpIntegrationTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/MasterLifecycleIntegrationTest.php b/tests/Integration/MasterLifecycleIntegrationTest.php index 1a8a522..4fcb838 100644 --- a/tests/Integration/MasterLifecycleIntegrationTest.php +++ b/tests/Integration/MasterLifecycleIntegrationTest.php @@ -33,7 +33,7 @@ final class MasterLifecycleIntegrationTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/SharedSocketMasterCoverageTest.php b/tests/Integration/SharedSocketMasterCoverageTest.php index 0273d35..6a6bade 100644 --- a/tests/Integration/SharedSocketMasterCoverageTest.php +++ b/tests/Integration/SharedSocketMasterCoverageTest.php @@ -54,7 +54,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/SharedSocketMasterSocketResourceTest.php b/tests/Integration/SharedSocketMasterSocketResourceTest.php index de96c5f..f8670de 100644 --- a/tests/Integration/SharedSocketMasterSocketResourceTest.php +++ b/tests/Integration/SharedSocketMasterSocketResourceTest.php @@ -42,7 +42,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/WorkerCrashIntegrationTest.php b/tests/Integration/WorkerCrashIntegrationTest.php index 90e2829..25f7e3d 100644 --- a/tests/Integration/WorkerCrashIntegrationTest.php +++ b/tests/Integration/WorkerCrashIntegrationTest.php @@ -33,7 +33,7 @@ final class WorkerCrashIntegrationTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Integration/WorkerPoolNotificationIntegrationTest.php b/tests/Integration/WorkerPoolNotificationIntegrationTest.php index a90aded..2287c8b 100644 --- a/tests/Integration/WorkerPoolNotificationIntegrationTest.php +++ b/tests/Integration/WorkerPoolNotificationIntegrationTest.php @@ -58,7 +58,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Performance/ThroughputBaselineTest.php b/tests/Performance/ThroughputBaselineTest.php index 19120d0..1c744b6 100644 --- a/tests/Performance/ThroughputBaselineTest.php +++ b/tests/Performance/ThroughputBaselineTest.php @@ -39,7 +39,7 @@ final class ThroughputBaselineTest extends TestCase #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Unit/Master/CentralizedMasterEventTest.php b/tests/Unit/Master/CentralizedMasterEventTest.php index b843d95..e7855c8 100644 --- a/tests/Unit/Master/CentralizedMasterEventTest.php +++ b/tests/Unit/Master/CentralizedMasterEventTest.php @@ -92,7 +92,7 @@ protected function tearDown(): void $this->capturedServer->reset(); $this->capturedServer = null; } - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Unit/Master/CentralizedMasterRestartTest.php b/tests/Unit/Master/CentralizedMasterRestartTest.php index b5cd836..715fe02 100644 --- a/tests/Unit/Master/CentralizedMasterRestartTest.php +++ b/tests/Unit/Master/CentralizedMasterRestartTest.php @@ -346,6 +346,6 @@ public function run(int $workerId, ServerInterface $server): void if (null !== $eventWorker->capturedServer) { $eventWorker->capturedServer->reset(); } - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); } } diff --git a/tests/Unit/Master/SharedSocketMasterEventTest.php b/tests/Unit/Master/SharedSocketMasterEventTest.php index ca00900..0c56dc5 100644 --- a/tests/Unit/Master/SharedSocketMasterEventTest.php +++ b/tests/Unit/Master/SharedSocketMasterEventTest.php @@ -71,7 +71,7 @@ protected function tearDown(): void $this->capturedServer->reset(); $this->capturedServer = null; } - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php b/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php index 4bc1e1c..2b9dd98 100644 --- a/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php +++ b/tests/Unit/Worker/EventDrivenWorkerInterfaceTest.php @@ -33,7 +33,7 @@ protected function tearDown(): void } catch (Throwable) { } } - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } diff --git a/tests/Unit/Worker/HttpWorkerAdapterTest.php b/tests/Unit/Worker/HttpWorkerAdapterTest.php index 62a41f9..ab71a9e 100644 --- a/tests/Unit/Worker/HttpWorkerAdapterTest.php +++ b/tests/Unit/Worker/HttpWorkerAdapterTest.php @@ -39,7 +39,7 @@ protected function setUp(): void #[Override] protected function tearDown(): void { - (new ErrorHandler(new NullLogger()))->reset(); + new ErrorHandler(new NullLogger())->reset(); parent::tearDown(); } From 27c5cdae602d63ac882ecfb8c07a2478b06077e3 Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 16:33:52 +1000 Subject: [PATCH 4/8] refactor: rename $previousEr to $previousErrorReporting in integration tests --- .../ConcurrencyIntegrationTest.php | 30 +++++++++---------- .../LoadBalancingIntegrationTest.php | 20 ++++++------- .../Integration/MasterHttpIntegrationTest.php | 16 +++++----- .../MasterLifecycleIntegrationTest.php | 8 ++--- .../WorkerCrashIntegrationTest.php | 16 +++++----- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/Integration/ConcurrencyIntegrationTest.php b/tests/Integration/ConcurrencyIntegrationTest.php index 48b2e90..f44f3c3 100644 --- a/tests/Integration/ConcurrencyIntegrationTest.php +++ b/tests/Integration/ConcurrencyIntegrationTest.php @@ -105,18 +105,18 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $concurrentRequests; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_set_nonblock($client); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; $attempts = 0; while ($attempts < 100) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($chunk) { $response .= $chunk; } @@ -133,7 +133,7 @@ public function handle(mixed $clientSocket, array $metadata): void socket_close($client); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } usleep(5000); @@ -213,16 +213,16 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < 4; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } @@ -235,7 +235,7 @@ public function handle(mixed $clientSocket, array $metadata): void socket_close($client); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } usleep(50000); @@ -303,13 +303,13 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < 50; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_write($client, "GET / HTTP/1.1\r\n\r\n"); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $response = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($response && str_contains($response, 'HTTP')) { ++$successCount; @@ -317,7 +317,7 @@ public function handle(mixed $clientSocket, array $metadata): void socket_close($client); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } } diff --git a/tests/Integration/LoadBalancingIntegrationTest.php b/tests/Integration/LoadBalancingIntegrationTest.php index e152d13..f895457 100644 --- a/tests/Integration/LoadBalancingIntegrationTest.php +++ b/tests/Integration/LoadBalancingIntegrationTest.php @@ -101,16 +101,16 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $requestCount; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } @@ -119,7 +119,7 @@ public function handle(mixed $clientSocket, array $metadata): void $responses[] = $response; socket_close($client); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } usleep(10000); @@ -210,21 +210,21 @@ public function handle(mixed $clientSocket, array $metadata): void for ($i = 0; $i < $concurrentRequests; $i++) { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $response = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($response && str_contains($response, 'HTTP/1.1 200 OK')) { ++$successfulConnections; } socket_close($client); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } } diff --git a/tests/Integration/MasterHttpIntegrationTest.php b/tests/Integration/MasterHttpIntegrationTest.php index 84d16e9..b097775 100644 --- a/tests/Integration/MasterHttpIntegrationTest.php +++ b/tests/Integration/MasterHttpIntegrationTest.php @@ -90,9 +90,9 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $connected = socket_connect($client, '127.0.0.1', $port); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; @@ -100,9 +100,9 @@ public function handle(mixed $clientSocket, array $metadata): void $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } @@ -174,9 +174,9 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $connected = socket_connect($client, '127.0.0.1', $port); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; @@ -184,9 +184,9 @@ public function handle(mixed $clientSocket, array $metadata): void $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } diff --git a/tests/Integration/MasterLifecycleIntegrationTest.php b/tests/Integration/MasterLifecycleIntegrationTest.php index 4fcb838..a6a9abc 100644 --- a/tests/Integration/MasterLifecycleIntegrationTest.php +++ b/tests/Integration/MasterLifecycleIntegrationTest.php @@ -97,9 +97,9 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->assertNotFalse($client); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $connected = socket_connect($client, '127.0.0.1', $port); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if ($connected) { $request = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"; @@ -107,9 +107,9 @@ public function handle(mixed $clientSocket, array $metadata): void $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } diff --git a/tests/Integration/WorkerCrashIntegrationTest.php b/tests/Integration/WorkerCrashIntegrationTest.php index 25f7e3d..bb94aab 100644 --- a/tests/Integration/WorkerCrashIntegrationTest.php +++ b/tests/Integration/WorkerCrashIntegrationTest.php @@ -153,16 +153,16 @@ public function handle(mixed $clientSocket, array $metadata): void $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_write($client, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); $response = ''; while (true) { - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); $chunk = socket_read($client, 1024); - error_reporting($previousEr); + error_reporting($previousErrorReporting); if (false === $chunk || '' === $chunk) { break; } @@ -173,18 +173,18 @@ public function handle(mixed $clientSocket, array $metadata): void $this->assertStringContainsString('HTTP/1.1 200 OK', $response); } else { - error_reporting($previousEr); + error_reporting($previousErrorReporting); } posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); if (!socket_connect($client, '127.0.0.1', $port)) { - error_reporting($previousEr); + error_reporting($previousErrorReporting); $this->markTestSkipped('Could not connect to server'); } - error_reporting($previousEr); + error_reporting($previousErrorReporting); } private function findFreePort(): int From e81e461a992d2ba02ec0cea0b220017ca196afe7 Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 16:34:08 +1000 Subject: [PATCH 5/8] refactor: rename $previousEr to $previousErrorReporting in unit tests --- tests/Unit/Master/SocketManagerTest.php | 4 +-- tests/Unit/Worker/HttpWorkerAdapterTest.php | 40 ++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/Unit/Master/SocketManagerTest.php b/tests/Unit/Master/SocketManagerTest.php index 9333095..6b6fa94 100644 --- a/tests/Unit/Master/SocketManagerTest.php +++ b/tests/Unit/Master/SocketManagerTest.php @@ -131,9 +131,9 @@ public function accepts_connection(): void socket_set_nonblock($clientSocket); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); socket_connect($clientSocket, $host, $port); - error_reporting($previousEr); + error_reporting($previousErrorReporting); usleep(10000); diff --git a/tests/Unit/Worker/HttpWorkerAdapterTest.php b/tests/Unit/Worker/HttpWorkerAdapterTest.php index ab71a9e..c1b6955 100644 --- a/tests/Unit/Worker/HttpWorkerAdapterTest.php +++ b/tests/Unit/Worker/HttpWorkerAdapterTest.php @@ -75,7 +75,7 @@ public function handles_simple_http_request(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -83,7 +83,7 @@ public function handles_simple_http_request(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); @@ -122,7 +122,7 @@ public function reads_request_with_body(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -130,7 +130,7 @@ public function reads_request_with_body(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -159,9 +159,9 @@ public function closes_socket_after_handling(): void sleep(1); - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); socket_read($clientSocket, 1); - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -188,7 +188,7 @@ public function handles_empty_request(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -196,7 +196,7 @@ public function handles_empty_request(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -224,7 +224,7 @@ public function handles_invalid_http_request(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -232,7 +232,7 @@ public function handles_invalid_http_request(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -266,7 +266,7 @@ public function handles_request_with_metadata(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -274,7 +274,7 @@ public function handles_request_with_metadata(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -310,7 +310,7 @@ public function handles_request_with_multiple_headers(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -318,7 +318,7 @@ public function handles_request_with_multiple_headers(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -355,7 +355,7 @@ public function handles_chunked_request_body(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -363,7 +363,7 @@ public function handles_chunked_request_body(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -391,7 +391,7 @@ public function handles_partial_headers(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -399,7 +399,7 @@ public function handles_partial_headers(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); @@ -426,7 +426,7 @@ public function handles_malformed_request_line(): void socket_close($serverSocket); $response = ''; - $previousEr = error_reporting(0); + $previousErrorReporting = error_reporting(0); while (true) { $chunk = socket_read($clientSocket, 1024); if (false === $chunk || '' === $chunk) { @@ -434,7 +434,7 @@ public function handles_malformed_request_line(): void } $response .= $chunk; } - error_reporting($previousEr); + error_reporting($previousErrorReporting); socket_close($clientSocket); pcntl_waitpid($pid, $status); From 68e6567df1a46d4c8e4118beded7d3772c054951 Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 19:27:11 +1000 Subject: [PATCH 6/8] refactor: remove excessive debug logging from FdPasser - Removed 6 debug-level logger calls from IPC module - Sorted function imports alphabetically - Error-level logging preserved for all failure cases --- src/IPC/FdPasser.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/IPC/FdPasser.php b/src/IPC/FdPasser.php index 6fbe240..63f5820 100644 --- a/src/IPC/FdPasser.php +++ b/src/IPC/FdPasser.php @@ -13,15 +13,14 @@ use Socket; use function array_key_exists; +use function assert; use function defined; use function function_exists; use function gettype; use function is_array; use function is_resource; -use function strlen; - -use function assert; use function is_string; +use function strlen; use const JSON_THROW_ON_ERROR; use const MSG_DONTWAIT; @@ -56,8 +55,6 @@ public function sendFd(Socket $controlSocket, Socket $fdToSend, array $metadata throw new IPCException('SCM_RIGHTS is not defined'); } - $this->logger->debug('Sending FD with metadata', ['metadata' => $metadata]); - $metadataJson = json_encode($metadata, JSON_THROW_ON_ERROR); if ('[]' === $metadataJson) { $metadataJson = '{}'; @@ -80,8 +77,6 @@ public function sendFd(Socket $controlSocket, Socket $fdToSend, array $metadata $this->logger->error('sendmsg failed', [ 'error' => $this->socketWrapper->strerror($this->socketWrapper->lastError($controlSocket)), ]); - } else { - $this->logger->debug('FD sent', ['bytes' => $result]); } return false !== $result; @@ -123,11 +118,6 @@ public function receiveFd(Socket $controlSocket): ?array return null; } - $this->logger->debug('recvmsg returned bytes', ['bytes' => $result]); - $this->logger->debug('Message type', ['type' => gettype($message)]); - - $this->logger->debug('Message keys', ['keys' => array_keys($message)]); - assert(is_array($message['control'])); if (!array_key_exists(0, $message['control'])) { @@ -178,8 +168,6 @@ public function receiveFd(Socket $controlSocket): ?array $metadata = []; } - $this->logger->debug('FD received successfully', ['metadata' => $metadata]); - return [ 'fd' => $receivedFd, 'metadata' => $metadata, From 8adb1e18c5f56b218808d5082dffb3b236429882 Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 19:27:22 +1000 Subject: [PATCH 7/8] refactor: remove delegation overrides and consolidate signal handlers in masters - Removed stop() overrides that only called parent::stop() - Consolidated duplicate SIGTERM/SIGINT closures into shared variable - Removed redundant try/catch that only logged and re-threw - Removed non-functional 'note' key from debug log context --- src/Master/CentralizedMaster.php | 16 ++++------------ src/Master/SharedSocketMaster.php | 22 +++++----------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/Master/CentralizedMaster.php b/src/Master/CentralizedMaster.php index 2c88e25..71cb07f 100644 --- a/src/Master/CentralizedMaster.php +++ b/src/Master/CentralizedMaster.php @@ -86,12 +86,6 @@ public function start(): void $this->run(); } - #[Override] - public function stop(): void - { - parent::stop(); - } - #[Override] public function getMetrics(): array { @@ -309,7 +303,6 @@ private function runEventDrivenWorker(int $workerId, Socket $workerSocket): void $this->logger->debug('External socket resource set for worker', [ 'worker_id' => $workerId, 'mode' => 'centralized', - 'note' => 'Unix socket for IPC - EvTimer fallback recommended', ]); $server->enableNotification(); @@ -355,13 +348,12 @@ private function runCallbackWorker(int $workerId, Socket $workerSocket): void { $workerShouldStop = false; - pcntl_signal(SIGTERM, function () use (&$workerShouldStop): void { + $signalHandler = function () use (&$workerShouldStop): void { $workerShouldStop = true; - }); + }; - pcntl_signal(SIGINT, function () use (&$workerShouldStop): void { - $workerShouldStop = true; - }); + pcntl_signal(SIGTERM, $signalHandler); + pcntl_signal(SIGINT, $signalHandler); $this->logger->info('Worker entering receive loop', ['worker_id' => $workerId]); diff --git a/src/Master/SharedSocketMaster.php b/src/Master/SharedSocketMaster.php index 63fb699..a3e4d4a 100644 --- a/src/Master/SharedSocketMaster.php +++ b/src/Master/SharedSocketMaster.php @@ -60,12 +60,6 @@ public function start(): void $this->run(); } - #[Override] - public function stop(): void - { - parent::stop(); - } - #[Override] public function getMetrics(): array { @@ -222,20 +216,14 @@ private function runCallbackWorker(int $workerId): void $workerShouldStop = false; - pcntl_signal(SIGTERM, function () use (&$workerShouldStop): void { + $signalHandler = function () use (&$workerShouldStop): void { $workerShouldStop = true; - }); + }; - pcntl_signal(SIGINT, function () use (&$workerShouldStop): void { - $workerShouldStop = true; - }); + pcntl_signal(SIGTERM, $signalHandler); + pcntl_signal(SIGINT, $signalHandler); - try { - $socket = $this->createReusePortSocket($workerId); - } catch (WorkerPoolException $e) { - $this->logger->error($e->getMessage(), ['worker_id' => $workerId]); - throw $e; - } + $socket = $this->createReusePortSocket($workerId); $this->logger->info('Worker listening', [ 'worker_id' => $workerId, From 07fc546a76908c6101b95c2cfeb28ce0e13bc37a Mon Sep 17 00:00:00 2001 From: Mikhail Ilinsky Date: Fri, 22 May 2026 19:27:34 +1000 Subject: [PATCH 8/8] refactor: fix code style and clean up PHPDoc in worker and signal modules - SignalHandler: apply Yoda style for isset(), eliminate redundant check - EventDrivenWorkerInterface: simplify redundant parameter descriptions - HttpWorkerAdapter: sort function imports into single alphabetical block --- src/Signal/SignalHandler.php | 4 ++-- src/Worker/EventDrivenWorkerInterface.php | 6 +----- src/Worker/HttpWorkerAdapter.php | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Signal/SignalHandler.php b/src/Signal/SignalHandler.php index bc75cc5..09a8a4f 100644 --- a/src/Signal/SignalHandler.php +++ b/src/Signal/SignalHandler.php @@ -23,9 +23,9 @@ final class SignalHandler public function register(int $signal, Closure $handler): void { - $needsInstall = !isset($this->handlers[$signal]); + $needsInstall = false === isset($this->handlers[$signal]); - if (false === isset($this->handlers[$signal])) { + if ($needsInstall) { $this->handlers[$signal] = []; } diff --git a/src/Worker/EventDrivenWorkerInterface.php b/src/Worker/EventDrivenWorkerInterface.php index 5199581..184dfbe 100644 --- a/src/Worker/EventDrivenWorkerInterface.php +++ b/src/Worker/EventDrivenWorkerInterface.php @@ -114,12 +114,8 @@ interface EventDrivenWorkerInterface * * @param int $workerId Worker ID (1, 2, 3, ..., N) * @param ServerInterface $server Server instance for Worker Pool interaction - * - hasRequest() - check for requests - * - getRequest() - get next request - * - respond() - send response - * - hasPendingResponse() - check for pending responses * - * @return void (never returns - infinite loop inside) + * @return void */ public function run(int $workerId, ServerInterface $server): void; } diff --git a/src/Worker/HttpWorkerAdapter.php b/src/Worker/HttpWorkerAdapter.php index f5eefcb..12ac377 100644 --- a/src/Worker/HttpWorkerAdapter.php +++ b/src/Worker/HttpWorkerAdapter.php @@ -14,13 +14,12 @@ use Socket; use Throwable; +use function assert; use function count; +use function is_string; use function sprintf; use function strlen; -use function assert; -use function is_string; - use const SOL_SOCKET; use const SO_RCVTIMEO; use const SO_SNDTIMEO;