I have laravel rules validation and i want test it all give rules with one method and dataProvider using phpunit
For example i have rules required|string|max:255
i want test required
string and
max:255` rules without writing test method separately
But i only can do it for required
rules only i want test the second rules like digit_between
for identity field but first_name
field doesnt have digit_between
but is string
- here my example rules code
{
return [
'identity_number' => 'required|digits_between:1,255|unique:borrowers',
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'birthdate' => 'required|date',
];
}
2.testing code :
/**
* Test store validation.
*
* @return void
*
* @group user
* @dataProvider requiredStoreValidationProvider
*/
public function testStoreValidation($formInput, $formInputValue)
{
$response = $this->actingAs($this->user)
->post(route('borrower.store'), [
$formInput => $formInputValue,
]);
$response->assertSessionHasErrorsIn('validation', $formInput);
}
/**
* Required store data validation provider.
*
* @return \string[][]
*/
public function requiredStoreValidationProvider()
{
return [
['identity_number', ''],
['first_name', ''],
['last_name', ''],
['birthdate', ''],
];
}
Aucun commentaire:
Enregistrer un commentaire