redirect() in action, strange behaviour
I've got the following test:
and
The first assertion in the test passes.
The second fails with count being 3 !== 2
But, when I remove the
it('bla', function () {
$invitationData = \App\Models\UserInvitation::factory()->make()->toArray();
data_forget($invitationData, 'uuid');
$invitationData['name'] = fake()->name;
$invitationData['email'] = fake()->email;
$invitationData['company'] = fake()->company;
$invitationData['address'] = fake()->address;
$invitationData['postcode'] = fake()->postcode;
$invitation = (new StoreUserInvitation())->execute(invitationData: $invitationData);
livewire(UserInvitationResource\Pages\ViewUserInvitation::class, [
'record' => $invitation->id,
])->callPageAction('resend');
$expectedNewInvitationData = data_get($invitation, [
'name',
'email',
'company',
'address',
'postcode',
]);
$expectedNewInvitationData['status'] = UserInvitationStatus::PENDING;
$this->assertDatabaseCount(\App\Models\UserInvitation::class, 2);
}); it('bla', function () {
$invitationData = \App\Models\UserInvitation::factory()->make()->toArray();
data_forget($invitationData, 'uuid');
$invitationData['name'] = fake()->name;
$invitationData['email'] = fake()->email;
$invitationData['company'] = fake()->company;
$invitationData['address'] = fake()->address;
$invitationData['postcode'] = fake()->postcode;
$invitation = (new StoreUserInvitation())->execute(invitationData: $invitationData);
livewire(UserInvitationResource\Pages\ViewUserInvitation::class, [
'record' => $invitation->id,
])->callPageAction('resend');
$expectedNewInvitationData = data_get($invitation, [
'name',
'email',
'company',
'address',
'postcode',
]);
$expectedNewInvitationData['status'] = UserInvitationStatus::PENDING;
$this->assertDatabaseCount(\App\Models\UserInvitation::class, 2);
});ViewUserInvitation.phpViewUserInvitation.php related parts are: protected function getActions(): array
{
return [
Action::make('resend')->action('resendInvitation'),
];
} protected function getActions(): array
{
return [
Action::make('resend')->action('resendInvitation'),
];
}and
public function resendInvitation()
{
$newInvitationData = Arr::except($this->record->toArray(), [
'id',
'uuid',
'token',
'expires_at',
'status',
'created_at',
'updated_at',
]);
$invitation = (new StoreUserInvitation())->execute(invitationData: $newInvitationData);
return redirect()->route('filament.resources.user-invitations.view', [
'record' => $invitation,
]);
} public function resendInvitation()
{
$newInvitationData = Arr::except($this->record->toArray(), [
'id',
'uuid',
'token',
'expires_at',
'status',
'created_at',
'updated_at',
]);
$invitation = (new StoreUserInvitation())->execute(invitationData: $newInvitationData);
return redirect()->route('filament.resources.user-invitations.view', [
'record' => $invitation,
]);
}The first assertion in the test passes.
The second fails with count being 3 !== 2
But, when I remove the
return redirect()....return redirect().... , the test passes as expected.