Skip to content

Add assertions for ignoring whitespace differences in strings #5757

Open
@andrewnicols

Description

@andrewnicols

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);
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/assertionIssues related to assertions and expectationstype/enhancementA new idea that should be implemented

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions