diff --git a/src/Expectation.php b/src/Expectation.php index 17479ba6..b156d558 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -168,6 +168,16 @@ final class Expectation 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/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);