Overview
All examples in this guide will be written using Pest. To use Pest’s Livewire plugin for testing, you can follow the installation instructions in the Pest documentation on plugins: Livewire plugin for Pest. However, you can easily adapt this to PHPUnit. Since all pages in the app are Livewire components, we’re just using Livewire testing helpers everywhere. If you’ve never tested Livewire components before, please read this guide from the Livewire docs.Getting started
Ensure that you are authenticated to access the app in yourTestCase:
Testing multiple panels
If you have multiple panels and you would like to test a non-default panel, you will need to tell Filament which panel you are testing. This can be done in thesetUp() method of the test case, or you can do it at the start of a particular test. Filament usually does this in a middleware when you access the panel through a request, so if you’re not making a request in your test like when testing a Livewire component, you need to set the current panel manually:
Resources
Pages
List
Routing & render
To ensure that the List page for thePostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Table
Filament includes a selection of helpers for testing tables. A full guide to testing tables can be found in the Table Builder documentation. To use a table testing helper, make assertions on the resource’s List page class, which holds the table:Create
Routing & render
To ensure that the Create page for thePostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Creating
You may check that data is correctly saved into the database by callingfillForm() with your form data, and then asserting that the database contains a matching record:
Validation
UseassertHasFormErrors() to ensure that data is properly validated in a form:
Edit
Routing & render
To ensure that the Edit page for thePostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you mayassertFormSet() that the data in the form matches that of the record:
Saving
You may check that data is correctly saved into the database by callingfillForm() with your form data, and then asserting that the database contains a matching record:
Validation
UseassertHasFormErrors() to ensure that data is properly validated in a form:
Deleting
You can test theDeleteAction using callAction():
DeleteAction using assertActionHidden():
View
Routing & render
To ensure that the View page for thePostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you mayassertFormSet() that the data in the form matches that of the record: