Skip to content

Commit

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

namespace App\Listeners;

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

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

Event::assertListening(Logout::class, LogoutListener::class);
}

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

Event::fake();

Event::assertNotDispatched(Login::class);

// Login event triggers when a user logs in
$this->post(route('login'), [
'email' => $user->email,
'password' => 'password',
]);

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

0 comments on commit 27ff63f

Please sign in to comment.