Certainly! The error you are seeing:
Illuminate\Support\ViewErrorBag::put(): Argument #2 ($bag) must be of type Illuminate\Contracts\Support\MessageBag, null given
typically indicates that, somewhere in your code path, something is trying to add a "null" error bag to the view error bags system (usually in the session), but it must be an actual MessageBag object.
This frequently happens when using Livewire in a testing environment outside of a full Laravel app (like with Orchestra Testbench), especially when the session or error bag system is not set up as expected.
Why does this happen?
Filament and Livewire's registration pages often assume a valid session driver and that the session is started (so error bags can be flashed to the session between requests). During tests, especially when not using Laravel’s RefreshDatabase or correct test setup, this can fail.
Solution
1. Ensure You Have a Valid Session Driver and Middleware
In your Testbench test case (or in your package test setUp), make sure to set a session driver and that the web middleware is applied to your routes:
protected function getEnvironmentSetUp($app)
{
$app['config']->set('session.driver', 'array');
$app['config']->set('session.lottery', [100, 100]);
}
2. Make Sure the Middleware is Applied
If you are registering your package routes, ensure they use the web middleware group:
Route::middleware(['web'])->group(function () {
// your Filament routes...
});
3. Add Session Handling In Your Test
You may need to start the session in your test:
use Illuminate\Support\Facades\Session;
beforeEach(function () {
Session::start();
});
Or, wrap your livewire call in a withSession call:
test('Register page can be visited.', function () {
\Pest\Livewire\livewire(\Filament\Auth\Pages\Register::class)
->setSession(['_token' => csrf_token()])
->assertSee('Password');
});
4. Use Pest’s helpers and Testbench’s built-in features
You can use these in a setUp or beforeEach block to guarantee the environment is right for Livewire and Filament.
Final Example
// in your TestCase or test file
use Illuminate\Support\Facades\Session;
beforeEach(function () {
Session::start();
});
// Your test
test('Register page can be visited.', function () {
\Pest\Livewire\livewire(\Filament\Auth\Pages\Register::class)
->assertSee('Password');
});
And in your Testbench bootstrap:
protected function getEnvironmentSetUp($app)
{
$app['config']->set('session.driver', 'array');
}
Summary:
Make sure the session is started and available, the web middleware is present on your routes, and your test environment mimics an actual Laravel request environment as closely as possible.
Let me know if you need more help!