Skip to content

Commit

Permalink
Merge pull request #131 from alma/devx/fix-coverage-for-all-php-versions
Browse files Browse the repository at this point in the history
[DEVX] Fix CI for PHP versions > 8.0
  • Loading branch information
carine-bonnafous authored Aug 1, 2024
2 parents 5bcfa43 + f356ea7 commit 0a4249c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ jobs:
grep -r -l "$string" tests/ | xargs sed -i "s/$string//g"
- name: PHPUnit
run: composer exec phpunit -- --configuration phpunit.ci.xml --coverage-xml ./.coverage
run: |
case ${{ matrix.php }} in
8.1|8.2|8.3 ) composer exec phpunit -- --configuration phpunit.ci.8.xml --coverage-xml ./.coverage;;
*) composer exec phpunit -- --configuration phpunit.ci.xml --coverage-xml ./.coverage;;
esac
env:
XDEBUG_MODE: coverage

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ phpunit.xml
.phpunit.cache/
composer.lock
.DS_Store
.env
.env
.coverage/
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG COMPOSER_VERSION

FROM composer:${COMPOSER_VERSION} as composer
FROM php:${PHP_VERSION}-fpm
ARG PHP_VERSION

ENV DEBIAN_FRONTEND noninteractive

Expand All @@ -16,6 +17,11 @@ RUN apt update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN case ${PHP_VERSION} in \
8.0|8.1|8.2|8.3 ) pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug;; \
*) pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug;; \
esac

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ RUN apt update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Install xdebug for code coverage
RUN pecl install xdebug-2.5.5 \
&& docker-php-ext-enable xdebug

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

Expand Down
12 changes: 6 additions & 6 deletions Taskfile.php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ tasks:
cmds:
- >-
{{ if eq .PHP_VERSION "5.6" "7.0" }}
docker compose run {{ .COMPOSE_SERVICE }} ./tests/legacy_tests.sh
docker compose run --rm {{ .COMPOSE_SERVICE }} ./tests/legacy_tests.sh
{{ else }}
docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite"
docker compose run --rm {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration {{ .PHPUNIT_FILE }} --testsuite "Alma PHP Client Unit Test Suite" --coverage-xml ./.coverage
{{ end }}
tests:integration:
Expand All @@ -39,15 +39,15 @@ tasks:
cmds:
- >-
{{ if eq .PHP_VERSION "5.6" "7.0" }}
docker compose run {{ .COMPOSE_SERVICE }} ./tests/legacy_integration_tests.sh
docker compose run --rm {{ .COMPOSE_SERVICE }} ./tests/legacy_integration_tests.sh
{{ else }}
docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Integration Test Suite"
docker compose run --rm {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration {{ .PHPUNIT_FILE }} --testsuite "Alma PHP Client Integration Test Suite"
{{ end }}
shell:
desc: Connect to PHP container
deps:
- docker:build
cmds:
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' phpunit.dist.xml > phpunit.xml
- docker compose run {{ .COMPOSE_SERVICE }} bash
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml
- docker compose run --rm {{ .COMPOSE_SERVICE }} bash
3 changes: 3 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ includes:
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.1"
PHPUNIT_FILE: phpunit.dist.8.xml
"8.2":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.2"
PHPUNIT_FILE: phpunit.dist.8.xml
"8.3":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.3"
PHPUNIT_FILE: phpunit.dist.8.xml

tasks:
default:
Expand Down
2 changes: 2 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
volumes:
- ./:/app
- /app/vendor
environment:
XDEBUG_MODE: coverage

php-legacy:
user: ${UID:-1000}:${GID:-1000}
Expand Down
32 changes: 32 additions & 0 deletions phpunit.ci.8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="true"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">

<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
</coverage>

<source>
<include>
<directory suffix=".php">./src/*</directory>
</include>
</source>

</phpunit>
40 changes: 40 additions & 0 deletions phpunit.dist.8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
testdox="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">

<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Alma PHP Client Integration Test Suite">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
</coverage>

<source>
<include>
<directory suffix=".php">./src/*</directory>
</include>
</source>

<php>
<env name="ALMA_API_KEY" value="sk_test_*******"/>
<env name="ALMA_API_ROOT" value="alma-api-url"/>
</php>
</phpunit>
12 changes: 11 additions & 1 deletion phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" testdox="true" displayDetailsOnTestsThatTriggerDeprecations="true" processIsolation="false" stopOnFailure="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false">
<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
Expand All @@ -8,6 +13,11 @@
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/*</directory>
</whitelist>
</filter>
<php>
<env name="ALMA_API_KEY" value="sk_test_*******"/>
<env name="ALMA_API_ROOT" value="alma-api-url"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ string=': void'
grep -r -l "$string" tests/ | xargs sed -i "s/$string//g"

# Run tests
composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite"
composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite" --coverage-xml ./.coverage

0 comments on commit 0a4249c

Please sign in to comment.