-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
StringContains: bug fix for ignoring line endings #5279
Merged
sebastianbergmann
merged 1 commit into
sebastianbergmann:10.0
from
jrfnl:feature/stringcontainsstringignorelineendings-bugfix
Mar 13, 2023
Merged
StringContains: bug fix for ignoring line endings #5279
sebastianbergmann
merged 1 commit into
sebastianbergmann:10.0
from
jrfnl:feature/stringcontainsstringignorelineendings-bugfix
Mar 13, 2023
+31
−4
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As things were, at the time of the comparison, only the line endings of the `$haystack` were normalized, not the line endings of the `$needle`, which led to false negatives. Fixed now. Includes additional tests demonstrating the issue and safeguarding the fix. Includes a similar additional test for the case-insensitivity check, which did not have this issue, but wasn't being safeguarded against it either.
Note: the CI / Coding style issue is unrelated to this PR and I believe it's a false positive anyway. |
|
jrfnl
added a commit
to Yoast/PHPUnit-Polyfills
that referenced
this pull request
Mar 30, 2023
…sertStringEqualsStringIgnoringLineEndings() et al methods PHPUnit 10.0.0 introduces the new `Assert::assertStringEqualsStringIgnoringLineEndings()` and `Assert::assertStringContainsStringIgnoringLineEndings()` methods. This commit: * Adds two traits with the same name. One to polyfill the methods when not available in PHPUnit. The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available. * Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used. * An availability test and limited functional test for the functionality polyfilled. Note: the function name for the `private` `normalizeLineEndings()` method is a little convoluted - `normalizeLineEndingsForIgnoringLineEndingsAssertions()`. This is intentional to prevent potential naming collisions with pre-existing end-user defined methods for the same, which may exist in other traits used in tests, which would be hard to solve due to the method only existing in the non-empty trait. Includes: * Adding the new polyfill to the existing `TestCases` classes. Refs: * sebastianbergmann/phpunit#4641 * sebastianbergmann/phpunit#4670 (and follow up commits) * sebastianbergmann/phpunit#5279 Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl
added a commit
to Yoast/PHPUnit-Polyfills
that referenced
this pull request
Mar 30, 2023
…sertStringEqualsStringIgnoringLineEndings() et al methods PHPUnit 10.0.0 introduces the new `Assert::assertStringEqualsStringIgnoringLineEndings()` and `Assert::assertStringContainsStringIgnoringLineEndings()` methods. This commit: * Adds two traits with the same name. One to polyfill the methods when not available in PHPUnit. The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available. * Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used. * An availability test and limited functional test for the functionality polyfilled. Note: the function name for the `private` `normalizeLineEndings()` method is a little convoluted - `normalizeLineEndingsForIgnoringLineEndingsAssertions()`. This is intentional to prevent potential naming collisions with pre-existing end-user defined methods for the same, which may exist in other traits used in tests, which would be hard to solve due to the method only existing in the non-empty trait. Includes: * Adding the new polyfill to the existing `TestCases` classes. Refs: * sebastianbergmann/phpunit#4641 * sebastianbergmann/phpunit#4670 (and follow up commits) * sebastianbergmann/phpunit#5279 Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl
added a commit
to Yoast/PHPUnit-Polyfills
that referenced
this pull request
Mar 30, 2023
…sertStringEqualsStringIgnoringLineEndings() et al methods PHPUnit 10.0.0 introduces the new `Assert::assertStringEqualsStringIgnoringLineEndings()` and `Assert::assertStringContainsStringIgnoringLineEndings()` methods. This commit: * Adds two traits with the same name. One to polyfill the methods when not available in PHPUnit. The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available. * Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used. * An availability test and limited functional test for the functionality polyfilled. Note: the function name for the `private` `normalizeLineEndings()` method is a little convoluted - `normalizeLineEndingsForIgnoringLineEndingsAssertions()`. This is intentional to prevent potential naming collisions with pre-existing end-user defined methods for the same, which may exist in other traits used in tests, which would be hard to solve due to the method only existing in the non-empty trait. Includes: * Adding the new polyfill to the existing `TestCases` classes. Refs: * sebastianbergmann/phpunit#4641 * sebastianbergmann/phpunit#4670 (and follow up commits) * sebastianbergmann/phpunit#5279 Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl
added a commit
to Yoast/PHPUnit-Polyfills
that referenced
this pull request
Apr 1, 2023
…sertStringEqualsStringIgnoringLineEndings() et al methods PHPUnit 10.0.0 introduces the new `Assert::assertStringEqualsStringIgnoringLineEndings()` and `Assert::assertStringContainsStringIgnoringLineEndings()` methods. This commit: * Adds two traits with the same name. One to polyfill the methods when not available in PHPUnit. The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available. * Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used. * An availability test and limited functional test for the functionality polyfilled. Note: the function name for the `private` `normalizeLineEndings()` method is a little convoluted - `normalizeLineEndingsForIgnoringLineEndingsAssertions()`. This is intentional to prevent potential naming collisions with pre-existing end-user defined methods for the same, which may exist in other traits used in tests, which would be hard to solve due to the method only existing in the non-empty trait. Includes: * Adding the new polyfill to the existing `TestCases` classes. Refs: * sebastianbergmann/phpunit#4641 * sebastianbergmann/phpunit#4670 (and follow up commits) * sebastianbergmann/phpunit#5279 Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As things were, at the time of the comparison, only the line endings of the
$haystack
were normalized, not the line endings of the$needle
, which led to false negatives.Fixed now.
Includes additional tests demonstrating the issue and safeguarding the fix.
Includes a similar additional test for the case-insensitivity check, which did not have this issue, but wasn't being safeguarded against it either.