From 75ccc42b9d582d11c5422abc754be698030cfd63 Mon Sep 17 00:00:00 2001 From: LucasBrunner Date: Fri, 20 Dec 2024 13:22:22 -0500 Subject: [PATCH] Adds documentation for /lorisleiva/laravel-actions/pull/302 --- 2.x/as-fake.md | 12 ++++++++++++ 2.x/mock-and-test.md | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/2.x/as-fake.md b/2.x/as-fake.md index 47262c2..2eb7d9e 100644 --- a/2.x/as-fake.md +++ b/2.x/as-fake.md @@ -60,6 +60,18 @@ FetchContactsFromGoogle::shouldNotRun(); FetchContactsFromGoogle::mock()->shouldNotReceive('handle'); ``` +### `shouldExpect` +Helper method adding an expectation on the `handle` method. + +```php +FetchContactsFromGoogle::shouldExpect(); + +// Equivalent to: +FetchContactsFromGoogle::shouldRun()->once(); +// And: +FetchContactsFromGoogle::mock()->expects('handle'); +``` + ### `allowToRun` Helper method allowing the `handle` method on a spy. diff --git a/2.x/mock-and-test.md b/2.x/mock-and-test.md index d68945b..8117fd4 100644 --- a/2.x/mock-and-test.md +++ b/2.x/mock-and-test.md @@ -36,6 +36,17 @@ FetchContactsFromGoogle::shouldNotRun(); FetchContactsFromGoogle::mock()->shouldNotReceive('handle'); ``` +The helper method `shouldExpect` is the same as `shouldRun` but adds the expection that `handle` will be called once and only once. + +```php +FetchContactsFromGoogle::shouldExpect(); + +// Equivalent to: +FetchContactsFromGoogle::shouldRun()->once(); +// And: +FetchContactsFromGoogle::mock()->expects('handle'); +``` + ## Partial mocking If you only want to mock the methods that have expectations, you may use the `partialMock` method instead. In the example below, only the `fetch` method will be mocked.