DEF STUDIO srl

Exceptions Expectations

toThrowValidationException() (available from v2, still with v1? Upgrade!)

Assert that the given closure throws an Illuminate\Validation\ValidationException

expect(fn() => $request->validate(/* rules */))->toThrowValidationException();

additionally, validation errors can be checked:

expect(fn() => $request->validate(/* rules */))
    ->toThrowValidationException([
        'field1' => ['field 1 is required'],
        'user.email' => ['user email must be a valid email address'],
    ]);
Suggest a change
Last updated 10 September 2024