Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Diff Laravel Package

sebastian/diff

Standalone PHP diff library extracted from PHPUnit. Generate unified/strict unified diffs or diff-only output between strings via Differ and output builders, or parse unified diff text into an object graph with Parser for further processing.

View on GitHub
Deep Wiki
Context7

sebastian/diff is a lightweight PHP component for generating and parsing text diffs, extracted from PHPUnit into a standalone library. It helps you compare strings, produce readable patches, or turn unified diffs into structured objects for further processing.

Use Differ with configurable output builders (unified/strict/diff-only) to render changes, or Parser to convert a unified diff into an object graph—ideal for tooling, code review utilities, and test failure output.

  • Generate diffs between strings via Differ
  • Multiple formats: Unified, Strict Unified (patch/git apply compatible), Diff-only
  • Extensible output through DiffOutputBuilderInterface
  • Parse unified diffs into structured objects with Parser
  • Composer-friendly, production or dev dependency support
Frequently asked questions about Diff
How do I install sebastian/diff in a Laravel project?
Run `composer require sebastian/diff` for production use or `composer require --dev sebastian/diff` if only needed for testing. No Laravel-specific setup is required—it’s a standalone PHP library.
Can I use sebastian/diff with Laravel’s Pest or PHPUnit for test assertions?
Yes. Use the `Differ` class to generate human-readable diffs for test failures. For Pest, integrate it into custom expectations, and for PHPUnit, use it in listeners or assertions to replace generic failure messages.
What Laravel versions and PHP versions does sebastian/diff support?
The package requires PHP 8.4+. It works with any Laravel 10+ app (or newer) since those versions support PHP 8.4+. For older Laravel/PHP stacks, consider `symfony/diff` or `php-diff` as alternatives.
How do I customize the diff output format beyond UnifiedDiff or StrictUnifiedDiff?
Implement the `DiffOutputBuilderInterface` to create custom formats like JSON or minimalist CLI output. The package provides extensibility hooks for non-standard use cases, such as API responses or script-friendly diffs.
Is sebastian/diff suitable for real-time diffing in live collaboration tools?
No. While it’s efficient for most use cases (e.g., test failures, CI logs), it’s not optimized for high-frequency operations like live collaboration. For real-time needs, consider `diff-match-patch` or client-side libraries.
How can I integrate sebastian/diff with Laravel Debugbar or Telescope?
Use the `Differ` class to generate diffs for log entries or query results, then pass them to Debugbar’s `addMessage()` or Telescope’s `record()` methods. This visualizes changes in a user-friendly format.
Does sebastian/diff support parsing Git diffs into structured objects?
Yes. The `Parser` class converts unified diff text (e.g., from Git) into an object graph. This is useful for analyzing changes in CI/CD pipelines or CMS tools like Laravel Nova.
How do I handle malformed diffs or edge cases (e.g., binary files) in production?
Gracefully fall back to string diffs or implement custom error handling. The `Parser` may throw exceptions for invalid input; wrap it in a try-catch block or validate diffs before parsing.
Can I use sebastian/diff to compare database records or Eloquent models in Laravel?
Indirectly, yes. Serialize model attributes to strings (e.g., using `json_encode()`) and pass them to `Differ`. For complex comparisons, consider extending the `Differ` class or using a helper trait in your test suite.
What are the performance implications of using sebastian/diff in CI/CD pipelines?
The library is lightweight (~1MB) with minimal overhead. Benchmark in your pipeline to ensure it doesn’t slow down deployments. For large files, consider limiting diff context or pre-filtering changes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport