From 0d4c2511d318928dcc37568de9a02cd47acade57 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Mon, 21 Apr 2025 16:20:10 +0100 Subject: [PATCH] Replace old usages of methods --- docs/10-testing/02-testing-resources.md | 8 ++++---- docs/10-testing/04-testing-forms.md | 10 +++++----- packages/forms/.stubs.php | 19 +++++++++++-------- packages/forms/docs/12-repeater.md | 6 +++--- packages/forms/docs/13-builder.md | 6 +++--- packages/forms/src/Testing/TestsForms.php | 8 ++++---- tests/src/Forms/ActionTest.php | 12 ++++++------ tests/src/Forms/Components/FileUploadTest.php | 2 +- tests/src/Forms/Components/RepeaterTest.php | 6 +++--- tests/src/Forms/FormsTest.php | 2 +- tests/src/Forms/StateTest.php | 10 +++++----- tests/src/Forms/Utilities/SetTest.php | 10 +++++----- tests/src/Panels/Auth/EditProfileTest.php | 6 +++--- .../Resources/Pages/CreateRecordTest.php | 4 ++-- .../Panels/Resources/Pages/EditRecordTest.php | 8 ++++---- .../Panels/Resources/Pages/ViewRecordTest.php | 8 ++++---- 16 files changed, 64 insertions(+), 61 deletions(-) diff --git a/docs/10-testing/02-testing-resources.md b/docs/10-testing/02-testing-resources.md index 0271bd0e92..29afed6cd6 100644 --- a/docs/10-testing/02-testing-resources.md +++ b/docs/10-testing/02-testing-resources.md @@ -138,7 +138,7 @@ use PostResource\PostResource;it('can render page', function () { ##### Filling existing data -To check that the form is filled with the correct data from the database, you may `assertFormSet()` that the data in the form matches that of the record: +To check that the form is filled with the correct data from the database, you may `assertSchemaSet()` that the data in the form matches that of the record: ```php use function Pest\Livewire\livewire; @@ -149,7 +149,7 @@ it('can retrieve data', function () { livewire(PostResource\Pages\EditPost::class, [ 'record' => $post->getRouteKey(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => $post->author->getKey(), 'content' => $post->content, 'tags' => $post->tags, @@ -262,7 +262,7 @@ use PostResource\PostResource;it('can render page', function () { ##### Filling existing data -To check that the form is filled with the correct data from the database, you may `assertFormSet()` that the data in the form matches that of the record: +To check that the form is filled with the correct data from the database, you may `assertSchemaSet()` that the data in the form matches that of the record: ```php use function Pest\Livewire\livewire; @@ -273,7 +273,7 @@ it('can retrieve data', function () { livewire(PostResource\Pages\ViewPost::class, [ 'record' => $post->getRouteKey(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => $post->author->getKey(), 'content' => $post->content, 'tags' => $post->tags, diff --git a/docs/10-testing/04-testing-forms.md b/docs/10-testing/04-testing-forms.md index 69ce7028e9..7d2e7219ca 100644 --- a/docs/10-testing/04-testing-forms.md +++ b/docs/10-testing/04-testing-forms.md @@ -24,7 +24,7 @@ livewire(CreatePost::class) > If you have multiple forms on a Livewire component, you can specify which form you want to fill using `fillForm([...], 'createPostForm')`. -To check that a form has data, use `assertFormSet()`: +To check that a form has data, use `assertSchemaSet()`: ```php use Illuminate\Support\Str; @@ -37,15 +37,15 @@ it('can automatically generate a slug from the title', function () { ->fillForm([ 'title' => $title, ]) - ->assertFormSet([ + ->assertSchemaSet([ 'slug' => Str::slug($title), ]); }); ``` -> If you have multiple forms on a Livewire component, you can specify which form you want to check using `assertFormSet([...], 'createPostForm')`. +> If you have multiple forms on a Livewire component, you can specify which form you want to check using `assertSchemaSet([...], 'createPostForm')`. -You may also find it useful to pass a function to the `assertFormSet()` method, which allows you to access the form `$state` and perform additional assertions: +You may also find it useful to pass a function to the `assertSchemaSet()` method, which allows you to access the form `$state` and perform additional assertions: ```php use Illuminate\Support\Str; @@ -58,7 +58,7 @@ it('can automatically generate a slug from the title without any spaces', functi ->fillForm([ 'title' => $title, ]) - ->assertFormSet(function (array $state): array { + ->assertSchemaSet(function (array $state): array { expect($state['slug']) ->not->toContain(' '); diff --git a/packages/forms/.stubs.php b/packages/forms/.stubs.php index 64b38372d8..72be57d5f4 100644 --- a/packages/forms/.stubs.php +++ b/packages/forms/.stubs.php @@ -5,23 +5,26 @@ namespace Livewire\Features\SupportTesting { use Closure; class Testable { - public function fillForm(array | Closure $state = [], string $form = 'form'): static {} + public function fillForm(array | Closure $state = [], ?string $form = null): static {} + /** + * @deprecated Use `assertSchemaSet()` instead. + */ public function assertFormSet(array | Closure $state, string $form = 'form'): static {} - public function assertHasFormErrors(array $keys = [], string $form = 'form'): static {} + public function assertHasFormErrors(array $keys = [], ?string $form = null): static {} - public function assertHasNoFormErrors(array $keys = [], string $form = 'form'): static {} + public function assertHasNoFormErrors(array $keys = [], ?string $form = null): static {} - public function assertFormFieldExists(string $fieldName, string | Closure $form = 'form', ?Closure $checkFieldUsing = null): static {} + public function assertFormFieldExists(string $fieldName, string | Closure | null $form = null, ?Closure $checkFieldUsing = null): static {} - public function assertFormFieldDoesNotExist(string $fieldName, string $form = 'form'): static {} + public function assertFormFieldDoesNotExist(string $fieldName, ?string $form = null): static {} - public function assertFormFieldDisabled(string $fieldName, string $form = 'form'): static {} + public function assertFormFieldDisabled(string $fieldName, ?string $form = null): static {} - public function assertFormFieldEnabled(string $fieldName, string $form = 'form'): static {} + public function assertFormFieldEnabled(string $fieldName, ?string $form = null): static {} - public function assertFormFieldReadOnly(string $fieldName, string $form = 'form'): static {} + public function assertFormFieldReadOnly(string $fieldName, ?string $form = null): static {} /** * @deprecated Use `assertSchemaExists()` instead. diff --git a/packages/forms/docs/12-repeater.md b/packages/forms/docs/12-repeater.md index 982af31e91..4aad273b18 100644 --- a/packages/forms/docs/12-repeater.md +++ b/packages/forms/docs/12-repeater.md @@ -819,7 +819,7 @@ use function Pest\Livewire\livewire; $undoRepeaterFake = Repeater::fake(); livewire(EditPost::class, ['record' => $post]) - ->assertFormSet([ + ->assertSchemaSet([ 'quotes' => [ [ 'content' => 'First quote', @@ -834,7 +834,7 @@ livewire(EditPost::class, ['record' => $post]) $undoRepeaterFake(); ``` -You may also find it useful to test the number of items in a repeater by passing a function to the `assertFormSet()` method: +You may also find it useful to test the number of items in a repeater by passing a function to the `assertSchemaSet()` method: ```php use Filament\Forms\Components\Repeater; @@ -843,7 +843,7 @@ use function Pest\Livewire\livewire; $undoRepeaterFake = Repeater::fake(); livewire(EditPost::class, ['record' => $post]) - ->assertFormSet(function (array $state) { + ->assertSchemaSet(function (array $state) { expect($state['quotes']) ->toHaveCount(2); }); diff --git a/packages/forms/docs/13-builder.md b/packages/forms/docs/13-builder.md index e9cb731068..4bc82104a5 100644 --- a/packages/forms/docs/13-builder.md +++ b/packages/forms/docs/13-builder.md @@ -675,7 +675,7 @@ use function Pest\Livewire\livewire; $undoBuilderFake = Builder::fake(); livewire(EditPost::class, ['record' => $post]) - ->assertFormSet([ + ->assertSchemaSet([ 'content' => [ [ 'type' => 'heading', @@ -697,7 +697,7 @@ livewire(EditPost::class, ['record' => $post]) $undoBuilderFake(); ``` -You may also find it useful to access test the number of items in a repeater by passing a function to the `assertFormSet()` method: +You may also find it useful to access test the number of items in a repeater by passing a function to the `assertSchemaSet()` method: ```php use Filament\Forms\Components\Builder; @@ -706,7 +706,7 @@ use function Pest\Livewire\livewire; $undoBuilderFake = Builder::fake(); livewire(EditPost::class, ['record' => $post]) - ->assertFormSet(function (array $state) { + ->assertSchemaSet(function (array $state) { expect($state['content']) ->toHaveCount(2); }); diff --git a/packages/forms/src/Testing/TestsForms.php b/packages/forms/src/Testing/TestsForms.php index 579b136f59..7ba2628758 100644 --- a/packages/forms/src/Testing/TestsForms.php +++ b/packages/forms/src/Testing/TestsForms.php @@ -70,7 +70,7 @@ class TestsForms public function assertFormSet(): Closure { - return function (array | Closure $state, ?string $form = null): static { + return function (array | Closure $state, string $form = 'form'): static { $this->assertSchemaSet($state, $form); return $this; @@ -158,10 +158,10 @@ class TestsForms public function assertFormComponentExists(): Closure { - return function (string $componentKey, string | Closure | null $form = null, ?Closure $checkComponentUsing = null): static { + return function (string $componentKey, string | Closure $form = 'form', ?Closure $checkComponentUsing = null): static { if ($form instanceof Closure) { $checkComponentUsing = $form; - $form = null; + $form = 'form'; } $this->assertSchemaComponentExists($componentKey, $form, $checkComponentUsing); @@ -172,7 +172,7 @@ class TestsForms public function assertFormComponentDoesNotExist(): Closure { - return function (string $componentKey, ?string $form = null): static { + return function (string $componentKey, string $form = 'form'): static { $this->assertSchemaComponentDoesNotExist($componentKey, $form); return $this; diff --git a/tests/src/Forms/ActionTest.php b/tests/src/Forms/ActionTest.php index 37b5a9556c..c35ca499d2 100644 --- a/tests/src/Forms/ActionTest.php +++ b/tests/src/Forms/ActionTest.php @@ -41,13 +41,13 @@ it('can call an action with data', function (): void { ->callAction(TestAction::make('setValue')->schemaComponent('textInput'), data: [ 'value' => $value = Str::random(), ]) - ->assertFormSet(['textInput' => $value]); + ->assertSchemaSet(['textInput' => $value]); livewire(Actions::class) ->callFormComponentAction('textInput', 'setValue', data: [ 'value' => $value = Str::random(), ]) - ->assertFormSet(['textInput' => $value]); + ->assertSchemaSet(['textInput' => $value]); }); it('can validate an action\'s data', function (): void { @@ -56,14 +56,14 @@ it('can validate an action\'s data', function (): void { 'value' => null, ]) ->assertHasFormErrors(['value' => ['required']]) - ->assertFormSet(['textInput' => null]); + ->assertSchemaSet(['textInput' => null]); livewire(Actions::class) ->callFormComponentAction('textInput', 'setValue', data: [ 'value' => null, ]) ->assertHasFormComponentActionErrors(['value' => ['required']]) - ->assertFormSet(['textInput' => null]); + ->assertSchemaSet(['textInput' => null]); }); it('can set default action data when mounted', function (): void { @@ -85,13 +85,13 @@ it('can call an action with arguments', function (): void { ->callAction(TestAction::make('setValueFromArguments')->schemaComponent('textInput')->arguments([ 'value' => $value = Str::random(), ])) - ->assertFormSet(['textInput' => $value]); + ->assertSchemaSet(['textInput' => $value]); livewire(Actions::class) ->callFormComponentAction('textInput', 'setValueFromArguments', arguments: [ 'value' => $value = Str::random(), ]) - ->assertFormSet(['textInput' => $value]); + ->assertSchemaSet(['textInput' => $value]); }); it('can call an action and halt', function (): void { diff --git a/tests/src/Forms/Components/FileUploadTest.php b/tests/src/Forms/Components/FileUploadTest.php index dd26b10b13..319fe81ad0 100644 --- a/tests/src/Forms/Components/FileUploadTest.php +++ b/tests/src/Forms/Components/FileUploadTest.php @@ -22,7 +22,7 @@ it('UploadedFile should be converted to TemporaryUploadedFile', function (): voi UploadedFile::fake()->image('multiple-file2.jpg'), ], ]) - ->assertFormSet(function (array $data): void { + ->assertSchemaSet(function (array $data): void { expect($data['single-file'][0])->toBeInstanceOf(TemporaryUploadedFile::class) ->and($data['multiple-files'][0])->toBeInstanceOf(TemporaryUploadedFile::class) ->and($data['multiple-files'][1])->toBeInstanceOf(TemporaryUploadedFile::class); diff --git a/tests/src/Forms/Components/RepeaterTest.php b/tests/src/Forms/Components/RepeaterTest.php index 92ad2cd80c..186d7981a6 100644 --- a/tests/src/Forms/Components/RepeaterTest.php +++ b/tests/src/Forms/Components/RepeaterTest.php @@ -21,7 +21,7 @@ it('can fill and assert data in a repeater', function (array $data): void { try { livewire(TestComponentWithRepeater::class) ->fillForm($data) - ->assertFormSet($data); + ->assertSchemaSet($data); } catch (RootTagMissingFromViewException $exception) { // Flaky test } @@ -127,13 +127,13 @@ it('can remove items from a repeater', function (): void { ], ], ]) - ->assertFormSet($data) + ->assertSchemaSet($data) ->fillForm([ 'normal' => [ Arr::first($data['normal']), ], ]) - ->assertFormSet(function (array $data) { + ->assertSchemaSet(function (array $data) { expect($data['normal'])->toHaveCount(1); return [ diff --git a/tests/src/Forms/FormsTest.php b/tests/src/Forms/FormsTest.php index d8e0620e9e..07ae49d1d6 100644 --- a/tests/src/Forms/FormsTest.php +++ b/tests/src/Forms/FormsTest.php @@ -48,7 +48,7 @@ it('has fields on multiple forms', function (): void { it('can fill fields on multiple forms', function (): void { livewire(TestComponentWithMultipleForms::class) ->fillForm(['title' => 'value'], 'fooForm') - ->assertFormSet(['title' => 'value'], 'fooForm'); + ->assertSchemaSet(['title' => 'value'], 'fooForm'); }); it('can have disabled fields', function (): void { diff --git a/tests/src/Forms/StateTest.php b/tests/src/Forms/StateTest.php index cc9489179c..5cf7888b50 100644 --- a/tests/src/Forms/StateTest.php +++ b/tests/src/Forms/StateTest.php @@ -818,7 +818,7 @@ test('components can set their own state after they are hydrated', function (): ->statePath('data'); } }) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => 'bar', ]); }); @@ -839,7 +839,7 @@ test('components can set their own state after they are updated', function (): v ->fillForm([ 'foo' => 'baz', ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => 'bar', ]); }); @@ -860,7 +860,7 @@ test('components can inject their own state after they are updated', function () ->fillForm([ 'foo' => $state = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => strrev($state), ]); }); @@ -881,7 +881,7 @@ test('components can get their own state from the component object', function () ->fillForm([ 'foo' => $state = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => strrev($state), ]); }); @@ -930,7 +930,7 @@ test('components can inject their old state after it is updated', function (): v 'foo' => $state = Str::random(), ]) ->assertSet('storedOldState', $oldState) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => $state, ]); }); diff --git a/tests/src/Forms/Utilities/SetTest.php b/tests/src/Forms/Utilities/SetTest.php index 1e93238d5b..2d55a5bb95 100644 --- a/tests/src/Forms/Utilities/SetTest.php +++ b/tests/src/Forms/Utilities/SetTest.php @@ -30,7 +30,7 @@ it('can set the value of a field', function (): void { ->fillForm([ 'bar' => $bar = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => $bar, ]); }); @@ -54,7 +54,7 @@ it('can set the value of a field and call its updated hook', function (): void { ->fillForm([ 'bar' => $bar = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => $bar, 'baz' => 'qux', ]); @@ -82,7 +82,7 @@ it('can set the value of a nested field', function (): void { ->fillForm([ 'bar' => $bar = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'nested.foo' => $bar, ]); }); @@ -109,7 +109,7 @@ it('can set the value of a parent level field', function (): void { ->fillForm([ 'nested.bar' => $bar = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'foo' => $bar, ]); }); @@ -140,7 +140,7 @@ it('can set the value of a parent level field with a nested field', function (): ->fillForm([ 'nestedTwo.bar' => $bar = Str::random(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'nestedOne.foo' => $bar, ]); }); diff --git a/tests/src/Panels/Auth/EditProfileTest.php b/tests/src/Panels/Auth/EditProfileTest.php index 4ae6225ac6..71b1ae4e93 100644 --- a/tests/src/Panels/Auth/EditProfileTest.php +++ b/tests/src/Panels/Auth/EditProfileTest.php @@ -27,7 +27,7 @@ it('can render page', function (): void { it('can retrieve data', function (): void { livewire(EditProfile::class) - ->assertFormSet([ + ->assertSchemaSet([ 'name' => $this->user->name, 'email' => $this->user->email, ]); @@ -83,7 +83,7 @@ it('can send email change verification', function (): void { ->call('save') ->assertHasNoFormErrors() ->assertNotified('Email address change request sent') - ->assertFormSet([ + ->assertSchemaSet([ 'email' => $oldEmail, ]); @@ -122,7 +122,7 @@ it('can save password', function (): void { ->call('save') ->assertHasNoFormErrors() ->assertNotified('Saved') - ->assertFormSet([ + ->assertSchemaSet([ 'password' => '', 'passwordConfirmation' => '', ]); diff --git a/tests/src/Panels/Resources/Pages/CreateRecordTest.php b/tests/src/Panels/Resources/Pages/CreateRecordTest.php index a70aa7a893..108e6808b9 100644 --- a/tests/src/Panels/Resources/Pages/CreateRecordTest.php +++ b/tests/src/Panels/Resources/Pages/CreateRecordTest.php @@ -59,7 +59,7 @@ it('can create another', function (): void { ->call('create', true) ->assertHasNoFormErrors() ->assertNoRedirect() - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => null, 'content' => null, 'tags' => [], @@ -109,7 +109,7 @@ it('can create another and preserve data', function (): void { ->call('create', true) ->assertHasNoFormErrors() ->assertNoRedirect() - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => null, 'content' => null, 'tags' => $newData->tags, diff --git a/tests/src/Panels/Resources/Pages/EditRecordTest.php b/tests/src/Panels/Resources/Pages/EditRecordTest.php index fecbb84b36..222922cbe8 100644 --- a/tests/src/Panels/Resources/Pages/EditRecordTest.php +++ b/tests/src/Panels/Resources/Pages/EditRecordTest.php @@ -38,7 +38,7 @@ it('can retrieve data', function (): void { livewire(EditPost::class, [ 'record' => $post->getKey(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => $post->author->getKey(), 'content' => $post->content, 'tags' => $post->tags, @@ -104,7 +104,7 @@ it('can refresh data', function (): void { $originalPostTitle = $post->title; - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $originalPostTitle, ]); @@ -113,13 +113,13 @@ it('can refresh data', function (): void { $post->title = $newPostTitle; $post->save(); - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $originalPostTitle, ]); $page->call('refreshTitle'); - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $newPostTitle, ]); }); diff --git a/tests/src/Panels/Resources/Pages/ViewRecordTest.php b/tests/src/Panels/Resources/Pages/ViewRecordTest.php index 35c52c3124..5f8f14dd81 100644 --- a/tests/src/Panels/Resources/Pages/ViewRecordTest.php +++ b/tests/src/Panels/Resources/Pages/ViewRecordTest.php @@ -36,7 +36,7 @@ it('can retrieve data', function (): void { livewire(ViewPost::class, [ 'record' => $post->getKey(), ]) - ->assertFormSet([ + ->assertSchemaSet([ 'author_id' => $post->author->getKey(), 'content' => $post->content, 'tags' => $post->tags, @@ -53,7 +53,7 @@ it('can refresh data', function (): void { $originalPostTitle = $post->title; - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $originalPostTitle, ]); @@ -62,13 +62,13 @@ it('can refresh data', function (): void { $post->title = $newPostTitle; $post->save(); - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $originalPostTitle, ]); $page->call('refreshTitle'); - $page->assertFormSet([ + $page->assertSchemaSet([ 'title' => $newPostTitle, ]); });