sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.69k stars 2.2k forks source link

Assertion failure is confusing when asserting a string matches a format #6026

Open stof opened 6 days ago

stof commented 6 days ago

When asserting a string matches a format fails, the failure produces a string diff between the string and the expected format. This is quite confusing because this diff will report differences for each placeholder in the expected format, even when the corresponding content in the string matched that placeholder (and the issue was elsewhere)

sebastianbergmann commented 6 days ago

I agree that this is confusing, but this is, AFAIK, how the official PHPT test runner has always worked. I mention PHPT here because assertStringMatchesFormat() (re)uses the code for EXPECTF handling in PHPT tests.

stof commented 6 days ago

Well, doing a format-aware diffing is more complex. But if the logic is implemented, maybe the official PHPT test runner would also accept using it to provide better failure reporting.