The php_test.yml workflow runs PHP unit tests using Pest or PHPUnit with optional CodeCov integration. It supports Laravel projects with environment decryption and
provides flexible configuration options.
- PHP: All PHP projects with Pest or PHPUnit testing frameworks
- Laravel: Full support including environment decryption
- Flexible Testing: Supports both Pest and PHPUnit via composer scripts
- CodeCov Integration: Optional code coverage reporting
- Laravel Support: Environment decryption for Laravel projects
- Directory Support: Can target subdirectories within repositories
uses: ./.github/workflows/php_test.yml
with:
branch: "main"
phpVersion: "8.3"
useCodeCov: true
codeCovSlug: "your-org/your-repo"
secrets:
laravelEnvDecryptionKey: ${{ secrets.LARAVEL_ENV_DECRYPTION_KEY }}
codeCovToken: ${{ secrets.CODECOV_TOKEN }}| Input | Type | Required | Default | Description |
|---|---|---|---|---|
branch |
string | ❌ | main |
The branch to test |
phpVersion |
string | ❌ | 8.3 |
PHP version to use |
useLaravelEnvDecryptionKey |
boolean | ❌ | false |
Use Laravel environment decryption |
directory |
string | ❌ | ${{ github.workspace }} |
Directory path relative to workspace |
useCodeCov |
boolean | ❌ | false |
Enable CodeCov integration |
codeCovSlug |
string | ❌ | '' |
CodeCov repository slug |
| Secret | Required | Description |
|---|---|---|
laravelEnvDecryptionKey |
❌ | Laravel environment decryption key |
codeCovToken |
❌ | CodeCov authentication token |
This is required in v3.0+. Your composer.json must include a test script:
{
"scripts": {
"test": "pest"
}
}Or for PHPUnit:
{
"scripts": {
"test": "phpunit"
}
}For CodeCov integration:
{
"scripts": {
"test": "pest --parallel --coverage-clover coverage.xml --log-junit junit.xml"
}
}The workflow has two jobs that run conditionally:
- Test Job: Runs when
useCodeCov: false- Standard testing without coverage - CodeCov Job: Runs when
useCodeCov: true- Testing with coverage reporting
uses: ./.github/workflows/php_test.yml
with:
phpVersion: "8.3"uses: ./.github/workflows/php_test.yml
with:
phpVersion: "8.3"
useLaravelEnvDecryptionKey: true
secrets:
laravelEnvDecryptionKey: ${{ secrets.LARAVEL_ENV_DECRYPTION_KEY }}uses: ./.github/workflows/php_test.yml
with:
phpVersion: "8.3"
useCodeCov: true
codeCovSlug: "your-org/your-repo"
secrets:
codeCovToken: ${{ secrets.CODECOV_TOKEN }}uses: ./.github/workflows/php_test.yml
with:
directory: "backend"
phpVersion: "8.3"When useLaravelEnvDecryptionKey: true, the workflow will:
- Decrypt the testing environment file using the provided key
- Move the decrypted file to
.envfor testing
Requires:
- Laravel project with encrypted environment files
LARAVEL_ENV_DECRYPTION_KEYsecret configured
When useCodeCov: true, the workflow will:
- Run tests with coverage reporting
- Upload coverage data to CodeCov
- Upload test results to CodeCov
Requires:
codeCovTokensecretcodeCovSluginput with repository identifier- Test script configured to generate
coverage.xmlandjunit.xml
enforceCoverage- No longer configurableminCodeCoverage- No longer configurablerunParallel- No longer configurable
- Add composer test script - Required for all projects
- Update workflow calls - Remove deprecated parameters
- Configure coverage in test script - Instead of workflow parameters
Test Script Not Found
- Ensure
composer.jsonhas atestscript defined - Verify the test command is correct for your testing framework
Laravel Environment Issues
- Ensure the decryption key is correct
- Check that encrypted environment files exist
CodeCov Upload Fails
- Verify
codeCovTokenis valid - Check
codeCovSlugformat (should be "owner/repo") - Ensure test script generates required coverage files
- php_staticAnalysis.yml: For code quality analysis
- actions/php/codeStyle: For code style enforcement