Skip to content

Commit

Permalink
[11.x] Add some tests in SupportStrTest class (#51235)
Browse files Browse the repository at this point in the history
* improvement tests for beforeLast method

* improvement tests for Str::words

* improvement tests

* fixes code style
  • Loading branch information
saMahmoudzadeh authored Apr 29, 2024
1 parent f993b9c commit e38d945
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'));
Expand All @@ -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()
Expand Down

0 comments on commit e38d945

Please sign in to comment.