Kane G
Kane G
FFilament
Created by Kane G on 10/28/2024 in #❓┊help
Is it possible to test broadcast notifications?
I'm currently using reverb to broadcast notifications, everything is working fine and the notifications are coming through. I'd like to run some tests to ensure this is always the case but I can't seem to get assertNotified to return true while using toBroadcast(). If I switch it back to send() the notification test passes (which a few other small changes - eg. removing notification from notify() function.) I'm triggering the notification like this:
try {
if (Carbon::parse($this->data['starts_at'])->gte(Carbon::parse($this->data['ends_at']))) {
throw new \Exception('Date Error');
}
} catch (\Exception $e) {
auth()->user()->notify(
Notification::make()
->danger()
->title('Date Error')
->body('Ends at date should be greater than the starts at date.')
->persistent()
->toBroadcast()
);

$this->halt();
}
try {
if (Carbon::parse($this->data['starts_at'])->gte(Carbon::parse($this->data['ends_at']))) {
throw new \Exception('Date Error');
}
} catch (\Exception $e) {
auth()->user()->notify(
Notification::make()
->danger()
->title('Date Error')
->body('Ends at date should be greater than the starts at date.')
->persistent()
->toBroadcast()
);

$this->halt();
}
Testing notification like this:
Livewire::actingAs($this->user)
->test(CreateTenancy::class)
->fillForm([
'starts_at' => now()->addDays(5)->toDateString(),
'ends_at' => now()->toDateString(),
])
->call('create')
->assertNotified(
Notification::make()
->danger()
->title('Date Error')
->body('Ends at date should be greater than the starts at date.')
->persistent()
);
Livewire::actingAs($this->user)
->test(CreateTenancy::class)
->fillForm([
'starts_at' => now()->addDays(5)->toDateString(),
'ends_at' => now()->toDateString(),
])
->call('create')
->assertNotified(
Notification::make()
->danger()
->title('Date Error')
->body('Ends at date should be greater than the starts at date.')
->persistent()
);
Test currently fails with:
A notification was not sent
Failed asserting that null is not null.
A notification was not sent
Failed asserting that null is not null.
Thanks.
2 replies
FFilament
Created by Kane G on 9/30/2024 in #❓┊help
Action $arguments returning empty in visible closure
I'm currently trying to access to $arguments data within a visible closure but it's currently returning empty. Is it possible to access this variable here? I know $arguments are being passed correctly because they work fine in modalDescription This is an Action on a custom Livewire component on a custom page using Filament\Actions\Action Function not working: ->visible(fn(array $arguments) => dd($arguments)) Result: [] // app/Livewire/SubscriptionManagement.php:134 Function working: ->modalDescription(fn(array $arguments) => dd($arguments)) Result:
array:1 [▼ // app/Livewire/SubscriptionManagement.php:136
"name" => "Test Subscription"
]
array:1 [▼ // app/Livewire/SubscriptionManagement.php:136
"name" => "Test Subscription"
]
Any help would be appreciated.
5 replies