Skip to content

Commit

Permalink
start porting to 4.0; add proper PHPDos
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrashoff committed Aug 9, 2023
1 parent b99e1cf commit bf465ed
Show file tree
Hide file tree
Showing 7 changed files with 447 additions and 772 deletions.
67 changes: 41 additions & 26 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
name: Unit Testing
name: Unit Tests

on:
pull_request:
branches: '**'
push:
branches: '**'
branches:
- master

jobs:
phpinsights:
name: PHP-Insights
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHP-Insights
uses: docker://tienvx/phpinsights-action


unit-test:
name: Unit
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
image: ghcr.io/mvorisek/image-php:${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0']
php: ['8.2']
type: ['Phpunit']

env:
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == '8.0' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- 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)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Setup cache 2/2
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.type }}-${{ hashFiles('composer.json') }}
Expand All @@ -46,13 +42,32 @@ jobs:
- name: Install PHP dependencies
run: |
if [ "${{ matrix.php }}" == "8.0" ]; then composer config platform.php 7.4.5 ; fi
composer install --no-suggest --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ] && [ "${{ matrix.type }}" != "Phpunit Burn" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap --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/\* --dev; fi
if [ -n "$LOG_COVERAGE" ]; then composer require --no-interaction --no-update phpunit/phpcov; 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(); gc_collect_cycles(); $memDiffs = array_fill(0, '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 1024; else echo 64; fi)"', 0); for ($i = -1; $i < count($memDiffs); ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); $mem = memory_get_usage(); if ($i !== -1) { $memDiffs[$i] = $mem - $memPrev; } $memPrev = $mem; rsort($memDiffs); if (array_sum($memDiffs) >= 4096 * 1024 || $memDiffs[2] > 0) { $this->onNotSuccessfulTest(new AssertionFailedError( "Memory leak detected! (" . implode(" + ", array_map(fn ($v) => number_format($v / 1024, 3, ".", " "), array_filter($memDiffs))) . " KB, " . ($i + 2) . " 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: |
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi
- name: "Run tests"
if: matrix.type == 'Phpunit'
run: vendor/bin/phpunit tests --whitelist src --coverage-clover tests/coverage.xml -v

- name: Codecov
uses: codecov/codecov-action@v1
run: |
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) -v
- name: Upload coverage logs 1/2 (only for coverage)
if: env.LOG_COVERAGE
run: |
ls -l coverage | wc -l
php -d memory_limit=2G vendor/bin/phpcov merge coverage/ --clover coverage/merged.xml
- name: Upload coverage logs 2/2 (only for coverage)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: coverage/merged.xml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor
.phpunit.result.cache
.phpunit.result.cache
/coverage
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"prefer-stable": true,
"config": {
"platform": {
"php": "7.4"
"php": "8.2"
}
},
"require": {
"atk4/data": "2.4.*",
"philippgrashoff/traitsforatkdata": "2.4.*"
"atk4/data": "4.*",
"philippgrashoff/atkextendedtestcase": "4.*"
},
"require-dev": {
"phpunit/phpunit": ">8"
"phpunit/phpunit": "^9.5.5",
"phpstan/phpstan": "1.*"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit bf465ed

Please sign in to comment.