Skip to content

Commit

Permalink
feat: add str::startswith and endswith (tempestphp#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt authored Sep 25, 2024
1 parent df14709 commit 3ac79d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Tempest/Support/src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,14 @@ public function classBasename(): self
{
return new self(basename(str_replace('\\', '/', $this->string)));
}

public function startsWith(string $needle): bool
{
return str_starts_with($this->string, $needle);
}

public function endsWith(string $needle): bool
{
return str_ends_with($this->string, $needle);
}
}
12 changes: 12 additions & 0 deletions src/Tempest/Support/tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@ public function test_str_before_last(): void
$this->assertTrue(str('tempest framework')->beforeLast(' ')->equals('tempest'));
$this->assertTrue(str("yvette\tyv0et0te")->beforeLast("\t")->equals('yvette'));
}

public function test_starts_with(): void
{
$this->assertTrue(str('abc')->startsWith('a'));
$this->assertFalse(str('abc')->startsWith('c'));
}

public function test_ends_with(): void
{
$this->assertTrue(str('abc')->endsWith('c'));
$this->assertFalse(str('abc')->endsWith('a'));
}
}

0 comments on commit 3ac79d6

Please sign in to comment.