diff options
Diffstat (limited to 'tests_integration/LogoutHandlerTest.php')
| -rw-r--r-- | tests_integration/LogoutHandlerTest.php | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/tests_integration/LogoutHandlerTest.php b/tests_integration/LogoutHandlerTest.php index 4495872..93ee596 100644 --- a/tests_integration/LogoutHandlerTest.php +++ b/tests_integration/LogoutHandlerTest.php @@ -1,47 +1,8 @@ <?php use PHPUnit\Framework\TestCase; -final class LogoutHandlerTest extends TestCase +final class LogoutHandlerTest extends ApiTestCase { - private string $apiUrl; - - protected function setUp(): void - { - $this->apiUrl = getenv('API_URL') ?: 'http://localhost:9080/backend.php'; - } - - /** - * Make an HTTP POST request and return [status_code, decoded_body]. - * @param array<string, string> $data - * @return array<int, mixed> - */ - private function post(string $endpoint, array $data, ?string $cookieFile = null): array - { - $ch = curl_init($endpoint); - curl_setopt_array($ch, [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => http_build_query($data), - CURLOPT_TIMEOUT => 10, - CURLOPT_CONNECTTIMEOUT => 5, - CURLOPT_COOKIEFILE => $cookieFile ?? '', - CURLOPT_COOKIEJAR => $cookieFile ?? '', - ]); - $body = curl_exec($ch); - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $errno = curl_errno($ch); - $error = curl_error($ch); - curl_close($ch); - - if ($errno) { - $this->fail("cURL error ($errno): $error"); - } - - /** @var array<string, mixed>|null $decoded */ - $decoded = json_decode($body, true); - return [$status, $decoded ?? []]; - } - // ── Successful logout ───────────────────────────────────────────────────── public function test_logout_returns_ok(): void @@ -63,8 +24,10 @@ final class LogoutHandlerTest extends TestCase 'op' => 'logout', ], $cookieFile); + print_r($body); + $this->assertEquals(200, $status); - $this->assertEquals('OK', $body['result'] ?? null); + $this->assertEquals('ok', $body['result'] ?? null); unlink($cookieFile); } @@ -79,7 +42,7 @@ final class LogoutHandlerTest extends TestCase $this->post($this->apiUrl, [ 'op' => 'perform-login', 'user' => 'test', - 'password' => 'test', + 'password' => 'test1', ], $cookieFile); // Step 2: Logout |
