From 961de8614a7a22c58283d7a3a6120992fc3cab6e Mon Sep 17 00:00:00 2001 From: Mike Garde Date: Wed, 15 May 2024 13:45:47 -0400 Subject: [PATCH] PHP Unit update Also allowing tests to run against multiple docker containers via taskfile --- .github/workflows/php.yml | 2 +- Dockerfile | 3 ++- README.md | 12 +++++----- Taskfile.yaml | 46 +++++++++++++++++++++++++++++++++++++++ composer.json | 2 +- 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 Taskfile.yaml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 76d5040..48bbd58 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 8.0, 8.1, 8.2 ] + php: [ 8.0, 8.1, 8.2, 8.3 ] name: php:${{ matrix.php }} diff --git a/Dockerfile b/Dockerfile index d78aef6..6183672 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM php:8.2-fpm +ARG PHP_VERSION +FROM php:${PHP_VERSION}-fpm RUN apt-get update RUN apt-get install -y git zip unzip libzip-dev libmcrypt-dev --no-install-recommends diff --git a/README.md b/README.md index afcd8cf..db525e3 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,12 @@ else // OCONUS ## Local Development Notes -```shell -docker build . -t php:8.2 +The numeric value after the command represents the PHP version -docker run --rm -it -v $(pwd):/app php:8.2 composer install -docker run --rm -it -v $(pwd):/app php:8.2 composer test -docker run --rm -it -v $(pwd):/app php:8.2 composer phpcs +```shell +task build-8.3 +task setup-8.3 +task test-8.3 ``` + +Alternatively you can run `task test-all` to build, setup, and test against all supported PHP versions. diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..4717ace --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,46 @@ +version: '3' +vars: + DEFAULT_PHP_VERSION: "8.3" +tasks: + build: + vars: + PHP_VERSION: '{{default .DEFAULT_PHP_VERSION .PHP_VERSION}}' + cmds: + - docker build --build-arg PHP_VERSION={{.PHP_VERSION}} -t cc:{{.PHP_VERSION}} . + build-*: + vars: + PHP_VERSION: '{{index .MATCH 0}}' + cmds: + - task: build + vars: { PHP_VERSION: "{{.PHP_VERSION}}" } + silent: true + docker-run: + vars: + COMMAND: '{{.COMMAND}}' + PHP_VERSION: '{{default .DEFAULT_PHP_VERSION .PHP_VERSION}}' + cmds: + - docker run --rm -it -v $(pwd):/app cc:{{.PHP_VERSION}} composer {{.COMMAND}} + setup-*: + vars: + PHP_VERSION: '{{index .MATCH 0}}' + cmds: + - rm -f composer.lock 2> /dev/null + - task: docker-run + vars: { COMMAND: "install", PHP_VERSION: "{{.PHP_VERSION}}" } + test-*: + vars: + PHP_VERSION: '{{index .MATCH 0}}' + cmds: + - task: docker-run + vars: { COMMAND: "test", PHP_VERSION: "{{.PHP_VERSION}}" } + - task: docker-run + vars: { COMMAND: "phpcs", PHP_VERSION: "{{.PHP_VERSION}}" } + test-all: + cmds: + - | + VERSIONS=("8.0" "8.1" "8.2" "8.3") + for VERSION in "${VERSIONS[@]}"; do + task build-$VERSION + task setup-$VERSION + task test-$VERSION + done diff --git a/composer.json b/composer.json index bfaf0f0..e356bed 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.0" }, "require-dev": { - "phpunit/phpunit": "^9.0 || ^10.5.0", + "phpunit/phpunit": ">9.0", "squizlabs/php_codesniffer": "^3.0" }, "scripts": {