Overview of Request Factories
mainRequest Factories allow you to test Laravel routes by faking FormRequest validation requirements. Instead of manually providing every field required by a FormRequest in every test, you can call the fake() method on the request class. This method automatically populates the request with valid data for all required fields, allowing you to focus your test on the specific field or behavior you are actually testing.
// Without Request Factories (Boilerplate heavy)
$this->put('/users', [
'phone' => '+375 154 767 1088',
'email' => 'foo@bar.com',
'name' => 'Luke Downing',
'company' => 'Worksome',
'bio' => 'Blah blah blah',
'profile_picture' => UploadedFile::fake()->image('luke.png', 200, 200),
'accepts_terms_and_conditions' => true,
]);
// With Request Factories (Clean and focused)
SignupRequest::fake();
$this->put('/users', ['phone' => '+375 154 767 1088']);