diff --git a/src/Tempest/Support/src/StringHelper.php b/src/Tempest/Support/src/StringHelper.php index d0a093573..a423cbed2 100644 --- a/src/Tempest/Support/src/StringHelper.php +++ b/src/Tempest/Support/src/StringHelper.php @@ -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); + } } diff --git a/src/Tempest/Support/tests/StringHelperTest.php b/src/Tempest/Support/tests/StringHelperTest.php index d68a0bd8c..d3f3667e1 100644 --- a/src/Tempest/Support/tests/StringHelperTest.php +++ b/src/Tempest/Support/tests/StringHelperTest.php @@ -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')); + } }