Published: Aug 12, 2022 by C.S. Rhymes This post uses the same techniques as that post, but shows how to transfer it to Pest instead of PHP Unit.

Pest is a PHP testing framework built on top of PHP Unit and is not framework specific.

create(); $anotherUser = User::factory()->create(['email' => 'duplicate@email.com']); $this->actingAs($user); livewire(ProfileForm::class, ['user' => $user]) ->set($field, $value) ->call('save') ->assertHasErrors([$field => $rule]); })->with([ 'name is null' => ['user.name', null, 'required'], 'name is too long' => ['user.name', str_repeat('*', 201), 'max'], 'email is null' => ['user.email', null, 'required'], 'email is invalid' => ['user.email', 'this is not an email', 'email'], 'email is not unique' => ['user.email', 'duplicate@email.com', 'unique'], 'bio is null' => ['user.bio', null, 'required'], 'bio is too short' => ['user.bio', str_repeat('*', 8), 'min'], 'bio is too long' => ['user.bio', str_repeat('*', 1001), 'max'], ]); Other Pest features

An example of this is creating an admin user for all of the tests that need an admin user.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners