roave/backward-compatibility-check
CLI tool to detect backward-compatibility breaks between two versions of a PHP library. Compares the last SemVer git tag to current HEAD (or chosen refs) and fails CI on API breaks. Install via Composer or run with Docker.
Installation:
composer require --dev roave/backward-compatibility-check
Add to composer.json under require-dev if not using global install.
First Run:
vendor/bin/roave-backward-compatibility-check
v1.2.3) with HEAD.CI Integration:
Ensure Git tags are fetched (e.g., fetch-depth: 0 in GitHub Actions):
- uses: actions/checkout@v4
with:
fetch-depth: 0
1.2.0 → 1.3.0), verify no BC breaks exist.vendor/bin/roave-backward-compatibility-check --baseline=1.2.0
.roave-backward-compatibility-check.xml (if exists):
<ignored-regex>#\[BC\] REMOVED: Method TestClass\#deprecatedMethod\(\)#</ignored-regex>
composer.json:
autoload covers all source paths (required for accurate analysis).Local Checks:
vendor/bin/roave-backward-compatibility-check --baseline=origin/main
--format=markdown to generate a changelog-friendly report:
vendor/bin/roave-backward-compatibility-check --format=markdown > CHANGELOG.md
Branch-Specific Baselines:
feature-branch vs. main):
vendor/bin/roave-backward-compatibility-check --baseline=main
CI Pipeline Integration:
- name: BC Check
run: vendor/bin/roave-backward-compatibility-check --format=github-actions
--format=github-actions).Service Container Classes:
--baseline to compare against the last stable version before major releases.Eloquent Models:
fillable, casts).@internal PHPDoc to avoid noise.Custom Artisan Commands:
Dynamic Baselines:
--baseline to compare against a specific commit/tag:
vendor/bin/roave-backward-compatibility-check --baseline=v1.2.0
Ignoring False Positives:
.roave-backward-compatibility-check.xml:
<ignored-regex>#\[BC\] CHANGED: Parameter \$model of App\Services\#update\(\)#</ignored-regex>
Illuminate\Contracts dependencies.Git Tag Requirements:
v1.2.3).--baseline or ensure tags are pushed to remote.False Positives in Laravel:
.roave-backward-compatibility-check.xml:
<ignored-path>vendor/laravel/</ignored-path>
Enum and Attribute Changes:
--baseline to compare against a version where the change was intentional.Reflection Errors:
__call/__callStatic methods may cause parsing errors.<ignored-class>App\DynamicProxy\Handler</ignored-class>
Verbose Output:
vendor/bin/roave-backward-compatibility-check --verbose
Dry Run:
vendor/bin/roave-backward-compatibility-check --dry-run
JSON Output for Scripting:
vendor/bin/roave-backward-compatibility-check --format=json > bc-results.json
$results = json_decode(file_get_contents('bc-results.json'), true);
$critical = array_filter($results, fn($item) => $item['type'] === 'REMOVED');
Custom Formatters:
JsonFormatter or create a new formatter by implementing FormatterInterface.Hooks for Pre/Post-Analysis:
--hook to run scripts before/after analysis (e.g., cleanup temporary files):
vendor/bin/roave-backward-compatibility-check --hook="php ./scripts/pre-bc-check.php"
PHP 8.4+ Support:
set_hook()).--baseline for manual comparisons.Facade Changes:
App::make() → app()) may not be detected.config/app.php alongside BC checks.Dynamic Proxies:
<ignored-class>App\Proxies\*</ignored-class>
Service Provider Booting:
composer dump-autoload to ensure up-to-date class maps:
composer dump-autoload && vendor/bin/roave-backward-compatibility-check
How can I help you explore Laravel packages today?