From e38d945fce91860c29f10a6bd4a19790ff25ad84 Mon Sep 17 00:00:00 2001 From: "S.a Mahmoudzadeh" <36761585+saMahmoudzadeh@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:53:52 +0330 Subject: [PATCH] [11.x] Add some tests in `SupportStrTest` class (#51235) * improvement tests for beforeLast method * improvement tests for Str::words * improvement tests * fixes code style --- tests/Support/SupportStrTest.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 909699b7a266..1bd26cbde1c3 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -12,11 +12,13 @@ class SupportStrTest extends TestCase { - public function testStringCanBeLimitedByWords() + public function testStringCanBeLimitedByWords(): void { $this->assertSame('Taylor...', Str::words('Taylor Otwell', 1)); $this->assertSame('Taylor___', Str::words('Taylor Otwell', 1, '___')); $this->assertSame('Taylor Otwell', Str::words('Taylor Otwell', 3)); + $this->assertSame('Taylor Otwell', Str::words('Taylor Otwell', -1, '...')); + $this->assertSame('', Str::words('', 3, '...')); } public function testStringCanBeLimitedByWordsNonAscii() @@ -114,11 +116,13 @@ public function testStringApa() $this->assertSame(' ', Str::apa(' ')); } - public function testStringWithoutWordsDoesntProduceError() + public function testStringWithoutWordsDoesntProduceError(): void { $nbsp = chr(0xC2).chr(0xA0); $this->assertSame(' ', Str::words(' ')); $this->assertEquals($nbsp, Str::words($nbsp)); + $this->assertSame(' ', Str::words(' ')); + $this->assertSame("\t\t\t", Str::words("\t\t\t")); } public function testStringAscii() @@ -265,7 +269,7 @@ public function testStrBefore() $this->assertSame('han', Str::before('han2nah', 2)); } - public function testStrBeforeLast() + public function testStrBeforeLast(): void { $this->assertSame('yve', Str::beforeLast('yvette', 'tte')); $this->assertSame('yvet', Str::beforeLast('yvette', 't')); @@ -276,6 +280,10 @@ public function testStrBeforeLast() $this->assertSame('yv0et', Str::beforeLast('yv0et0te', '0')); $this->assertSame('yv0et', Str::beforeLast('yv0et0te', 0)); $this->assertSame('yv2et', Str::beforeLast('yv2et2te', 2)); + $this->assertSame('', Str::beforeLast('', 'test')); + $this->assertSame('', Str::beforeLast('yvette', 'yvette')); + $this->assertSame('laravel', Str::beforeLast('laravel framework', ' ')); + $this->assertSame('yvette', Str::beforeLast("yvette\tyv0et0te", "\t")); } public function testStrBetween()