From be7554ba28e84f3cd329322fce6462f4126ca868 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Sun, 11 Oct 2026 05:14:11 -0400 Subject: [PATCH] Fix server constructor syntax for PHP 8.2 and 8.3 --- .github/workflows/main.yml | 5 ++++- README.md | 7 ++++++- scripts/lint.php | 26 ++++++++++++++++++++++++++ src/VerifierServer/Server.php | 4 ++-- tests/isolated/ServerLoadingTest.php | 26 ++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 scripts/lint.php create mode 100644 tests/isolated/ServerLoadingTest.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da21c31..a74f760 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.2', '8.4'] + php: ['8.2', '8.3', '8.4', '8.5'] steps: - name: Checkout code @@ -45,5 +45,8 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest + - name: Lint package source and entry points + run: php scripts/lint.php + - name: Run tests run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/isolated diff --git a/README.md b/README.md index 6a74fe6..43466da 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,14 @@ This project is licensed under the MIT License. ## Offline verification checks +Run `php scripts/lint.php` to parse all package source, entry points, scripts, and tests. +CI checks PHP 8.2, 8.3, 8.4, and 8.5. + Run `php vendor/bin/phpunit --bootstrap vendor/autoload.php tests/isolated`. These contract tests inject storage that never writes files or opens databases; -they do not load `.env`, start the server, or contact verification services. +they do not load `.env`, bind a listening socket, or contact verification services. +A server loading test constructs the server and routes a synthetic request without +initializing its network listener. The older tests outside this directory use configured storage and are not run by CI. Run `php -d xdebug.mode=off scripts/benchmark_lookups.php` for a synthetic diff --git a/scripts/lint.php b/scripts/lint.php new file mode 100644 index 0000000..402ded0 --- /dev/null +++ b/scripts/lint.php @@ -0,0 +1,26 @@ +isFile() && $file->getExtension() === 'php') $paths[] = $file->getPathname(); + } +} +sort($paths); +foreach ($paths as $path) { + $process = proc_open([PHP_BINARY, '-l', $path], [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + if (!is_resource($process)) throw new RuntimeException('Could not start PHP lint'); + $output = stream_get_contents($pipes[1]); + $error = stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + $status = proc_close($process); + if ($status !== 0) { + fwrite(STDERR, $output . $error); + exit($status); + } +} +printf("Parsed %d PHP files with PHP %s.\n", count($paths), PHP_VERSION); diff --git a/src/VerifierServer/Server.php b/src/VerifierServer/Server.php index 04a4e6f..e3d525a 100644 --- a/src/VerifierServer/Server.php +++ b/src/VerifierServer/Server.php @@ -174,12 +174,12 @@ private function __initStreamSocketServer(): void */ private function __initReactHttpServer(?LoopInterface $loop = null): void { - $this->server = new HttpServer( + $this->server = (new HttpServer( $this->loop = $loop instanceof LoopInterface ? $loop : Loop::get(), fn($request) => $this->handleReact($request) - )->on('error', fn(Throwable $e) => $this->logError($e, true)); + ))->on('error', fn(Throwable $e) => $this->logError($e, true)); $this->socket = new SocketServer( "{$this->addr}:{$this->port}", [ diff --git a/tests/isolated/ServerLoadingTest.php b/tests/isolated/ServerLoadingTest.php new file mode 100644 index 0000000..dbdcf4f --- /dev/null +++ b/tests/isolated/ServerLoadingTest.php @@ -0,0 +1,26 @@ + '123', 'ss13' => 'alice']]; + $state->setVerifyList($list, false); + $server->setState($state); + $handler = new ReflectionMethod(Server::class, 'handleReact'); + $response = $handler->invoke($server, new ServerRequest('GET', '/verified')); + self::assertSame(200, $response->getStatusCode()); + self::assertSame($list, json_decode((string) $response->getBody(), true)); + self::assertSame('application/json', $response->getHeaderLine('Content-Type')); + self::assertNull($server->getServer()); + self::assertNull($server->getSocketServer()); + $server->close(); + } +}