Level 25
Have you tried:
['title', '@#', NotHasSymbol::class]
1 like
For example in Filament has a form with post title input
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')
->required()
->string()
->rules([
'between:8,255',
new NotHasSymbol(),
])
->unique(ignoreRecord: true),
]);
}
and write a Test with use https://pestphp.com/docs/datasets
test('can not pass validation', function (
string $attribute,
string | array | null $value,
string $rule
) {
$component = Livewire::test(CreatePost::class)
->fillForm([
$attribute => $value,
])
->call('create');
$component->assertHasFormErrors([$attribute => $rule]);
})
->with([
['title', null, 'required'],
['title', ['array'], 'string'],
['title', 'a', 'between'],
['title', fn() => str('a')->repeat(256)->toString(), 'between'],
['title', '@#', 'if NotHasSymbol rule fail, what is the error key ??'], // <-----------
]);
Testing result
✓ can not pass validation with ('title', null, 'required')
✓ can not pass validation with ('title', ['array'], 'string')
✓ can not pass validation with ('title', 'a', 'between')
✓ can not pass validation with ('title', Closure, 'between')
Have you tried:
['title', '@#', NotHasSymbol::class]
Please or to participate in this conversation.