sebastian/diff
Standalone PHP diff library extracted from PHPUnit. Generate textual diffs between strings with configurable output builders (unified, strict unified, diff-only) or custom formats, and parse unified diffs into an object model for further processing.
/compare endpoints, CLI diffs for logs/configs).DiffOutputBuilderInterface, enabling tailored diffs for Laravel’s admin panels, audit logs, or third-party integrations.php artisan diff:compare for file/config comparisons).ddl outputs).Parser for pull request reviews).| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | - v9.0+: Removed UnifiedDiffOutputBuilder; migrate to StrictUnifiedDiffOutputBuilder (backward-compatible in most cases). |
| - Deprecated LCS: No runtime impact until PHP 8.3 migration; phase out custom implementations gradually. | |
| Performance Overhead | - Myers’ algorithm is faster for large diffs (e.g., 10K+ lines); benchmark against custom logic in Laravel’s CI/CD. |
| Output Format Inconsistency | Standardize on StrictUnifiedDiffOutputBuilder across all tools to ensure predictable diffs (e.g., line numbers, headers). |
| Customization Limits | Extend via DiffOutputBuilderInterface for niche formats (e.g., Markdown, JSON diffs). |
| PHP 8.3+ Compatibility | Drop support for PHP <8.3 in Laravel’s roadmap; align with Laravel’s PHP version policy. |
DiffService in Laravel’s container) or decentralized (per-component usage)?laravel-debugbar, telescope) that could leverage this package for enhanced diffs?StrictUnifiedDiffOutputBuilder globally, or allow flexibility for specific use cases?laravel.log) for critical comparisons (e.g., database migrations)?File facade diffing or other ad-hoc implementations?Differ for consistent test failures.diff:compare command for CLI-based file/config comparisons.Differ and Parser as singletons for centralized access:
$this->app->singleton(Differ::class, fn() => new Differ(new StrictUnifiedDiffOutputBuilder));
$this->app->singleton(Parser::class, fn() => new Parser);
Schema::getConnection()->getDoctrineSchema() outputs).cache:table contents, queue payloads).Http::asJson() diffs).Parser for pull request reviews).| Phase | Action Items | Dependencies | Risk |
|---|---|---|---|
| Assessment | Audit all diff usages in Laravel (tests, CLI, admin panels, migrations). Identify custom implementations to replace. | None | Low |
| Core Integration | 1. Add sebastian/diff to composer.json (dev dependency if only for tests). 2. Bind Differ and Parser to Laravel’s container. 3. Replace UnifiedDiffOutputBuilder with StrictUnifiedDiffOutputBuilder. |
PHP 8.1+ | Medium (breaking change) |
| Testing | 1. Update test assertions to use Differ. 2. Add snapshot tests for diff outputs. 3. Benchmark performance vs. custom implementations. |
PHPUnit/PestPHP | Low |
| CLI Tools | Add an artisan diff:compare command for manual file/config comparisons. |
Symfony Console | Low |
| Admin Panels | Integrate diffs into Laravel Debugbar or custom admin tools (e.g., config file comparisons). | Laravel Debugbar (optional) | Medium (UI changes) |
| CI/CD | Replace custom diff scripts with Differ/Parser (e.g., for migration validation, API response testing). |
GitHub Actions/GitLab CI | High (CI pipeline changes) |
| Database | Use Parser to compare migration files or schema dumps. |
Laravel Migrations | Medium (edge cases) |
| API Layer | Add diff assertions to API tests (e.g., assertEquals($expectedJson, $actualJson, '', true, true, $this->app->make(Differ::class))). |
Laravel HTTP Testing | Low |
StrictUnifiedDiffOutputBuilder is mostly compatible with UnifiedDiffOutputBuilder (except for strict formatting).DiffOutputBuilder implementations may need updates if relying on deprecated methods.Storage facade for file comparisons.Assert facade or PestPHP assertions.filesystem.updated events).How can I help you explore Laravel packages today?