diff --git a/packages/forms/src/Concerns/InteractsWithForms.php b/packages/forms/src/Concerns/InteractsWithForms.php index 46e06186a1..0ffaec902f 100644 --- a/packages/forms/src/Concerns/InteractsWithForms.php +++ b/packages/forms/src/Concerns/InteractsWithForms.php @@ -13,6 +13,7 @@ use Filament\Support\Contracts\TranslatableContentDriver; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Validation\ValidationException; +use Livewire\Attributes\Locked; use Livewire\Attributes\Renderless; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\WithFileUploads; @@ -28,6 +29,9 @@ trait InteractsWithForms */ public array $componentFileAttachments = []; + #[Locked] + public bool $areFormStateUpdateHooksDisabledForTesting = false; + /** * @var array */ @@ -306,11 +310,33 @@ trait InteractsWithForms public function updatedInteractsWithForms(string $statePath): void { + if (app()->runningUnitTests() && $this->areFormStateUpdateHooksDisabledForTesting) { + return; + } + foreach ($this->getCachedForms() as $form) { $form->callAfterStateUpdated($statePath); } } + public function disableFormStateUpdateHooksForTesting(): void + { + if (! app()->runningUnitTests()) { + return; + } + + $this->areFormStateUpdateHooksDisabledForTesting = true; + } + + public function enableFormStateUpdateHooksForTesting(): void + { + if (! app()->runningUnitTests()) { + return; + } + + $this->areFormStateUpdateHooksDisabledForTesting = false; + } + protected function cacheForm(string $name, Form | Closure | null $form): ?Form { $this->isCachingForms = true; diff --git a/packages/forms/src/Testing/TestsForms.php b/packages/forms/src/Testing/TestsForms.php index ceebdeda32..b91917fb40 100644 --- a/packages/forms/src/Testing/TestsForms.php +++ b/packages/forms/src/Testing/TestsForms.php @@ -45,6 +45,8 @@ class TestsForms $state = Arr::undot([$formStatePath => $state]); } + $this->call('disableFormStateUpdateHooksForTesting'); + foreach (Arr::dot($state) as $key => $value) { if ($value instanceof UploadedFile || (is_array($value) && isset($value[0]) && $value[0] instanceof UploadedFile) @@ -54,6 +56,8 @@ class TestsForms } } + $this->call('enableFormStateUpdateHooksForTesting'); + $this->call('fillFormDataForTesting', $state); }