Skip to content

Commit 89f47b6

Browse files
Complete Str::replaceMatches tests with limit parameter tests
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.
1 parent 39169a1 commit 89f47b6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/Support/SupportStrTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,6 @@ public function testReplaceMatches()
17631763
{
17641764
// Test basic string replacement
17651765
$this->assertSame('foo bar bar', Str::replaceMatches('/baz/', 'bar', 'foo baz bar'));
1766-
$this->assertSame('foo BBB baz', Str::replaceMatches('/bar/', 'BBB', 'foo bar baz'));
17671766
$this->assertSame('foo baz baz', Str::replaceMatches('/404/', 'found', 'foo baz baz'));
17681767

17691768
// Test with array of patterns
@@ -1781,6 +1780,15 @@ public function testReplaceMatches()
17811780
}, 'foo 123 bar 456');
17821781

17831782
$this->assertSame('foo 246 bar 912', $result);
1783+
1784+
// Test with limit parameter
1785+
$this->assertSame('foo baz baz', Str::replaceMatches('/ba(.)/', 'ba$1', 'foo baz baz', 1));
1786+
1787+
$result = Str::replaceMatches('/ba(.)/', function ($match) {
1788+
return 'ba'.strtoupper($match[1]);
1789+
}, 'foo baz baz bar', 1);
1790+
1791+
$this->assertSame('foo baZ baz bar', $result);
17841792
}
17851793
}
17861794

0 commit comments

Comments
 (0)