- How do I install sebastian/diff in a Laravel project?
- Use Composer with `composer require sebastian/diff` for production or `composer require --dev sebastian/diff` if only needed for testing. The package has no Laravel-specific dependencies and integrates seamlessly with PHPUnit/Pest.
- Can I use sebastian/diff to generate diffs for Laravel test assertions?
- Yes. Extend Pest or PHPUnit with a custom assertion using `Differ` and `UnifiedDiffOutputBuilder`. Example: `Pest::extend('diff', fn($expected, $actual) => (new Differ(new UnifiedDiffOutputBuilder))->diff($expected, $actual));` for human-readable failures.
- Does sebastian/diff support Laravel’s PHP 8.4+ requirements?
- Yes, sebastian/diff supports PHP 8.0+. If your Laravel app uses PHP 8.3, check the changelog for updates or consider alternatives like `symfony/diff` for broader compatibility.
- How do I parse Git diffs in Laravel using sebastian/diff?
- Use the `Parser` class to convert unified diff strings (e.g., from `Git::getDiff()`) into structured objects. This is useful for changelog generators or automated code review tools in Laravel applications.
- What output formats does sebastian/diff support for Laravel debugging?
- It provides three built-in formats: `UnifiedDiffOutputBuilder` (PHPUnit-style), `StrictUnifiedDiffOutputBuilder` (Git-compatible), and `DiffOnlyOutputBuilder` (minimal changes). For custom formats (e.g., HTML for Nova), implement `DiffOutputBuilderInterface`.
- Is sebastian/diff suitable for diffing large files in Laravel logs or migrations?
- While optimized, large diffs (e.g., multi-MB logs) may impact memory. Test performance with your largest expected payload. For production, consider streaming or chunking diff operations in Laravel queues.
- How can I integrate sebastian/diff with Laravel Telescope for debugging?
- Wrap `Differ` in a service provider to configure default output (e.g., `UnifiedDiffOutputBuilder`). Use Telescope’s `log` method to display diffs in the UI, replacing generic error messages with actionable patch-style output.
- Are there alternatives to sebastian/diff for Laravel array/object diffs?
- For non-textual data (e.g., arrays), use `spatie/array-diff`. sebastian/diff focuses on string diffs, making it ideal for text-based comparisons like config files, logs, or Git diffs in Laravel.
- Can I extend sebastian/diff to create custom diff formats for Laravel APIs?
- Yes. Implement `DiffOutputBuilderInterface` to generate formats like JSON or HTML. Example: Create a `JsonDiffOutputBuilder` for API responses or a `HtmlDiffOutputBuilder` for Nova tooltips.
- How does sebastian/diff handle thread safety in Laravel’s concurrent environments?
- The package is stateless and thread-safe by design. For heavy diff operations in Laravel queues (e.g., batch processing), benchmark performance to avoid memory spikes, but no locks or shared state are required.