From 855695a8620a3a5ffada836fd28e04bb912bbd3a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 28 Oct 2023 18:43:47 +0300 Subject: add stuff necessary to run integration tests using phpunit --- tests/ApiTest.php | 13 ---------- tests/integration/ApiTest.php | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-) delete mode 100644 tests/ApiTest.php create mode 100644 tests/integration/ApiTest.php (limited to 'tests') diff --git a/tests/ApiTest.php b/tests/ApiTest.php deleted file mode 100644 index cee4f8313..000000000 --- a/tests/ApiTest.php +++ /dev/null @@ -1,13 +0,0 @@ -api_url = $_ENV['API_URL']; + + print_r($this->api_url); + + parent::__construct(); + } + + function api(array $payload) : ?array { + $ch = curl_init($this->api_url); + + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/json"]); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); + + $response = curl_exec($ch); + + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + return json_decode($response, true); + } + + public function common_assertions(array $response) { + $this->assertArrayHasKey("content", $response); + $this->assertArrayNotHasKey("error", $response['content'], $response['content']['error']); + } + + public function test_login() { + $response = $this->api(["op" => "login", "user" => "test", "password" => "test"]); + + $this->common_assertions($response); + } + + public function test_getVersion() { + + $response = $this->api(["op" => "getVersion"]); + + $this->common_assertions($response); + + + } + +} -- cgit v1.2.3