Skip to content

Commit

Permalink
Add unit tests for replaceMatches method (#48771)
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 authored Oct 18, 2023
1 parent 10ba03e commit 041aa19
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,21 @@ public function testStripTags()
$this->assertSame('<strong>before</strong><br>after', (string) $this->stringable('<strong>before</strong><br>after')->stripTags('<br><strong>'));
}

public function testReplaceMatches()
{
$stringable = $this->stringable('Hello world!');
$result = $stringable->replaceMatches('/world/', function ($match) {
return strtoupper($match[0]);
});

$this->assertSame('Hello WORLD!', $result->value);

$stringable = $this->stringable('apple orange apple');
$result = $stringable->replaceMatches('/apple/', 'fruit', 1);

$this->assertSame('fruit orange apple', $result->value);
}

public function testScan()
{
$this->assertSame([123456], $this->stringable('SN/123456')->scan('SN/%d')->toArray());
Expand Down

0 comments on commit 041aa19

Please sign in to comment.