I have a test to test, if a client can checkin with all required fields:
public function test_client_can_checkin()
{
$client = Client::factory()->create();
$response = $this->post('/', $client->toArray());
$response->assertStatus(200);
}
In addition I have some validation rules in place:
return [
'uniqid' => ['required', 'string', 'max:255'],
'realm' => ['required', 'string', 'max:255'],
'fn' => ['required', 'string', 'max:255'],
'ln' => ['required', 'string', 'max:255'],
'email' => ['required', 'email'],
'phone' => ['required', 'string', 'max:255'],
'street' => ['required', 'string', 'max:255'],
'zip' => ['required', 'integer', 'digits:5'],
'city' => ['required', 'string', 'max:255'],
'dob' => ['required', 'date']
];
Is there a short hand way to test against all validation rules, instead of writing a test for each rule?
E.g.
public function test_client_can_not_checkin_with_missing_values()
{
$client = Client::factory()->create();
unset($client->uniqid);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->realm);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->fn);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->ln);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->email);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->phone);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->street);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->zip);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->city);
$this->post('/', $client->toArray())
->assertStatus(302);
$client = Client::factory()->create();
unset($client->dob);
$this->post('/', $client->toArray())
->assertStatus(302);
}
I would now continue like this with all the restrictions of type (email / string) and length and so on...