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