Skip to content

Commit

Permalink
Fix #175: Add testcase for multibyte LikeHandler (#190)
Browse files Browse the repository at this point in the history
* Fix #175: Add testcase for multibyte LikeHandler

* Do not ignore mutants

* Use str_contains for case sensitive search

* Add CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Sergei Predvoditelev <[email protected]>

---------

Co-authored-by: Alexey Rogachev <[email protected]>
Co-authored-by: Sergei Predvoditelev <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2024
1 parent 9c31209 commit 5f7cc68
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- New #173, #184: Add `$caseSensitive` parameter to `Like` filter to control whether the search must be case-sensitive
or not (@arogachev)
- Chg #163: Rename `FilterableDataInterface::withFilterHandlers()` to `FilterableDataInterface::withAddedFilterHandlers()` (@samdark)
- Enh #190: Use `str_contains` for case-sensitive match in `LikeHandler` (@samdark)

## 1.0.1 January 25, 2023

Expand Down
3 changes: 1 addition & 2 deletions src/Reader/Iterable/FilterHandler/LikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public function match(object|array $item, FilterInterface $filter, array $iterab
return false;
}

/** @infection-ignore-all MBString No suitable test case was found yet. */
return $filter->isCaseSensitive() === true
? mb_strpos($itemValue, $filter->getValue()) !== false
? str_contains($itemValue, $filter->getValue())
: mb_stripos($itemValue, $filter->getValue()) !== false;
}
}
2 changes: 2 additions & 0 deletions tests/Reader/Iterable/FilterHandler/LikeHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static function matchDataProvider(): array
[false, ['id' => 1, 'value' => 'Great Cat Fighter'], 'id', '1', true],
[true, ['id' => 1, 'value' => '🙁🙂🙁'], 'value', '🙂', true],
[true, ['id' => 1, 'value' => 'Привет мир'], 'value', ' ', true],

[true, ['id' => 1, 'value' => 'das Öl'], 'value', 'öl', false],
];
}

Expand Down

0 comments on commit 5f7cc68

Please sign in to comment.