Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Jan 30, 2024
1 parent cee5f87 commit 899a6aa
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 101 deletions.
6 changes: 0 additions & 6 deletions .docker/php81.Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions .docker/php82.Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions .docker/php83.Dockerfile

This file was deleted.

4 changes: 4 additions & 0 deletions .docker/xdebug.ci.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=coverage
5 changes: 5 additions & 0 deletions .docker/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=coverage,debug,develop
xdebug.client_host=host.docker.internal
19 changes: 10 additions & 9 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/.docker export-ignore
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
docker-compose.yml export-ignore
phpstan.neon.dist export-ignore
phpunit.xml.dist export-ignore
/.docker export-ignore
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
docker-compose.ci.yml export-ignore
docker-compose.yml export-ignore
phpstan.neon.dist export-ignore
phpunit.xml.dist export-ignore
3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ We accept contributions via Pull Requests on [GitHub](https://github.com/stauden
## Running Tests

```
vendor/bin/phpunit
docker compose run --rm php8.3 composer install
docker compose run --rm php8.3 vendor/bin/phpunit
```
52 changes: 22 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,32 @@ jobs:
include:
- php: 8.3
release: stable
coverage: xdebug

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
coverage: true

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/cache@v3
- name: Check out code
uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ~/.cache/composer/files
key: php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, ctype, json, mbstring, openssl, pdo, pdo_${{ matrix.database }}, tokenizer, xml
coverage: ${{ matrix.coverage }}
- run: composer update --no-interaction --no-progress --prefer-dist --prefer-${{ matrix.release }}
- run: cp tests/config/database.ci.php tests/config/database.php
- run: |
PHPUNIT_FLAGS=$([ "${{ matrix.coverage }}" == "xdebug" ] && echo "--coverage-clover=coverage.xml" || echo "")
vendor/bin/phpunit $PHPUNIT_FLAGS
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Start database container
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml up --wait ${{ matrix.database }}
if: matrix.database != 'sqlite'
- name: Install dependencies
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm php${{ matrix.php }} \
composer update --no-interaction --no-progress --prefer-dist --prefer-${{ matrix.release }}
- name: Run tests
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run -e DB_CONNECTION=${{ matrix.database }} \
--rm php${{ matrix.php }}${{ env.XDEBUG }} vendor/bin/phpunit ${{ env.COVERAGE }}
env:
DATABASE: ${{ matrix.database }}
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
- uses: codecov/codecov-action@v3
XDEBUG: ${{ matrix.coverage && '-xdebug' || '' }}
COVERAGE: ${{ matrix.coverage && '--coverage-clover=coverage.xml' || '' }}
- name: Upload code coverage
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: matrix.coverage == 'xdebug' && env.CODECOV_TOKEN
if: matrix.coverage && env.CODECOV_TOKEN
26 changes: 18 additions & 8 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ jobs:
phpstan:
runs-on: ubuntu-latest

strategy:
matrix:
php: [ 8.3 ]
release: [ stable ]

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- name: Check out code
uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ~/.cache/composer/files
key: php-8.3-composer-${{ hashFiles('**/composer.json') }}
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- run: composer update --no-interaction --no-progress --prefer-dist
- run: vendor/bin/phpstan analyse --error-format=github
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Install dependencies
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm php${{ matrix.php }} \
composer update --no-interaction --no-progress --prefer-dist --prefer-${{ matrix.release }}
- name: Analyse code
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm php${{ matrix.php }} \
vendor/bin/phpstan analyse --error-format=github --memory-limit=-1
36 changes: 36 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

services:
php8.1:
image: ghcr.io/staudenmeir/php:8.1
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
- ~/.cache/composer/files:/root/.composer/cache/files
php8.2:
image: ghcr.io/staudenmeir/php:8.2
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
- ~/.cache/composer/files:/root/.composer/cache/files
php8.3:
image: ghcr.io/staudenmeir/php:8.3
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
- ~/.cache/composer/files:/root/.composer/cache/files
php8.3-xdebug:
image: ghcr.io/staudenmeir/php:8.3
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
- .docker/xdebug.ci.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ~/.cache/composer/files:/root/.composer/cache/files
43 changes: 31 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
version: '3.8'

services:
php81:
build:
context: .
dockerfile: .docker/php81.Dockerfile
php8.1:
image: ghcr.io/staudenmeir/php:8.1
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
php82:
build:
context: .
dockerfile: .docker/php82.Dockerfile
- .docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
php8.2:
image: ghcr.io/staudenmeir/php:8.2
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
php83:
build:
context: .
dockerfile: .docker/php83.Dockerfile
- .docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
php8.3:
image: ghcr.io/staudenmeir/php:8.3
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
- .docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
mysql:
image: 'mysql:latest'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
healthcheck:
test: mysqladmin ping --silent
interval: 5s
timeout: 3s
retries: 10
networks:
- test

networks:
test:
driver: bridge
23 changes: 0 additions & 23 deletions tests/config/database.ci.php

This file was deleted.

0 comments on commit 899a6aa

Please sign in to comment.