.github/workflows/test-unit.yml
name: Unit
on:
pull_request:
push:
schedule:
- cron: '0 0/2 * * *'
jobs:
smoke-test:
name: Smoke
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['latest']
type: ['Phpunit']
include:
- php: 'latest'
type: 'CodingStyle'
- php: 'latest'
type: 'StaticAnalysis'
env:
LOG_COVERAGE: ""
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure PHP
run: |
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
php --version
- name: Setup cache 1/2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup cache 2/2
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-smoke-${{ matrix.php }}-${{ matrix.type }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install PHP dependencies
run: |
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/dbunit phpunit/phpcov --dev ; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-interaction --no-update require jdorn/sql-formatter ; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev ; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Init
run: |
mkdir -p build/logs
- name: "Run tests: SQLite (only for Phpunit)"
if: matrix.type == 'Phpunit'
run: "vendor/bin/phpunit \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: Check Coding Style (only for CodingStyle)
if: matrix.type == 'CodingStyle'
run: vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose
- name: Run Static Analysis (only for StaticAnalysis)
if: matrix.type == 'StaticAnalysis'
run: |
echo "memory_limit = 1G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
vendor/bin/phpstan analyse
unit-test:
name: Unit
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['7.4', 'latest']
type: ['Phpunit']
include:
- php: 'latest'
type: 'Phpunit Lowest'
- php: 'latest'
type: 'Phpunit Burn'
env:
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == 'latest' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
services:
mysql:
image: mysql:8
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test__dsql --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: atk4_test
POSTGRES_PASSWORD: atk4_pass
POSTGRES_DB: atk4_test__dsql
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mssql:
image: mcr.microsoft.com/mssql/server
env:
ACCEPT_EULA: Y
SA_PASSWORD: atk4_pass
oracle:
image: wnameless/oracle-xe-11g-r2
env:
ORACLE_ALLOW_REMOTE: true
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure PHP
run: |
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
php --version
- name: Setup cache 1/2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup cache 2/2
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.type }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install PHP dependencies
run: |
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ] && [ "${{ matrix.type }}" != "Phpunit Burn" ]; then composer remove --no-interaction --no-update phpunit/phpunit phpunit/dbunit phpunit/phpcov --dev ; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev ; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev ; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 250; else echo 10; fi)"'; ++$i) { $this->_runBare(); if ($i === 0) { gc_collect_cycles(); $mem1 = memory_get_usage(); } } gc_collect_cycles(); $mem2 = memory_get_usage(); if ($mem2 - 1536 * 1024 > $mem0 || $mem2 - 128 * 1024 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " + " . round(($mem2 - $mem1) \/ (1024 * 1024), 3) . " MB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi
- name: Init
run: |
mkdir -p build/logs
- name: "Run tests: SQLite (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: "Run tests: MySQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-mysql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: "Run tests: PostgreSQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-pgsql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: "Run tests: MSSQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-mssql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: "Run tests: Oracle (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-oracle.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
- name: Upload coverage logs 1/2 (only for "latest" Phpunit)
if: env.LOG_COVERAGE
run: vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml
- name: Upload coverage logs 2/2 (only for "latest" Phpunit)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/logs/cc.xml