F
Filamentβ€’2y ago
bernhard

Filament::serving and tests

Hey! Maybe a stupid question, but how to get the code inside Filament::serving running in a Feature test? For performance reasons, I have some code inside Filament::serving , for example some Macros like:
Field::macro("onlyOnEdit", fn() => $this->hidden(fn($record) => !$record || !$record->exists));
Field::macro("onlyOnEdit", fn() => $this->hidden(fn($record) => !$record || !$record->exists));
When I run now a test, it doesn't find the macro, since the Filament::serving isn't called at all?
4 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Not sure how "safe" that is but maybe ServingFilament::dispatch() ?
bernhard
bernhardOPβ€’2y ago
Currently, my workaround is
protected function setUp(): void
{
parent::setUp();
(new FillyServiceProvider($this->app))->filamentMacros();
}
protected function setUp(): void
{
parent::setUp();
(new FillyServiceProvider($this->app))->filamentMacros();
}
` Where filamentMacros is the method which is called by serving. but thats obviously ugly. Dispatching is obviously better, not sure if its the best way πŸ˜„
Patrick Boivin
Patrick Boivinβ€’2y ago
I don't know if dispatching is better actually... I think in the spirit of only including predictable things in each test, your solution is a bit better πŸ‘Œ Maybe filamentMacros() could be static, and it could be simplified to FillyServiceProvider::filamentMacros()
bernhard
bernhardOPβ€’2y ago
Thanks!
Want results from more Discord servers?
Add your server