Skip to content

Improving PHPUnit's Diff Output #6570

@sebastianbergmann

Description

@sebastianbergmann

PHPUnit's assertion failure diffs are produced by three packages working together:

  1. sebastian/diff provides Differ, UnifiedDiffOutputBuilder, and StrictUnifiedDiffOutputBuilder
  2. In sebastian/comparator, ComparisonFailure::getDiff() instantiates Differ with a hard-coded UnifiedDiffOutputBuilder
  3. 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.

Metadata

Metadata

Labels

type/enhancementA new idea that should be implemented

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions