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 using datasets in higher order tests #82

Merged
merged 1 commit into from
Jul 21, 2021
Merged
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
18 changes: 18 additions & 0 deletions higher-order-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: Higher Order Tests
# Higher Order Tests

- [Overview](#overview)
- [Working with Datasets](#working-with-datasets)

<a name="overview"></a>
## Overview
Expand Down Expand Up @@ -70,6 +71,23 @@ test('the user has the correct values')
->withTitle('Mr')->toEqual('Mr Nuno Maduro');
```

## Working with Datasets

When working with [datasets](/docs/datasets), Pest allows you to access the dataset values in higher order
tests when using the `expect`, `and` or `tap` methods:

```php
it('validates the user names')
->with('badUsernames')
->expect(fn($name) => ValidateUserName::isValid($name)) // We receive the data as a parameter to `expect`
->toBeFalse();

it('inserts a user in the database')
->with('users')
->tap(fn($name, $email) => User::create(['name' => $name, 'email' => $email])) // You may receive multiple arguments
->assertDatabaseHas('users', 1);
```

---

Next section: [Custom Helpers →](/docs/helpers)