From 041aa190f710ee333f580b543821cded6c63e03d Mon Sep 17 00:00:00 2001 From: Saleh Hashemi <81674631+salehhashemi1992@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:56:47 +0330 Subject: [PATCH] Add unit tests for replaceMatches method (#48771) --- tests/Support/SupportStringableTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index dc82faf86859..39506394a044 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -1187,6 +1187,21 @@ public function testStripTags() $this->assertSame('before
after', (string) $this->stringable('before
after')->stripTags('
')); } + 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());