From 9a9091c1e6ff7fb3290e608a046f0e72a3f29bc3 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:27:57 +0100 Subject: [PATCH 01/10] Prevent catching exceptions from DB commit side-effects --- packages/actions/src/Concerns/InteractsWithActions.php | 4 ++-- packages/forms/src/Concerns/HasFormComponentActions.php | 4 ++-- .../infolists/src/Concerns/InteractsWithInfolists.php | 4 ++-- packages/panels/src/Pages/Auth/EditProfile.php | 4 ++-- packages/panels/src/Pages/Tenancy/EditTenantProfile.php | 4 ++-- packages/panels/src/Pages/Tenancy/RegisterTenant.php | 4 ++-- packages/panels/src/Resources/Pages/CreateRecord.php | 4 ++-- packages/panels/src/Resources/Pages/EditRecord.php | 8 ++++---- .../src/Pages/SettingsPage.php | 4 ++-- packages/tables/src/Concerns/HasActions.php | 4 ++-- packages/tables/src/Concerns/HasBulkActions.php | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/actions/src/Concerns/InteractsWithActions.php b/packages/actions/src/Concerns/InteractsWithActions.php index d47468315a..9bc025c61e 100644 --- a/packages/actions/src/Concerns/InteractsWithActions.php +++ b/packages/actions/src/Concerns/InteractsWithActions.php @@ -102,8 +102,6 @@ trait InteractsWithActions $result = $action->callAfter() ?? $result; $this->afterActionCalled(); - - $action->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $action->rollBackDatabaseTransaction() : @@ -131,6 +129,8 @@ trait InteractsWithActions throw $exception; } + $action->commitDatabaseTransaction(); + if (store($this)->has('redirect')) { return $result; } diff --git a/packages/forms/src/Concerns/HasFormComponentActions.php b/packages/forms/src/Concerns/HasFormComponentActions.php index af03f83b08..b6b3827619 100644 --- a/packages/forms/src/Concerns/HasFormComponentActions.php +++ b/packages/forms/src/Concerns/HasFormComponentActions.php @@ -81,8 +81,6 @@ trait HasFormComponentActions ]); $result = $action->callAfter() ?? $result; - - $action->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $action->rollBackDatabaseTransaction() : @@ -110,6 +108,8 @@ trait HasFormComponentActions throw $exception; } + $action->commitDatabaseTransaction(); + if (store($this)->has('redirect')) { return $result; } diff --git a/packages/infolists/src/Concerns/InteractsWithInfolists.php b/packages/infolists/src/Concerns/InteractsWithInfolists.php index a907b69312..643c5f9069 100644 --- a/packages/infolists/src/Concerns/InteractsWithInfolists.php +++ b/packages/infolists/src/Concerns/InteractsWithInfolists.php @@ -124,8 +124,6 @@ trait InteractsWithInfolists ]); $result = $action->callAfter() ?? $result; - - $action->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $action->rollBackDatabaseTransaction() : @@ -153,6 +151,8 @@ trait InteractsWithInfolists throw $exception; } + $action->commitDatabaseTransaction(); + if (store($this)->has('redirect')) { return $result; } diff --git a/packages/panels/src/Pages/Auth/EditProfile.php b/packages/panels/src/Pages/Auth/EditProfile.php index ae9abf41e1..fa8ff7bd42 100644 --- a/packages/panels/src/Pages/Auth/EditProfile.php +++ b/packages/panels/src/Pages/Auth/EditProfile.php @@ -160,8 +160,6 @@ class EditProfile extends Page $this->handleRecordUpdate($this->getUser(), $data); $this->callHook('afterSave'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -174,6 +172,8 @@ class EditProfile extends Page throw $exception; } + $this->commitDatabaseTransaction(); + if (request()->hasSession() && array_key_exists('password', $data)) { request()->session()->put([ 'password_hash_' . Filament::getAuthGuard() => $data['password'], diff --git a/packages/panels/src/Pages/Tenancy/EditTenantProfile.php b/packages/panels/src/Pages/Tenancy/EditTenantProfile.php index b2aa5dc030..8479c2209d 100644 --- a/packages/panels/src/Pages/Tenancy/EditTenantProfile.php +++ b/packages/panels/src/Pages/Tenancy/EditTenantProfile.php @@ -125,8 +125,6 @@ abstract class EditTenantProfile extends Page $this->handleRecordUpdate($this->tenant, $data); $this->callHook('afterSave'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -139,6 +137,8 @@ abstract class EditTenantProfile extends Page throw $exception; } + $this->commitDatabaseTransaction(); + $this->getSavedNotification()?->send(); if ($redirectUrl = $this->getRedirectUrl()) { diff --git a/packages/panels/src/Pages/Tenancy/RegisterTenant.php b/packages/panels/src/Pages/Tenancy/RegisterTenant.php index 356e11ae70..01e64ef48c 100644 --- a/packages/panels/src/Pages/Tenancy/RegisterTenant.php +++ b/packages/panels/src/Pages/Tenancy/RegisterTenant.php @@ -91,8 +91,6 @@ abstract class RegisterTenant extends SimplePage $this->form->model($this->tenant)->saveRelationships(); $this->callHook('afterRegister'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -105,6 +103,8 @@ abstract class RegisterTenant extends SimplePage throw $exception; } + $this->commitDatabaseTransaction(); + if ($redirectUrl = $this->getRedirectUrl()) { $this->redirect($redirectUrl, navigate: FilamentView::hasSpaMode() && is_app_url($redirectUrl)); } diff --git a/packages/panels/src/Resources/Pages/CreateRecord.php b/packages/panels/src/Resources/Pages/CreateRecord.php index eba25857d2..02195f57c8 100644 --- a/packages/panels/src/Resources/Pages/CreateRecord.php +++ b/packages/panels/src/Resources/Pages/CreateRecord.php @@ -96,8 +96,6 @@ class CreateRecord extends Page $this->form->model($this->getRecord())->saveRelationships(); $this->callHook('afterCreate'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -110,6 +108,8 @@ class CreateRecord extends Page throw $exception; } + $this->commitDatabaseTransaction(); + $this->rememberData(); $this->getCreatedNotification()?->send(); diff --git a/packages/panels/src/Resources/Pages/EditRecord.php b/packages/panels/src/Resources/Pages/EditRecord.php index c9fd3f1090..4c104932d5 100644 --- a/packages/panels/src/Resources/Pages/EditRecord.php +++ b/packages/panels/src/Resources/Pages/EditRecord.php @@ -153,8 +153,6 @@ class EditRecord extends Page $this->handleRecordUpdate($this->getRecord(), $data); $this->callHook('afterSave'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -167,6 +165,8 @@ class EditRecord extends Page throw $exception; } + $this->commitDatabaseTransaction(); + $this->rememberData(); if ($shouldSendSavedNotification) { @@ -202,8 +202,6 @@ class EditRecord extends Page $this->handleRecordUpdate($this->getRecord(), $data); $this->callHook('afterSave'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -216,6 +214,8 @@ class EditRecord extends Page throw $exception; } + $this->commitDatabaseTransaction(); + $this->rememberData(); } diff --git a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php index aa2ffdaca2..cd77939531 100644 --- a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php +++ b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php @@ -81,8 +81,6 @@ class SettingsPage extends Page $settings->save(); $this->callHook('afterSave'); - - $this->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $this->rollBackDatabaseTransaction() : @@ -95,6 +93,8 @@ class SettingsPage extends Page throw $exception; } + $this->commitDatabaseTransaction(); + $this->rememberData(); $this->getSavedNotification()?->send(); diff --git a/packages/tables/src/Concerns/HasActions.php b/packages/tables/src/Concerns/HasActions.php index 266be5a9e6..4c76e1b56b 100644 --- a/packages/tables/src/Concerns/HasActions.php +++ b/packages/tables/src/Concerns/HasActions.php @@ -113,8 +113,6 @@ trait HasActions ]); $result = $action->callAfter() ?? $result; - - $action->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $action->rollBackDatabaseTransaction() : @@ -142,6 +140,8 @@ trait HasActions throw $exception; } + $action->commitDatabaseTransaction(); + if (store($this)->has('redirect')) { return $result; } diff --git a/packages/tables/src/Concerns/HasBulkActions.php b/packages/tables/src/Concerns/HasBulkActions.php index ba955b4d9c..fa93cbee35 100644 --- a/packages/tables/src/Concerns/HasBulkActions.php +++ b/packages/tables/src/Concerns/HasBulkActions.php @@ -84,8 +84,6 @@ trait HasBulkActions ]); $result = $action->callAfter() ?? $result; - - $action->commitDatabaseTransaction(); } catch (Halt $exception) { $exception->shouldRollbackDatabaseTransaction() ? $action->rollBackDatabaseTransaction() : @@ -113,6 +111,8 @@ trait HasBulkActions throw $exception; } + $action->commitDatabaseTransaction(); + if (store($this)->has('redirect')) { return $result; } From 8e08734570aff7f1b2de711e1ad6bce0e7f67a3b Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:46:34 +0100 Subject: [PATCH 02/10] Test --- .../Fixtures/Resources/PostResource.php | 13 +++++++ .../Resources/PostResource/Pages/EditPost.php | 13 +++++++ .../Resources/Pages/ListRecordsTest.php | 35 +++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/tests/src/Panels/Fixtures/Resources/PostResource.php b/tests/src/Panels/Fixtures/Resources/PostResource.php index 06267961be..c1f2f3ad80 100644 --- a/tests/src/Panels/Fixtures/Resources/PostResource.php +++ b/tests/src/Panels/Fixtures/Resources/PostResource.php @@ -10,6 +10,9 @@ use Filament\Tables\Table; use Filament\Tests\Models\Post; use Filament\Tests\Panels\Fixtures\Resources\PostResource\Pages; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; +use RuntimeException; class PostResource extends Resource { @@ -57,6 +60,16 @@ class PostResource extends Resource ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), + Tables\Actions\Action::make('randomize_title') + ->databaseTransaction() + ->action(action: function (Post $record) { + DB::afterCommit(function () { + throw new RuntimeException('This exception, happening after the successfully commit of the current transaction, should not trigger a rollback by Filament.'); + }); + + $record->title = Str::random(10); + $record->save(); + }), Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ diff --git a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php index c0336aa865..fa7ad6990f 100644 --- a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php +++ b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php @@ -4,7 +4,10 @@ namespace Filament\Tests\Panels\Fixtures\Resources\PostResource\Pages; use Filament\Actions; use Filament\Resources\Pages\EditRecord; +use Filament\Tests\Models\Post; use Filament\Tests\Panels\Fixtures\Resources\PostResource; +use Illuminate\Support\Facades\DB; +use RuntimeException; class EditPost extends EditRecord { @@ -17,6 +20,16 @@ class EditPost extends EditRecord Actions\ActionGroup::make([ Actions\DeleteAction::make(), ]), + Actions\Action::make('randomize_title') + ->databaseTransaction() + ->action(action: function (Post $record) { + DB::afterCommit(function () { + throw new RuntimeException('This exception, happening after the successfully commit of the current transaction, should not trigger a rollback by Filament.'); + }); + + $record->title = 'Test'; + $record->save(); + }), ]; } diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index 1959f81c39..64e7bf921f 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -7,6 +7,7 @@ use Filament\Tests\Panels\Fixtures\Resources\PostResource; use Filament\Tests\Panels\Fixtures\Resources\PostResource\Pages\ListPosts; use Filament\Tests\Panels\Fixtures\Resources\UserResource; use Filament\Tests\Panels\Resources\TestCase; +use Illuminate\Support\Facades\DB; use function Filament\Tests\livewire; use function Pest\Laravel\assertSoftDeleted; @@ -115,3 +116,37 @@ it('can bulk delete posts', function () { assertSoftDeleted($post); } }); + +it('actions will not interfere with database transactions on an error', function () { + $post = Post::factory()->create(); + + $transactionLevel = DB::transactionLevel(); + + try { + livewire(PostResource\Pages\EditPost::class, [ + 'record' => $post->getKey(), + ]) + ->callAction('randomize_title'); + } catch (Exception $e) { + // This can be catched and handled somewhere else, code continues... + } + + expect(DB::transactionLevel()) + ->toBe($transactionLevel); +}); + +it('table actions will not interfere with database transactions on an error', function () { + $post = Post::factory()->create(); + + $transactionLevel = DB::transactionLevel(); + + try { + livewire(PostResource\Pages\ListPosts::class) + ->callTableAction('randomize_title', $post); + } catch (Exception $e) { + // This can be catched and handled somewhere else, code continues... + } + + expect(DB::transactionLevel()) + ->toBe($transactionLevel); +}); From ad0cf783d95685655ba53dad7a2920e8663bd0a1 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:50:14 +0100 Subject: [PATCH 03/10] WIP --- tests/src/Panels/Fixtures/Resources/PostResource.php | 2 +- .../Panels/Fixtures/Resources/PostResource/Pages/EditPost.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Panels/Fixtures/Resources/PostResource.php b/tests/src/Panels/Fixtures/Resources/PostResource.php index c1f2f3ad80..1b337f3afb 100644 --- a/tests/src/Panels/Fixtures/Resources/PostResource.php +++ b/tests/src/Panels/Fixtures/Resources/PostResource.php @@ -64,7 +64,7 @@ class PostResource extends Resource ->databaseTransaction() ->action(action: function (Post $record) { DB::afterCommit(function () { - throw new RuntimeException('This exception, happening after the successfully commit of the current transaction, should not trigger a rollback by Filament.'); + throw new RuntimeException('This exception, happening after the successful commit of the current transaction, should not trigger a rollback by Filament.'); }); $record->title = Str::random(10); diff --git a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php index fa7ad6990f..e6758b180e 100644 --- a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php +++ b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/EditPost.php @@ -24,7 +24,7 @@ class EditPost extends EditRecord ->databaseTransaction() ->action(action: function (Post $record) { DB::afterCommit(function () { - throw new RuntimeException('This exception, happening after the successfully commit of the current transaction, should not trigger a rollback by Filament.'); + throw new RuntimeException('This exception, happening after the successful commit of the current transaction, should not trigger a rollback by Filament.'); }); $record->title = 'Test'; From 4a8a0df4f7d34e7dbbfb9086676bb4d9229fa489 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:50:28 +0100 Subject: [PATCH 04/10] Update ListRecordsTest.php --- tests/src/Panels/Resources/Pages/ListRecordsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index 64e7bf921f..18f3c5d7c2 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -117,7 +117,7 @@ it('can bulk delete posts', function () { } }); -it('actions will not interfere with database transactions on an error', function () { +test('actions will not interfere with database transactions on an error', function () { $post = Post::factory()->create(); $transactionLevel = DB::transactionLevel(); @@ -135,7 +135,7 @@ it('actions will not interfere with database transactions on an error', function ->toBe($transactionLevel); }); -it('table actions will not interfere with database transactions on an error', function () { +test('table actions will not interfere with database transactions on an error', function () { $post = Post::factory()->create(); $transactionLevel = DB::transactionLevel(); From 6528a7d82650a28e7e1d9e4e3ea56115f830f47e Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:50:54 +0100 Subject: [PATCH 05/10] Update ListRecordsTest.php --- tests/src/Panels/Resources/Pages/ListRecordsTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index 18f3c5d7c2..06a214aef0 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -131,6 +131,8 @@ test('actions will not interfere with database transactions on an error', functi // This can be catched and handled somewhere else, code continues... } + // Original transaction level should be unaffected... + expect(DB::transactionLevel()) ->toBe($transactionLevel); }); @@ -147,6 +149,8 @@ test('table actions will not interfere with database transactions on an error', // This can be catched and handled somewhere else, code continues... } + // Original transaction level should be unaffected... + expect(DB::transactionLevel()) ->toBe($transactionLevel); }); From 1aa2ba1897cd3fb0792ba845d55f9481059a0fcf Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:58:03 +0100 Subject: [PATCH 06/10] Phpstan? --- packages/support/src/Commands/CheckTranslationsCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/support/src/Commands/CheckTranslationsCommand.php b/packages/support/src/Commands/CheckTranslationsCommand.php index a640822c5c..0aff09ab02 100644 --- a/packages/support/src/Commands/CheckTranslationsCommand.php +++ b/packages/support/src/Commands/CheckTranslationsCommand.php @@ -116,7 +116,7 @@ class CheckTranslationsCommand extends Command implements PromptsForMissingInput }) ->tap(function (Collection $files) use ($locale, $package) { $missingKeysCount = $files->sum(fn ($file): int => count($file['missing'])); - $removedKeysCount = $files->sum(fn ($file): int => count($file['removed'])); + $removedKeysCount = $files->sum(fn ($file): int => $file['removed'] ? count($file['removed']) : 0); $locale = locale_get_display_name($locale, 'en'); From 3a65a986f999cbdd423d994a401a864c6efda8cc Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:05:19 +0100 Subject: [PATCH 07/10] Revert "Phpstan?" This reverts commit 1aa2ba1897cd3fb0792ba845d55f9481059a0fcf. --- packages/support/src/Commands/CheckTranslationsCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/support/src/Commands/CheckTranslationsCommand.php b/packages/support/src/Commands/CheckTranslationsCommand.php index 0aff09ab02..a640822c5c 100644 --- a/packages/support/src/Commands/CheckTranslationsCommand.php +++ b/packages/support/src/Commands/CheckTranslationsCommand.php @@ -116,7 +116,7 @@ class CheckTranslationsCommand extends Command implements PromptsForMissingInput }) ->tap(function (Collection $files) use ($locale, $package) { $missingKeysCount = $files->sum(fn ($file): int => count($file['missing'])); - $removedKeysCount = $files->sum(fn ($file): int => $file['removed'] ? count($file['removed']) : 0); + $removedKeysCount = $files->sum(fn ($file): int => count($file['removed'])); $locale = locale_get_display_name($locale, 'en'); From 5010fa6ebe8fec9b59ef4f7889be5fe59ea58371 Mon Sep 17 00:00:00 2001 From: ralphjsmit Date: Tue, 18 Mar 2025 16:13:03 +0000 Subject: [PATCH 08/10] chore: fix code style --- tests/src/Panels/Resources/Pages/ListRecordsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index 06a214aef0..3c4d205d18 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -143,7 +143,7 @@ test('table actions will not interfere with database transactions on an error', $transactionLevel = DB::transactionLevel(); try { - livewire(PostResource\Pages\ListPosts::class) + livewire(ListPosts::class) ->callTableAction('randomize_title', $post); } catch (Exception $e) { // This can be catched and handled somewhere else, code continues... From 1131805b0556424a89b975380c907687693e1147 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 20 Mar 2025 09:38:25 +0100 Subject: [PATCH 09/10] Move test --- .../Panels/Resources/Pages/EditRecordTest.php | 21 +++++++++++++++++++ .../Resources/Pages/ListRecordsTest.php | 20 ------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/src/Panels/Resources/Pages/EditRecordTest.php b/tests/src/Panels/Resources/Pages/EditRecordTest.php index 2016631172..f11e704f67 100644 --- a/tests/src/Panels/Resources/Pages/EditRecordTest.php +++ b/tests/src/Panels/Resources/Pages/EditRecordTest.php @@ -5,6 +5,7 @@ use Filament\Tests\Models\Post; use Filament\Tests\Panels\Fixtures\Resources\PostResource; use Filament\Tests\Panels\Fixtures\Resources\PostResource\Pages\EditPost; use Filament\Tests\Panels\Resources\TestCase; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use function Filament\Tests\livewire; @@ -109,3 +110,23 @@ it('can refresh data', function () { 'title' => $newPostTitle, ]); }); + +test('actions will not interfere with database transactions on an error', function () { + $post = Post::factory()->create(); + + $transactionLevel = DB::transactionLevel(); + + try { + livewire(PostResource\Pages\EditPost::class, [ + 'record' => $post->getKey(), + ]) + ->callAction('randomize_title'); + } catch (Exception $e) { + // This can be catched and handled somewhere else, code continues... + } + + // Original transaction level should be unaffected... + + expect(DB::transactionLevel()) + ->toBe($transactionLevel); +}); diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index 06a214aef0..fc5099c36a 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -117,26 +117,6 @@ it('can bulk delete posts', function () { } }); -test('actions will not interfere with database transactions on an error', function () { - $post = Post::factory()->create(); - - $transactionLevel = DB::transactionLevel(); - - try { - livewire(PostResource\Pages\EditPost::class, [ - 'record' => $post->getKey(), - ]) - ->callAction('randomize_title'); - } catch (Exception $e) { - // This can be catched and handled somewhere else, code continues... - } - - // Original transaction level should be unaffected... - - expect(DB::transactionLevel()) - ->toBe($transactionLevel); -}); - test('table actions will not interfere with database transactions on an error', function () { $post = Post::factory()->create(); From b0a52edaabe8dbe8478be63a581e4bc180bcdb31 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 20 Mar 2025 09:38:52 +0100 Subject: [PATCH 10/10] Update ListRecordsTest.php --- tests/src/Panels/Resources/Pages/ListRecordsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Panels/Resources/Pages/ListRecordsTest.php b/tests/src/Panels/Resources/Pages/ListRecordsTest.php index c7ecc24b4e..fc5099c36a 100644 --- a/tests/src/Panels/Resources/Pages/ListRecordsTest.php +++ b/tests/src/Panels/Resources/Pages/ListRecordsTest.php @@ -123,7 +123,7 @@ test('table actions will not interfere with database transactions on an error', $transactionLevel = DB::transactionLevel(); try { - livewire(ListPosts::class) + livewire(PostResource\Pages\ListPosts::class) ->callTableAction('randomize_title', $post); } catch (Exception $e) { // This can be catched and handled somewhere else, code continues...