Skip to content

Commit

Permalink
Test subscribing to Logout builtin event
Browse files Browse the repository at this point in the history
  • Loading branch information
unclexo committed Jan 16, 2023
1 parent 27ff63f commit 606217e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/Listeners/LogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Listeners;

use App\Events\Logout;
use Illuminate\Auth\Events\Logout;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

Expand All @@ -21,11 +21,11 @@ public function __construct()
/**
* Handle the event.
*
* @param \App\Events\Logout $event
* @param \Illuminate\Auth\Events\Logout $event
* @return void
*/
public function handle(Logout $event)
{
//
logger("Logged out user: {$event->user->email}");
}
}
17 changes: 17 additions & 0 deletions tests/Feature/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,21 @@ public function subscribing_to_login_event()
return $event->user->email === $user->email;
});
}

/** @test */
public function subscribing_to_logout_event()
{
$this->actingAs($user = User::factory()->create());

Event::fake();

Event::assertNotDispatched(Logout::class);

// Logout event triggers when a user logs out
$this->post(route('logout'));

Event::assertDispatched(Logout::class, function($event) use($user) {
return $event->user->email === $user->email;
});
}
}

0 comments on commit 606217e

Please sign in to comment.