diff --git a/.docker/Dockerfile b/.docker/Dockerfile deleted file mode 100644 index deca030f..00000000 --- a/.docker/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM composer:1 as composer -FROM php:5.6-fpm -#FROM php:7.0-fpm -#FROM php:7.1-fpm -#FROM php:7.2-fpm -#FROM php:7.3-fpm -#FROM php:7.4-fpm -#FROM php:8.0-fpm -#FROM php:8.1-fpm -#FROM php:8.2-fpm - -# Packages install -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get clean \ - && apt-get -y update \ - && apt-get install -y \ - git \ - unzip \ - && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* - -COPY php.ini /usr/local/etc/php/php.ini - -RUN usermod -u 1000 www-data -RUN groupmod -g 1000 www-data - -RUN mkdir -p /app && chown -R www-data:www-data /app - -COPY --from=composer /usr/bin/composer /usr/bin/composer -RUN composer self-update 1.10.19 - -USER www-data - -WORKDIR /app \ No newline at end of file diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml deleted file mode 100644 index a4afb610..00000000 --- a/.docker/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3.7' - -services: - test-php: - container_name: test-php - build: - context: ./ - dockerfile: Dockerfile - volumes: - - ../:/app - ports: - - "8080:80" - restart: unless-stopped - stdin_open: true - tty: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e650bc94..824eb1f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,16 +57,16 @@ jobs: run: composer validate - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest + run: composer install --prefer-dist --no-progress - name: Prepare unittests configuration run: sed -i 's/{MYVERSION}/${{ matrix.php.unittest-version }}/g' phpunit.ci.xml - name: Ensure source code is linted - run: ./vendor/bin/phpcs src + run: composer exec phpcs -- src/ - name: PHPUnit - run: ./vendor/bin/phpunit -c phpunit.ci.xml --coverage-xml ./.coverage + run: composer exec phpunit -- -c phpunit.ci.xml --coverage-xml ./.coverage env: XDEBUG_MODE: coverage diff --git a/.gitignore b/.gitignore index 0025fbcf..6d2a9612 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ .phpunit.result.cache .idea dist/ -composer.lock phpunit.xml -.phpunit.cache/ \ No newline at end of file +.phpunit.cache/ +composer.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..299b0540 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +ARG PHP_VERSION + +FROM composer:2 as composer +FROM php:${PHP_VERSION}-fpm + +ENV DEBIAN_FRONTEND noninteractive + +# Install dependencies +RUN apt update && \ + apt install -y --no-install-recommends \ + git \ + zip \ + unzip \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* + +RUN usermod -u 1000 www-data +RUN groupmod -g 1000 www-data + +RUN mkdir -p /app/vendor && chown -R www-data:www-data /app + +USER www-data +WORKDIR /app + +COPY --link .docker/php.ini /usr/local/etc/php/php.ini + +COPY --from=composer /usr/bin/composer /usr/bin/composer +COPY --link composer.json ./ +RUN composer install --prefer-dist --no-progress diff --git a/Dockerfile.legacy b/Dockerfile.legacy new file mode 100644 index 00000000..4223fa91 --- /dev/null +++ b/Dockerfile.legacy @@ -0,0 +1,35 @@ +ARG PHP_VERSION + +FROM composer:1 as composer +FROM php:${PHP_VERSION}-fpm + +ENV DEBIAN_FRONTEND noninteractive + +# Update sources.list to outdated Debian archives +RUN sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list && \ + sed -i s/security.debian.org/archive.debian.org/g /etc/apt/sources.list && \ + sed -i s/stretch-updates/stretch/g /etc/apt/sources.list + +# Install dependencies +RUN apt update && \ + apt install -y --no-install-recommends \ + git \ + zip \ + unzip \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* + +RUN usermod -u 1000 www-data +RUN groupmod -g 1000 www-data + +RUN mkdir -p /app/vendor && chown -R www-data:www-data /app + +USER www-data +WORKDIR /app + +COPY --link .docker/php.ini /usr/local/etc/php/php.ini + +COPY --from=composer /usr/bin/composer /usr/bin/composer +COPY --link composer.json ./ +RUN composer install --prefer-dist --no-progress diff --git a/Makefile b/Makefile deleted file mode 100644 index c8041407..00000000 --- a/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -.DEFAULT_GOAL := help -.PHONY: help, up, stop, remove, composer, test, test-all, integration-test, connect - -help: - @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-15s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' - -## -## Docker tests -##--------------------------------------------------------------------------- -up: ## Up PHP test container - CURRENT_UID=$(id -u):www-data docker-compose -f .docker/docker-compose.yml up -d --build ; - -stop: ## Stop PHP test container - CURRENT_UID=$(id -u):www-data docker-compose -f .docker/docker-compose.yml stop; - -remove: ## remove PHP test container - CURRENT_UID=$(id -u):www-data docker-compose -f .docker/docker-compose.yml down; - -composer: - docker exec -it -u www-data:www-data test-php /usr/bin/composer install - -unit-test: up composer ## Execute PHPUnit tests - docker exec -it -u www-data test-php sh -c './vendor/bin/phpunit --testsuite "Alma PHP Client Unit Test Suite"' - -integration-test: up composer ## Execute intregration tests - docker exec -it -u www-data test-php sh -c './vendor/bin/phpunit --testsuite "Alma PHP Client Integration Test Suite"' - -connect: up ## Connect to test container - docker exec -it -u www-data:www-data test-php /bin/bash - -lint: up ## lint the php code - docker exec -it -u www-data test-php sh -c './vendor/bin/phpcs src/' - -fix: up ## lint fix the php code - docker exec -it -u www-data test-php sh -c './vendor/bin/phpcbf src/ tests/' \ No newline at end of file diff --git a/Taskfile.php.yml b/Taskfile.php.yml new file mode 100644 index 00000000..d8edc3ba --- /dev/null +++ b/Taskfile.php.yml @@ -0,0 +1,43 @@ +version: 3 + +vars: + # Required variables + PHP_VERSION: '{{ .PHP_VERSION }}' + PHPUNIT_VERSION: '{{ .PHPUNIT_VERSION }}' + # Defaulted variable + COMPOSE_SERVICE: '{{ .COMPOSE_SERVICE | default "php" }}' + PHPUNIT_FILE: '{{ .PHPUNIT_FILE | default "phpunit.dist.xml" }}' + +env: + PHP_VERSION: '{{ .PHP_VERSION }}' + +tasks: + docker:build: + internal: true + desc: Build the PHP test container + cmds: + - docker compose build --pull {{ .COMPOSE_SERVICE }} + + tests: + desc: Execute PHPUnit tests on PHP {{ .PHP_VERSION }} + deps: + - docker:build + cmds: + - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml + - docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Unit Test Suite" + + tests:integration: + desc: Execute intregration tests + deps: + - docker:build + cmds: + - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml + - docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Integration Test Suite" + + shell: + desc: Connect to PHP container + deps: + - docker:build + cmds: + - sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml + - docker compose run {{ .COMPOSE_SERVICE }} bash diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..7f39fe45 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,94 @@ +version: 3 + +env: + UID: + sh: id -u + GID: + sh: id -g + +includes: + "5.6": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "5.6" + COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration + PHPUNIT_VERSION: Legacy + PHPUNIT_FILE: phpunit.dist.legacy.xml + "7.0": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "7.0" + COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration + PHPUNIT_VERSION: PHP7_0 + "7.1": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "7.1" + PHPUNIT_VERSION: PHP7_0 + "7.2": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "7.2" + PHPUNIT_VERSION: PHP7_2 + "7.3": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "7.3" + PHPUNIT_VERSION: PHP7_2 + "7.4": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "7.4" + PHPUNIT_VERSION: PHP7_2 + "8.0": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "8.0" + PHPUNIT_VERSION: PHP7_2 + "8.1": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "8.1" + PHPUNIT_VERSION: PHP8_1 + "8.2": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "8.2" + PHPUNIT_VERSION: PHP8_1 + "8.3": + taskfile: Taskfile.php.yml + vars: + PHP_VERSION: "8.3" + PHPUNIT_VERSION: PHP8_1 + +tasks: + default: + cmds: + - cmd: task -l + silent: true + + docker:down: + desc: Clean up the docker environment + cmds: + - docker compose down --volumes --remove-orphans + + lint: + desc: Lint the php code + deps: + - 8.3:docker:build + cmds: + - docker compose run php composer exec phpcs -- src/ + + lint:fix: + desc: Lint fix the php code + deps: + - 8.3:docker:build + cmds: + - docker compose run php composer exec phpcbf -- src/ tests/ + + build: + desc: Build zip dist package using Docker + deps: + - 8.3:docker:build + cmds: + - docker compose run php ./build.sh diff --git a/build.sh b/build.sh index f7bc4541..5cc76b74 100755 --- a/build.sh +++ b/build.sh @@ -1,18 +1,6 @@ #!/usr/bin/env bash -DIR=`pwd` - -rm -rf ./dist/ -rm -rf /tmp/alma-php-client -mkdir -p /tmp/alma-php-client - -cp -r ./* /tmp/alma-php-client/ - -mkdir ./dist - -cd /tmp/alma-php-client/ || exit -rm -rf vendor +rm -rf dist/ vendor/ +mkdir -p ./dist composer install --no-dev -zip -9 -r "$DIR/dist/alma-php-client.zip" . --exclude \*dist\* \*.git\* \*.idea\* \*.DS_Store - -rm -rf /tmp/alma-php-client +zip -9 -r "dist/alma-php-client.zip" src/ README.md CHANGELOG.md LICENSE composer.json diff --git a/compose.yml b/compose.yml new file mode 100644 index 00000000..1f91129d --- /dev/null +++ b/compose.yml @@ -0,0 +1,26 @@ +services: + php: + user: ${UID:-1000}:${GID:-1000} + build: + context: ./ + dockerfile: Dockerfile + args: + PHP_VERSION: ${PHP_VERSION} + ports: + - "8080:80" + volumes: + - ./:/app + - /app/vendor + + php-legacy: + user: ${UID:-1000}:${GID:-1000} + build: + context: ./ + dockerfile: Dockerfile.legacy + args: + PHP_VERSION: ${PHP_VERSION} + ports: + - "8080:80" + volumes: + - ./:/app + - /app/vendor diff --git a/composer.json b/composer.json index 060c58bc..f0b54593 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true - } + }, + "lock": false } } diff --git a/phpunit.dist.xml b/phpunit.dist.xml index 6be7a856..a8cc84a1 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -2,10 +2,10 @@ - tests/Unit/PHP8_1 + tests/Unit/{MYVERSION} - tests/Integration/PHP8_1 + tests/Integration/{MYVERSION} diff --git a/tests/README.md b/tests/README.md index a97d227c..735317b4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,40 +1,38 @@ -Alma PHP API Client tests -===================== +# Alma PHP API Client tests -## For PHP 5.6 to 8.0 -- copy `phpunit.dist.legacy.xml` to `phpunit.xml` +## Launch tests -#### If you are using PHP5.6 +We are using [Taskfile](https://taskfile.dev/) to run our development tasks. +[Actively supported PHP versions](https://www.php.net/supported-versions.php) should be used to run our tests. -You need to change in phpunit.xml the variable {MYVERSION} by "Legacy" +### Unit tests -#### If you are using PHP7.0 or PHP7.1 +```bash +task tests # defaults to latest +task tests PHP_VERSION=8.2 +``` -You need to change in phpunit.xml the variable {MYVERSION} by "PHP7_0" +### Integration tests -#### If you are using PHP7.2 or PHP7.3 or PHP7.4 or PHP8.0 +First fill in `ALMA_API_KEY` and `ALMA_API_ROOT` in `phpunit.dist.xml` -You need to change in phpunit.xml the variable {MYVERSION} by "PHP7_2" +```bash +task tests:integration # defaults to latest +task tests:integration PHP_VERSION=8.2 +``` +### Older PHP versions (5.6 to 8.0) -## For PHP > 8.0 -- copy `phpunit.dist.xml` to `phpunit.xml` +Copy `phpunit.dist.legacy.xml` to `phpunit.xml` -## For all version -- fill in `ALMA_API_KEY` and `ALMA_API_ROOT` -- Change in .docker/Dockerfile ligne 2 your version of PHP +#### If you are using PHP5.6 +You need to change in phpunit.xml the variable {MYVERSION} by "Legacy" ---------------------- +#### If you are using PHP7.0 or PHP7.1 -## Launch tests +You need to change in phpunit.xml the variable {MYVERSION} by "PHP7_0" -to launch unit test : -``` -make unit-test -``` +#### If you are using PHP7.2 or PHP7.3 or PHP7.4 or PHP8.0 -to launch integration test : -``` -make integration-test -``` +You need to change in phpunit.xml the variable {MYVERSION} by "PHP7_2"