• Reading time ~ 1 min
  • 10.10.2023

The Laravel Form Request Tester package is a collection of helpers that help test form requests. There are various ways to test form requests, either directly or through HTTP tests, that validate the behavior in form requests.

This package has helpers to scaffold a fake route if you want to isolate tests around your form request. You start by importing the provided testing trait TestsFormRequests:

use MohammedManssour\FormRequestTester\TestsFormRequests;

class SomeTest extends TestCase
{
     use TestsFormRequests;

     // ...
}

The trait provides a formRequest method you can use to set up the form request and perform assertions on the form:

$form = $this->formRequest(UpdatePost::class)
    ->withRoute('posts/{post}')
    ->put(['title' => 'New Title']);

// Assertions
$form
    ->assertAuthorized()
    ->assertValidationFailed()
    ->assertValidationErrors(['content'])
    ->assertValidationErrorsMissing(['title'])
    ->assertValidationMessages(['Content field is required']);

There are some other assertion methods you can use to assert passing validation, authorization, and validation data:

$form->assertValidationPassed();
$form->assertNotAuthorized();
$form->assertValidationData($data);
$form->assertValidationDataMissing($data);

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297