Skip to content

Commit 041aa19

Browse files
Add unit tests for replaceMatches method (#48771)
1 parent 10ba03e commit 041aa19

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/Support/SupportStringableTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,21 @@ public function testStripTags()
11871187
$this->assertSame('<strong>before</strong><br>after', (string) $this->stringable('<strong>before</strong><br>after')->stripTags('<br><strong>'));
11881188
}
11891189

1190+
public function testReplaceMatches()
1191+
{
1192+
$stringable = $this->stringable('Hello world!');
1193+
$result = $stringable->replaceMatches('/world/', function ($match) {
1194+
return strtoupper($match[0]);
1195+
});
1196+
1197+
$this->assertSame('Hello WORLD!', $result->value);
1198+
1199+
$stringable = $this->stringable('apple orange apple');
1200+
$result = $stringable->replaceMatches('/apple/', 'fruit', 1);
1201+
1202+
$this->assertSame('fruit orange apple', $result->value);
1203+
}
1204+
11901205
public function testScan()
11911206
{
11921207
$this->assertSame([123456], $this->stringable('SN/123456')->scan('SN/%d')->toArray());

0 commit comments

Comments
 (0)