mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #15994 from ralphjsmit/rjs/check-if-macro-exists
Ability to check if macro exists
This commit is contained in:
@@ -39,6 +39,11 @@ trait Macroable
|
||||
static::$macros = [];
|
||||
}
|
||||
|
||||
public static function hasMacro(string $name): bool
|
||||
{
|
||||
return (bool) static::getMacro($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key> $parameters
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Filament\Forms\ComponentContainer;
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Support\Components\Component;
|
||||
use Filament\Tests\TestCase;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
test('component is macroable', function () {
|
||||
expect(ComponentContainer::hasMacro('someMacro'))
|
||||
->toBeFalse();
|
||||
|
||||
expect(ComponentContainer::hasMacro('someMacro'))
|
||||
->toBeFalse();
|
||||
|
||||
ComponentContainer::macro('someMacro', fn () => 'Hello');
|
||||
|
||||
expect(ComponentContainer::hasMacro('someMacro'))
|
||||
->toBeTrue();
|
||||
|
||||
expect(Form::hasMacro('someMacro'))
|
||||
->toBeTrue(); // Descendant of `Component`...
|
||||
|
||||
expect(Field::hasMacro('someMacro'))
|
||||
->toBeFalse();
|
||||
});
|
||||
Reference in New Issue
Block a user