Dev #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php-version: ['8.1', '8.2', '8.3', '8.4'] | |
| name: PHP ${{ matrix.php-version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| coverage: xdebug | |
| tools: composer:v2 | |
| - name: Get composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Validate composer.json | |
| run: composer validate --strict --no-check-lock | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Security check for vulnerabilities | |
| run: composer audit --no-dev | |
| - name: Run PHPUnit tests | |
| run: composer test | |
| - name: Run PHPUnit with coverage | |
| if: matrix.php-version == '8.2' | |
| run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml | |
| - name: Upload coverage to Codecov | |
| if: matrix.php-version == '8.2' | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| flags: unittests | |
| fail_ci_if_error: false | |
| - name: Run PHPCS coding standards check | |
| if: matrix.php-version == '8.2' | |
| run: composer lint | |
| - name: Check PHP compatibility | |
| if: matrix.php-version == '8.2' | |
| run: composer phpcompat | |
| test-status: | |
| name: Test Status | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: always() | |
| steps: | |
| - name: Check test results | |
| run: | | |
| if [ "${{ needs.test.result }}" == "success" ]; then | |
| echo "✅ All tests passed!" | |
| exit 0 | |
| else | |
| echo "❌ Tests failed!" | |
| exit 1 | |
| fi |