1
0
Fork 0

Added support for GitLab CI

This commit is contained in:
Marcel Kapfer 2021-09-20 18:47:33 +02:00
parent e8e4112548
commit c66c7e6dcc
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09
5 changed files with 73 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
vendor/
/.phpunit.result.cache
.phpunit.cache/

14
.gitlab-ci.yml Normal file
View file

@ -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

23
ci/docker_install.sh Normal file
View file

@ -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

View file

@ -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"
]
}
}

22
phpunit.xml Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>