Skip to content

[12.x] Add test coverage for Str::replaceMatches method #54930

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

Conversation

mohammadrasoulasghari
Copy link
Contributor

Add test coverage for Str::replaceMatches method ✨

This PR adds comprehensive test coverage for the Str::replaceMatches method to ensure it correctly handles string replacements, array patterns, callback functions, and limit parameters.

The test cases cover three main aspects of the method's functionality:

  1. Basic string replacement

    • Simple pattern replacement with static strings
    • Handling non-matching patterns correctly
  2. Array-based pattern replacement

    • Testing multiple patterns and replacements in a single call
  3. Callback-based replacement

    • Testing dynamic replacements using callback functions
    • Verifying capture group access within callbacks
    • Ensuring proper handling of complex transformations (like numeric operations)
  4. Limit parameter functionality

    • Testing the behavior when limiting the number of replacements

The implementation follows the established testing patterns in the Laravel codebase, making it consistent with the existing test suite. I discovered while reviewing the code that the Str::replaceMatches method lacked any test coverage.🔍

This commit adds tests for the basic functionality of the replaceMatches
method using string replacements and array of patterns.
This commit finalizes the test coverage for the replaceMatches method
by adding tests for the limit parameter, which controls the maximum
number of replacements to be performed.
@mohammadrasoulasghari mohammadrasoulasghari force-pushed the feat/tests-for-str-replace-matches branch from 89f47b6 to ec19d6e Compare March 7, 2025 11:03
@taylorotwell taylorotwell merged commit 189a0bb into laravel:12.x Mar 7, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants