add phpunit integration (wip)

This commit is contained in:
Andrew Dolgov 2023-10-29 08:58:13 +03:00
parent 855695a862
commit 8b72d9ab11
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
2 changed files with 23 additions and 10 deletions

View File

@ -61,7 +61,7 @@ phpdoc:
chmod 0600 ~/.ssh/id_ed25519 chmod 0600 ~/.ssh/id_ed25519
- rsync -av -e 'ssh -o StrictHostKeyChecking=no' phpdoc/ ${PHPDOC_DEPLOY_HOST}:phpdoc/ - rsync -av -e 'ssh -o StrictHostKeyChecking=no' phpdoc/ ${PHPDOC_DEPLOY_HOST}:phpdoc/
integration-test: selenium:
image: ${SELENIUM_IMAGE} image: ${SELENIUM_IMAGE}
variables: variables:
TEST_HELM_REPO: https://gitlab.tt-rss.org/tt-rss/helm-charts/tt-rss TEST_HELM_REPO: https://gitlab.tt-rss.org/tt-rss/helm-charts/tt-rss
@ -73,8 +73,20 @@ integration-test:
rules: rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
integration-test:branch: selenium:branch:
extends: integration-test extends: selenium
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_REGISTRY_USER != null
when: manual
phpunit-integration:branch:
image: ${PHP_IMAGE}
extends: selenium
script:
- export K8S_NAMESPACE=$(kubectl get pods -o=custom-columns=NS:.metadata.namespace | tail -1)
- export API_URL="http://tt-rss-${CI_COMMIT_SHORT_SHA}-app.$K8S_NAMESPACE.svc.cluster.local/tt-rss/api/"
- env
- php82 vendor/bin/phpunit --group integration
rules: rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_REGISTRY_USER != null - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_REGISTRY_USER != null

View File

@ -7,18 +7,18 @@ final class ApiTest extends TestCase {
/** @var string */ /** @var string */
private $api_url; private $api_url;
/** @var string */
private $sid;
function __construct() { function __construct() {
$this->api_url = $_ENV['API_URL']; $this->api_url = getenv('API_URL');
print_r($this->api_url); print_r($this->api_url);
parent::__construct(); parent::__construct();
} }
/** @param array<mixed> $payload
* @return array<mixed>
*/
function api(array $payload) : ?array { function api(array $payload) : ?array {
$ch = curl_init($this->api_url); $ch = curl_init($this->api_url);
@ -37,18 +37,19 @@ final class ApiTest extends TestCase {
return json_decode($response, true); return json_decode($response, true);
} }
public function common_assertions(array $response) { /** @param array<mixed> $response */
public function common_assertions(array $response) : void {
$this->assertArrayHasKey("content", $response); $this->assertArrayHasKey("content", $response);
$this->assertArrayNotHasKey("error", $response['content'], $response['content']['error']); $this->assertArrayNotHasKey("error", $response['content'], $response['content']['error']);
} }
public function test_login() { public function test_login() : void {
$response = $this->api(["op" => "login", "user" => "test", "password" => "test"]); $response = $this->api(["op" => "login", "user" => "test", "password" => "test"]);
$this->common_assertions($response); $this->common_assertions($response);
} }
public function test_getVersion() { public function test_getVersion() : void {
$response = $this->api(["op" => "getVersion"]); $response = $this->api(["op" => "getVersion"]);