diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 21:19:36 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-27 21:19:39 +0300 |
| commit | b434f9127fc67d97ed224b22594ecbd232fa4da3 (patch) | |
| tree | 90449be52f3d9b85f449cc65707a75e82cc81b3a /tests_integration/LoginTest.php | |
| parent | 2b28a847f97395d756d16400ce3fb29b8c8bb75e (diff) | |
| download | the-epube-b434f9127fc67d97ed224b22594ecbd232fa4da3.tar.gz the-epube-b434f9127fc67d97ed224b22594ecbd232fa4da3.tar.xz | |
cleanup return values a bit (more json), move common API test stuff to an ancestor class
Diffstat (limited to 'tests_integration/LoginTest.php')
| -rw-r--r-- | tests_integration/LoginTest.php | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/tests_integration/LoginTest.php b/tests_integration/LoginTest.php index 3e155d8..6d685c7 100644 --- a/tests_integration/LoginTest.php +++ b/tests_integration/LoginTest.php @@ -1,45 +1,8 @@ <?php use PHPUnit\Framework\TestCase; -final class LoginTest extends TestCase +final class LoginTest 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): 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, - ]); - $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 login ────────────────────────────────────────────────────── public function test_perform_login_success(): void |
