roave/backward-compatibility-check
Checks your PHP library for backward compatibility breaks between git tags/versions. Designed for CI: compares the last SemVer tag to current HEAD, reports API breaks, and exits non-zero on failure. Install via Composer or run in Docker.
Installation:
composer require --dev roave/backward-compatibility-check
or via Docker:
docker run --rm -v $(pwd):/app nyholm/roave-bc-check
First Run:
vendor/bin/roave-backward-compatibility-check
v1.2.0) with HEAD.CI Integration:
Ensure your CI pipeline fetches all git history (e.g., fetch-depth: 0 in GitHub Actions):
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: vendor/bin/roave-backward-compatibility-check
vendor/bin/roave-backward-compatibility-check --format=github-actions
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: composer install
- run: phpunit
- run: vendor/bin/roave-backward-compatibility-check
.roave-backward-compatibility-check.xml<roave-bc-check>
<baseline>
<ignored-regex>#\[BC\] REMOVED: MyDeprecatedClass::oldMethod\(\)#</ignored-regex>
</baseline>
</roave-bc-check>
| Format | Use Case | Example Command |
|---|---|---|
default |
CLI output (fails on BC breaks) | vendor/bin/roave-backward-compatibility-check |
markdown |
Changelog documentation | --format=markdown > CHANGELOG.md |
github-actions |
GitHub PR annotations | --format=github-actions |
json |
Custom parsing (e.g., Slack notifications) | --format=json > bc-check.json |
post-test in phpunit.xml:
<phpunit>
<extensions>
<extension class="Roave\BackwardCompatibilityCheck\PHPUnit\Extension"/>
</extensions>
</phpunit>
Missing Git Tags:
No baseline tag found.v1.0.0) exist and are fetched in CI.vendor/bin/roave-backward-compatibility-check --baseline=v1.2.0
False Positives:
<ignored-regex> in .roave-backward-compatibility-check.xml:
<ignored-regex>#\[BC\] CHANGED: Added optional \$param to MyClass::method\(\)#</ignored-regex>
Performance:
PHP Version Mismatch:
Unsupported PHP version.Verbose Output:
vendor/bin/roave-backward-compatibility-check -v
Dry Run:
vendor/bin/roave-backward-compatibility-check --dry-run
Custom Autoload Paths:
If using non-standard autoloading (e.g., custom psr-4 paths), specify them:
vendor/bin/roave-backward-compatibility-check --autoload-path=app/
Custom Rules:
Roave\BackwardCompatibilityCheck\Rule\RuleInterface.HasFactory trait changes.Plugin System:
GitHub Action:
- uses: Nyholm/roave-bc-check-docker@v1
Facade Methods:
.roave-backward-compatibility-check.xml:
<ignored-class>Illuminate\Support\Facades\Route</ignored-class>
Service Providers:
register()/boot() methods are not BC breaks but may be flagged.app/Providers/ from checks if needed.Dynamic Proxies:
autoload-dev includes proxy paths in composer.json.How can I help you explore Laravel packages today?