Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds documentation for lorisleiva/laravel-actions/pull/302 #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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