diff --git a/src/Expectation.php b/src/Expectation.php index 879f7131..17479ba6 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -158,6 +158,16 @@ 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 $count matches the number of elements of the value. */ 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);