Last year I wrote a post about https://dev.to///2021/05/25/testing-validation-rules-in-a-livewire-component.html with PHP Unit. This post uses the same techniques as that post, but shows how to transfer it to Pest instead of PHP Unit.

It was carefully crafted to bring the joy of testing to PHP.

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 Other Pest features
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