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

StringContains: bug fix for ignoring line endings #5279

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Framework/Constraint/String/StringContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final class StringContains extends Constraint

public function __construct(string $string, bool $ignoreCase = false, bool $ignoreLineEndings = false)
{
if ($ignoreLineEndings) {
$string = $this->normalizeLineEndings($string);
}

$this->string = $string;
$this->ignoreCase = $ignoreCase;
$this->ignoreLineEndings = $ignoreLineEndings;
Expand All @@ -43,10 +47,6 @@ public function toString(): string
$string = mb_strtolower($this->string, 'UTF-8');
}

if ($this->ignoreLineEndings) {
$string = $this->normalizeLineEndings($string);
}

return sprintf(
'contains "%s"',
$string
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/Framework/Constraint/String/StringContainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public static function provider(): array
'prefix SUBSTRING suffix',
],

[
true,
'',
true,
false,
'SUBSTRING',
'prefix substring suffix',
],

[
true,
'',
Expand All @@ -68,6 +77,24 @@ public static function provider(): array
"prefix substring\r\n suffix",
],

[
true,
'',
false,
true,
"substring\r suffix",
"prefix substring\n suffix",
],

[
true,
'',
false,
true,
"substring\r\n suffix",
"prefix substring\r suffix",
],

[
true,
'',
Expand Down