CI/CD Integration
DocTest is designed to run in CI pipelines. It returns proper exit codes and supports JSON output for custom tooling and analysis.
GitHub Actions
Basic Setup
yaml
name: Documentation Tests
on: [push, pull_request]
jobs:
doctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
- run: composer install --no-interaction
- name: Run DocTest
run: vendor/bin/doctestGitLab CI
yaml
doctest:
image: php:8.4-cli
before_script:
- composer install --no-interaction
script:
- vendor/bin/doctestBitbucket Pipelines
yaml
pipelines:
default:
- step:
name: Documentation Tests
image: php:8.4-cli
script:
- composer install --no-interaction
- vendor/bin/doctestCircleCI
yaml
jobs:
doctest:
docker:
- image: cimg/php:8.4
steps:
- checkout
- run: composer install --no-interaction
- run: vendor/bin/doctestExit Codes
| Code | Meaning |
|---|---|
0 | All blocks passed |
1 | One or more blocks failed |
CI systems treat exit code 1 as a failure, which fails the build when documentation tests break.
Tips
- Run DocTest as a separate job so it doesn't block your main test suite
- Use
--stop-on-failureto fail fast in CI - Use the JSON reporter for custom analysis or trend tracking
- Cache
vendor/to speed up CI runs