Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/coverage-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Deploy Coverage to GitHub Pages

on:
workflow_run:
workflows: ["PHPUnit"]
types:
- completed
branches: [main, master]

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/configure-pages@v4

- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-report
path: ./coverage
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Create index page
run: |
cat > ./coverage/README.md << 'EOF'
# Code Coverage Report

This page contains the code coverage report for the project.

- [Coverage Report](./index.html) - Interactive HTML coverage report
- Generated from commit: `${{ github.event.workflow_run.head_sha }}`
- Branch: `${{ github.event.workflow_run.head_branch }}`
- Workflow run: [${{ github.event.workflow_run.id }}](${{ github.event.workflow_run.html_url }})

## How to read the coverage report

- **Green lines**: Covered by tests
- **Red lines**: Not covered by tests
- **Yellow lines**: Partially covered

Click on any file in the coverage report to see line-by-line coverage details.
EOF

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./coverage

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
24 changes: 7 additions & 17 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
run: composer install --prefer-dist --no-progress --no-suggest

- name: Create build directories
run: mkdir -p build/logs
run: mkdir -p build/logs build/coverage

- name: Run PHPUnit tests
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-html build/coverage

- if: |
matrix.php-versions == '8.1' &&
Expand All @@ -55,20 +55,10 @@ jobs:
- if: |
matrix.php-versions == '8.1' &&
matrix.operating-system == 'ubuntu-latest'
name: Debug coverage file
run: |
ls -la build/logs/
head -20 build/logs/clover.xml || echo "Coverage file not found or empty"

- if: |
matrix.php-versions == '8.1' &&
matrix.operating-system == 'ubuntu-latest'
name: Upload coverage to Codeclimate
continue-on-error: true
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
coverageLocations: ${{github.workspace}}/build/logs/clover.xml:clover
debug: true
name: coverage-report
path: build/coverage/
retention-days: 30

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ sniff_fix: vendor/autoload.php

test: vendor/autoload.php
vendor/bin/phpunit

coverage: vendor/autoload.php
mkdir -p build/logs build/coverage
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-html build/coverage
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
$ composer test
```

### Code Coverage

To generate code coverage reports:

``` bash
# Generate coverage reports locally
$ composer coverage
# or use the helper script
$ ./coverage.sh
```

The coverage reports will be generated in:
- **HTML report**: `build/coverage/index.html` (open in browser to see line-by-line coverage)
- **Clover XML**: `build/logs/clover.xml` (for CI/CD integration)

**Online Coverage Reports**: Coverage reports are automatically published to GitHub Pages after each successful test run on the main branch. You can view them at: `https://[username].github.io/[repository-name]/`

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"scripts": {
"phpunit": "phpunit",
"phpstan": "phpstan analyse",
"phpcs": "phpcs --standard=PSR2 src tests examples -n"
"phpcs": "phpcs --standard=PSR2 src tests examples -n",
"coverage": "XDEBUG_MODE=coverage phpunit --coverage-clover build/logs/clover.xml --coverage-html build/coverage"
}
}
32 changes: 32 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Generate code coverage report locally
echo "Generating code coverage report..."

# Create build directories
mkdir -p build/logs build/coverage

# Run PHPUnit with coverage (with Xdebug coverage mode)
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-html build/coverage

if [ $? -eq 0 ]; then
echo ""
echo "✅ Coverage report generated successfully!"
echo ""
echo "📊 Coverage reports available at:"
echo " - HTML: build/coverage/index.html"
echo " - Clover XML: build/logs/clover.xml"
echo ""
echo "🌐 Open the HTML report in your browser:"
if command -v xdg-open &> /dev/null; then
echo " xdg-open build/coverage/index.html"
elif command -v open &> /dev/null; then
echo " open build/coverage/index.html"
else
echo " file://$(pwd)/build/coverage/index.html"
fi
else
echo ""
echo "❌ Coverage generation failed!"
exit 1
fi