Skip to content

Commit

Permalink
Add test case for Form macro
Browse files Browse the repository at this point in the history
  • Loading branch information
curder committed Jun 12, 2024
1 parent 38f5410 commit e6dd2c2
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions docs/others/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,31 @@ Event::macro('logAndDispatch', function($event) {

### `Form`

```php
Form::macro('customInput', function($name, $value) {
return "<input type='text' name='{$name}' value='{$value}' />";
});
Filament 中的 Form 类允许自定义宏。

::: code-group
```php [定义]
use Filament\Forms\Form;

Form::macro('customInput', fn (string $name, mixed $value): string => "<input type='text' name='{$name}' value='{$value}' />");
```

```php [测试]
it('has customInput method for form', function (string $name, mixed $value) {

$output = \Filament\Forms\Form::customInput($name, $value);

$expect = "<input type='text' name='{$name}' value='{$value}' />";

expect($output)->toEqual($expect);
})->with([
['name', null],
['name', ''],
['name', 'value']
]);
```
:::

### `File`

通过 `File` 提供的宏,可以方便的自定义文件类型验证规则。
Expand All @@ -384,7 +403,7 @@ Form::macro('customInput', function($name, $value) {
// AppServiceProvider.php
use Illuminate\Validation\Rules\File;

File::macro('document', fn() => File::types(['pdf', 'rtf', 'doc', 'docx']));
File::macro('document', fn (): File => File::types(['pdf', 'rtf', 'doc', 'docx']));
```

```php [使用]
Expand Down

0 comments on commit e6dd2c2

Please sign in to comment.