From 6f21135cbe8ac6cb28da35f7177ce7a9717c2319 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 12 Jan 2024 22:15:15 +0100 Subject: [PATCH] improve fail() and fails() doc --- exceptions.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/exceptions.md b/exceptions.md index 1157863..54d3b65 100644 --- a/exceptions.md +++ b/exceptions.md @@ -64,7 +64,7 @@ it('throws no exceptions', function () { Sometimes, you may want to simply mark a test as failed. You can use the `fail()` method to do so. ```php -it('fail', function () { +it('fails', function () { $this->fail(); }); ``` @@ -72,25 +72,29 @@ it('fail', function () { You may also provide a message to the `fail()` method. ```php -it('fail', function () { +it('fails', function () { $this->fail('Something went wrong.'); }); ``` -In addition, you can also use the `fails()` method to verify the test fails. +In addition, you can also use the `fails()` method to verify if a test fails. ```php it('fails', function () { - throw new Exception('Something happened.'); + $this->fail('Something happened.'); })->fails(); ``` -Just like the `fail()` method, you may also provide a message to the `fails()` method. +You can also assert the failure reason by providing a message to the `fails()` method. ```php -it('fails', function () { - throw new Exception('Something happened.'); -})->fails('Something went wrong.'); +it('fails as expected', function () { + $this->fail('Something happened.'); +})->fails('Something happened.'); // Pass + +it('fails in an unexpected way', function () { + $this->fail('Something unexpected happened.'); +})->fails('Something happened.'); // Fail ``` ---