-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Improving PHPUnit's Diff Output #6570
Copy link
Copy link
Open
Labels
type/enhancementA new idea that should be implementedA new idea that should be implemented
Description
PHPUnit's assertion failure diffs are produced by three packages working together:
sebastian/diffprovidesDiffer,UnifiedDiffOutputBuilder, andStrictUnifiedDiffOutputBuilder- In
sebastian/comparator,ComparisonFailure::getDiff()instantiatesDifferwith a hard-codedUnifiedDiffOutputBuilder phpunit/phpunitinstantiatesDifferdirectly inTestCase(global state snapshot comparison) andStringMatchesFormatDescriptionconstraint
Currently, the context line count (3), the output builder choice (UnifiedDiffOutputBuilder), and the hunk header format (@@ @@ without line numbers) are all hard-coded with no user-facing configuration. This makes it difficult to read diffs for large, deeply nested structures, for example.
The goal is to incrementally move toward StrictUnifiedDiffOutputBuilder, which always produces spec-compliant unified diffs with proper hunk headers, while giving users control over context lines along the way.
- Add
$contextLinesconstructor parameter onUnifiedDiffOutputBuilderdiff#135
UnifiedDiffOutputBuilderhardcodescontextLines = 3with no way for callers to override it. Before PHPUnit can offer a--diff-contextoption, the underlying builder must accept the value. - Make diff context lines configurable in PHPUnit #6567
- Make diff context lines configurable comparator#137
All call sites in PHPUnit that constructComparisonFailureneed to pass the configured$contextLinesvalue through - Always show line numbers in hunk headers #6568
- Align
UnifiedDiffOutputBuilderbehavior withStrictUnifiedDiffOutputBuilderdiff#136 - Use
StrictUnifiedDiffOutputBuilderinstead ofUnifiedDiffOutputBuildercomparator#138 - Use
StrictUnifiedDiffOutputBuilderinstead ofUnifiedDiffOutputBuilder#6569
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type/enhancementA new idea that should be implementedA new idea that should be implemented