Skip to content

Commit

Permalink
Adds documentation for /lorisleiva/laravel-actions/pull/302
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasBrunner committed Dec 20, 2024
1 parent 2db7703 commit 75ccc42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 2.x/as-fake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions 2.x/mock-and-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 75ccc42

Please sign in to comment.