PHPUnit's assertion failure diffs are produced by three packages working together:
sebastian/diff provides Differ, UnifiedDiffOutputBuilder, and StrictUnifiedDiffOutputBuilder
- In
sebastian/comparator, ComparisonFailure::getDiff() instantiates Differ with a hard-coded UnifiedDiffOutputBuilder
phpunit/phpunit instantiates Differ directly in TestCase (global state snapshot comparison) and StringMatchesFormatDescription constraint
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.
PHPUnit's assertion failure diffs are produced by three packages working together:
sebastian/diffprovidesDiffer,UnifiedDiffOutputBuilder, andStrictUnifiedDiffOutputBuildersebastian/comparator,ComparisonFailure::getDiff()instantiatesDifferwith a hard-codedUnifiedDiffOutputBuilderphpunit/phpunitinstantiatesDifferdirectly inTestCase(global state snapshot comparison) andStringMatchesFormatDescriptionconstraintCurrently, 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.$contextLinesconstructor parameter onUnifiedDiffOutputBuilderdiff#135UnifiedDiffOutputBuilderhardcodescontextLines = 3with no way for callers to override it. Before PHPUnit can offer a--diff-contextoption, the underlying builder must accept the value.All call sites in PHPUnit that construct
ComparisonFailureneed to pass the configured$contextLinesvalue throughUnifiedDiffOutputBuilderbehavior withStrictUnifiedDiffOutputBuilderdiff#136StrictUnifiedDiffOutputBuilderinstead ofUnifiedDiffOutputBuildercomparator#138StrictUnifiedDiffOutputBuilderinstead ofUnifiedDiffOutputBuilder#6569