diff options
author | Andrew Dolgov <[email protected]> | 2023-10-29 09:42:53 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-10-29 09:42:53 +0300 |
commit | 7cd2c5cac8344157f2d9cef6ca659f97d0600daf (patch) | |
tree | 7fc627bc06a4ffac7f764454b145a543b462c4c8 /tests/integration | |
parent | adf3985afa594d0107bbaba2a0d5c3871ebc8701 (diff) |
fix apitest
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/ApiTest.php | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php index 80f8af983..67e7f0249 100644 --- a/tests/integration/ApiTest.php +++ b/tests/integration/ApiTest.php @@ -7,6 +7,9 @@ final class ApiTest extends TestCase { /** @var string */ private $api_url; + /** @var string */ + private $sid; + function __construct() { $this->api_url = getenv('API_URL'); @@ -25,34 +28,40 @@ final class ApiTest extends TestCase { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); - $response = curl_exec($ch); + $resp = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($status != 200) { + print("error: failed with HTTP status: $status"); + return null; + } + curl_close($ch); - return json_decode($response, true); + return json_decode($resp, true); } - /** @param array<mixed> $response */ - public function common_assertions(array $response) : void { - $this->assertArrayHasKey("content", $response); - $this->assertArrayNotHasKey("error", $response['content'], $response['content']['error']); + /** @param array<mixed> $resp */ + public function common_assertions(array $resp) : void { + $this->assertArrayHasKey("content", $resp); + $this->assertArrayNotHasKey("error", $resp['content'], $resp['content']['error'] ?? ''); } public function test_login() : void { - $response = $this->api(["op" => "login", "user" => "test", "password" => "test"]); + $resp = $this->api(["op" => "login", "user" => "test", "password" => "test"]); + $this->common_assertions($resp); - $this->common_assertions($response); + $this->assertArrayHasKey("session_id", $resp['content']); + $this->sid = $resp['content']['session_id']; } public function test_getVersion() : void { - $response = $this->api(["op" => "getVersion"]); - - $this->common_assertions($response); - + $this->test_login(); + $resp = $this->api(["op" => "getVersion", "sid" => $this->sid]); + $this->common_assertions($resp); + $this->assertArrayHasKey("version", $resp['content']); } - } |