Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertions for ignoring whitespace differences in strings #5757

Open
andrewnicols opened this issue Mar 20, 2024 · 0 comments
Open

Add assertions for ignoring whitespace differences in strings #5757

andrewnicols opened this issue Mar 20, 2024 · 0 comments
Labels
feature/assertion Issues related to assertions and expectations type/enhancement A new idea that should be implemented

Comments

@andrewnicols
Copy link
Contributor

andrewnicols commented Mar 20, 2024

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);
            }
@andrewnicols andrewnicols added the type/enhancement A new idea that should be implemented label Mar 20, 2024
@sebastianbergmann sebastianbergmann added the feature/assertion Issues related to assertions and expectations label Mar 20, 2024
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Mar 20, 2024
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Mar 21, 2024
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Mar 25, 2024
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Mar 25, 2024
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants