sebastianbergmann / phpunit

The PHP Unit Testing framework.

Home Page:https://phpunit.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add assertions for ignoring whitespace differences in strings

andrewnicols opened this issue · comments

ICU 72.1 replaced an ASCII space with a Unicode Narrow-Non-Breaking-Space.
In our codebase we have some code which works with \DateTime to produce dates in various formats and we confirm that the output is correct.

With the changes in ICU 72.1 out tests break because the visually identical space is different.

It would not be correct to update the string in the test because it is dependent upon the version of ICU installed on the test system.

PHPUnit already has assertions for things like assertEqualsIgnorningCase, assertStringContainsStringIgnoringCase, and assertEqualsCanonicalizing.

I wonder whether there is some merit in creatinng an assertion for assertEqualsIgnoringWhitespace which would essentially add:

            if ($ignoreCase) {
                $expectedToCompare = strtolower($expectedToCompare);
                $actualToCompare   = strtolower($actualToCompare);
            }

            if ($ignoreWhitespace) {
                $expectedToCompare = preg_replace('/\s/u', ' ', $expectedToCompare);
                $actualToCompare = preg_replace('/\s/u', ' ', $actualToCompare);
            }