Skip to content

Support sebastian/diff 9 - #93

Merged
ruudk merged 1 commit into
ruudk:mainfrom
Orest-Divintari:fix-sebastian-diff-9-compat
Aug 4, 2026
Merged

Support sebastian/diff 9#93
ruudk merged 1 commit into
ruudk:mainfrom
Orest-Divintari:fix-sebastian-diff-9-compat

Conversation

@Orest-Divintari

@Orest-Divintari Orest-Divintari commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

UnifiedDiffOutputBuilder was removed in sebastian/diff 9.0.0 (#157), but composer.json already allows ^7 || ^8 || ^9. With 9.x installed, --ensure-sync dies before comparing a single file:

 [ERROR] Generation failed: Class "SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder" not found

The builder is constructed unconditionally in the $ensureSync branch, so every --ensure-sync run fails, in sync or not.

We hit this while upgrading to PHPUnit 13.2, which requires sebastian/diff ^9.0 — so any consumer on PHPUnit 13.2+ can no longer run the sync guard.

Fix

StrictUnifiedDiffOutputBuilder with fromFile/toFile renders a byte-identical header (--- Actual\n+++ Expected\n). Those two options exist in 7.x, 8.x and 9.x alike, so the constraint needs no change and nothing drops out of support.

Note that header would not work here — that option only arrived in 8.3.0, and on older versions the constructor then throws because fromFile/toFile are still null. That would break the ^7 || ^8.0 end of the range.

One deliberate output change

Hunk headers now carry line numbers, because StrictUnifiedDiffOutputBuilder defaults addLineNumbers to true where UnifiedDiffOutputBuilder defaulted it to false:

-@@ @@
+@@ -641,7 +641,7 @@

Everything else — header, context lines, +/- markers — is unchanged, and formatDiff() colours the new header fine since it still matches str_starts_with($line, '@@').

This seemed worth keeping: the diff is console output for a human chasing drift in a long generated file, so knowing it is around line 641 beats searching for the snippet, and the output becomes a valid unified diff that patch accepts. Happy to pass 'addLineNumbers' => false instead if you would rather the output stay byte-identical.

Verified

  • vendor/bin/phpunit — 185 tests, 667 assertions, OK
  • vendor/bin/php-cs-fixer check — clean
  • vendor/bin/phpstan analyse — no errors
  • --ensure-sync against a real project with sebastian/diff 9.0.0 installed, both in sync ("Generated code is in sync ✅") and with deliberate drift in a 1113-line generated file

UnifiedDiffOutputBuilder was removed in sebastian/diff 9.0.0, while the
constraint here already allows ^9. Installing that version makes
--ensure-sync fatal with "Class UnifiedDiffOutputBuilder not found"
before it compares a single file.

StrictUnifiedDiffOutputBuilder renders the same header through fromFile
and toFile, and both options exist in ^7, ^8 and ^9, so the constraint
can stay as it is.

@ruudk ruudk left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@Orest-Divintari
Orest-Divintari force-pushed the fix-sebastian-diff-9-compat branch from aa75a31 to 1550d9c Compare August 4, 2026 05:18
@ruudk

ruudk commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Could you also provide a PR that bumps the minimum for diff to v9?

@ruudk
ruudk merged commit b0b80ef into ruudk:main Aug 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants