summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-10-28 18:43:47 +0300
committerAndrew Dolgov <[email protected]>2023-10-28 18:45:09 +0300
commit855695a8620a3a5ffada836fd28e04bb912bbd3a (patch)
treec1e3a4ae29ec9ad7c6180499f28b9f93ed77fac0 /tests
parent0ac8710ea1b1426bf19bb502ba4921ef35cd1db6 (diff)
add stuff necessary to run integration tests using phpunit
Diffstat (limited to 'tests')
-rw-r--r--tests/ApiTest.php13
-rw-r--r--tests/integration/ApiTest.php60
2 files changed, 60 insertions, 13 deletions
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 @@
-<?php
-use PHPUnit\Framework\TestCase;
-
-/** @group integration */
-final class ApiTest extends TestCase {
-
- function test_login() {
-
-
-
- }
-
-}
diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php
new file mode 100644
index 000000000..cd7a8d67a
--- /dev/null
+++ b/tests/integration/ApiTest.php
@@ -0,0 +1,60 @@
+<?php
+use PHPUnit\Framework\TestCase;
+
+/** @group integration */
+final class ApiTest extends TestCase {
+
+ /** @var string */
+ private $api_url;
+
+ /** @var string */
+ private $sid;
+
+ function __construct() {
+
+ $this->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);
+
+
+ }
+
+}