|
15 | 15 | strategy:
|
16 | 16 | fail-fast: false
|
17 | 17 | matrix:
|
18 |
| - php: ['7.4', '8.0', '8.1', '8.2', '8.3', 'latest'] |
| 18 | + php: ['latest'] |
19 | 19 | type: ['Phpunit']
|
20 | 20 | include:
|
21 | 21 | - php: 'latest'
|
|
55 | 55 | run: |
|
56 | 56 | echo "memory_limit = 2G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
|
57 | 57 | vendor/bin/phpstan analyse -v
|
| 58 | +
|
| 59 | + unit-test: |
| 60 | + name: Unit |
| 61 | + runs-on: ubuntu-latest |
| 62 | + container: |
| 63 | + image: ghcr.io/mvorisek/image-php:${{ matrix.php }} |
| 64 | + strategy: |
| 65 | + fail-fast: false |
| 66 | + matrix: |
| 67 | + php: ['7.4', '8.0', '8.1', '8.2', '8.3'] |
| 68 | + type: ['Phpunit', 'Phpunit Lowest'] |
| 69 | + env: |
| 70 | + LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == '8.3' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}" |
| 71 | + services: |
| 72 | + mysql: |
| 73 | + image: mysql |
| 74 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=test_pass_root -e MYSQL_USER=test_user -e MYSQL_PASSWORD=test_pass -e MYSQL_DATABASE=test_db |
| 75 | + postgres: |
| 76 | + image: postgres:12-alpine |
| 77 | + env: |
| 78 | + POSTGRES_USER: test_user |
| 79 | + POSTGRES_PASSWORD: test_pass |
| 80 | + POSTGRES_DB: test_db |
| 81 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 82 | + redis1: |
| 83 | + image: redis:alpine |
| 84 | + redis2: |
| 85 | + image: redis:alpine |
| 86 | + redis3: |
| 87 | + image: redis:alpine |
| 88 | + memcached: |
| 89 | + image: memcached:alpine |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Configure PHP |
| 95 | + run: | |
| 96 | + install-php-extensions lzf memcached sysvsem |
| 97 | + if [ -n "$LOG_COVERAGE" ]; then echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; else rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; fi |
| 98 | + php --version |
| 99 | +
|
| 100 | + - name: Install PHP dependencies |
| 101 | + run: | |
| 102 | + if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ]; then composer remove --no-interaction --no-update phpunit/phpunit ergebnis/phpunit-slow-test-detector --dev; fi |
| 103 | + if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer ergebnis/composer-normalize --dev; fi |
| 104 | + if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/\* --dev; fi |
| 105 | + if [ -n "$LOG_COVERAGE" ]; then composer require --no-interaction --no-install phpunit/phpcov; fi |
| 106 | + composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader |
| 107 | + if [ "${{ matrix.type }}" = "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader; fi |
| 108 | +
|
| 109 | + - name: Init |
| 110 | + run: | |
| 111 | + php -r '(new PDO("mysql:host=mysql", "root", "test_pass_root"))->exec("ALTER USER '"'"'test_user'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 15");' |
| 112 | + php -r '(new PDO("pgsql:host=postgres;dbname=test_db", "test_user", "test_pass"))->exec("ALTER ROLE test_user CONNECTION LIMIT 1");' |
| 113 | + if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi |
| 114 | +
|
| 115 | + - name: "Run tests" |
| 116 | + env: |
| 117 | + MYSQL_DSN: "mysql:host=mysql;dbname=test_db" |
| 118 | + MYSQL_USER: test_user |
| 119 | + MYSQL_PASSWORD: test_pass |
| 120 | + PGSQL_DSN: "pgsql:host=postgres;dbname=test_db" |
| 121 | + PGSQL_USER: test_user |
| 122 | + PGSQL_PASSWORD: test_pass |
| 123 | + REDIS_URIS: "redis://redis1,redis://redis2,redis://redis3" |
| 124 | + MEMCACHE_HOST: memcached |
| 125 | + run: | |
| 126 | + php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) --fail-on-warning --fail-on-risky $(if vendor/bin/phpunit --version | grep -q '^PHPUnit 9\.'; then echo -v; else echo --fail-on-notice --fail-on-deprecation --display-notices --display-deprecations --display-warnings --display-errors --display-incomplete --display-skipped; fi) |
| 127 | +
|
| 128 | + - name: Upload coverage (only for coverage) |
| 129 | + if: env.LOG_COVERAGE && false # TODO |
| 130 | + uses: codecov/codecov-action@v5 |
| 131 | + with: |
| 132 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 133 | + fail_ci_if_error: true |
| 134 | + files: coverage/phpunit.cov |
0 commit comments