diff --git a/src/Expectation.php b/src/Expectation.php index 879f7131..b156d558 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -158,6 +158,26 @@ final class Expectation return $this; } + /** + * Asserts that the value starts with $expected. + */ + public function toStartWith(string $expected): Expectation + { + Assert::assertStringStartsWith($expected, $this->value); + + return $this; + } + + /** + * Asserts that the value ends with $expected. + */ + public function toEndWith(string $expected): Expectation + { + Assert::assertStringEndsWith($expected, $this->value); + + return $this; + } + /** * Asserts that $count matches the number of elements of the value. */ diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 89093913..aae4b194 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -155,6 +155,11 @@ ✓ passes strings ✓ passes arrays ✓ failures + ✓ not failures + + PASS Tests\Expect\toEndWith + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toEqual @@ -195,6 +200,11 @@ PASS Tests\Expect\toMatchObject ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toStartWith + ✓ pass + ✓ failures ✓ not failures PASS Tests\Features\AfterAll @@ -363,5 +373,5 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 6 skipped, 214 passed + Tests: 6 skipped, 220 passed \ No newline at end of file diff --git a/tests/Expect/toEndWith.php b/tests/Expect/toEndWith.php new file mode 100644 index 00000000..e669795e --- /dev/null +++ b/tests/Expect/toEndWith.php @@ -0,0 +1,15 @@ +toEndWith('name'); +}); + +test('failures', function () { + expect('username')->toEndWith('password'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('username')->not->toEndWith('name'); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toStartWith.php b/tests/Expect/toStartWith.php new file mode 100644 index 00000000..64465869 --- /dev/null +++ b/tests/Expect/toStartWith.php @@ -0,0 +1,15 @@ +toStartWith('user'); +}); + +test('failures', function () { + expect('username')->toStartWith('password'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('username')->not->toStartWith('user'); +})->throws(ExpectationFailedException::class);