From c66c7e6dcc1e21086e5742e0bad6a7561d3a8906 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Mon, 20 Sep 2021 18:47:33 +0200 Subject: [PATCH] Added support for GitLab CI --- .gitignore | 1 + .gitlab-ci.yml | 14 ++++++++++++++ ci/docker_install.sh | 23 +++++++++++++++++++++++ composer.json | 13 +++++++++++++ phpunit.xml | 22 ++++++++++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 ci/docker_install.sh create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index 0a19c94..3bef214 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ /.phpunit.result.cache +.phpunit.cache/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..8ac883e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,14 @@ +# From https://docs.gitlab.com/ee/ci/examples/php.html +image: php:7.4-cli + +before_script: + # Install dependencies + - bash ci/docker_install.sh > /dev/null + +test: + script: + - php composer.phar run test:gitlab + artifacts: + when: always + reports: + junit: report.xml \ No newline at end of file diff --git a/ci/docker_install.sh b/ci/docker_install.sh new file mode 100644 index 0000000..ae3d3ee --- /dev/null +++ b/ci/docker_install.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# From https://docs.gitlab.com/ee/ci/examples/php.html + +# We need to install dependencies only for Docker +[[ ! -e /.dockerenv ]] && exit 0 + +set -xe + +# Install git (the php image doesn't have it) which is required by composer +apt-get update -yqq +apt-get install git wget unzip -yqq + +# Install & enable Xdebug for code coverage reports +pecl install xdebug +docker-php-ext-enable xdebug + +# Install composer dependencies +wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" +php composer-setup.php +php -r "unlink('composer-setup.php'); unlink('installer.sig');" +php composer.phar install \ No newline at end of file diff --git a/composer.json b/composer.json index fc83c56..9aa8a2c 100644 --- a/composer.json +++ b/composer.json @@ -4,5 +4,18 @@ }, "require-dev": { "phpunit/phpunit": "^9" + }, + "scripts": { + "test": [ + "phpunit --configuration phpunit.xml" + ], + "test:coverage": [ + "@putenv XDEBUG_MODE=coverage", + "phpunit --configuration phpunit.xml --coverage-text" + ], + "test:gitlab": [ + "@putenv XDEBUG_MODE=coverage", + "phpunit --configuration phpunit.xml --log-junit report.xml" + ] } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..8b11849 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + + tests + + + + + + src + + +