diff --git a/CHANGELOG.md b/CHANGELOG.md index 077ec7f..23f6b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Can select events to ignore in the Config File - Can select credentials to be omitted from the database in the Config File, such as passwords - Developers can now add authentication events easily through the `AuthenticationLogSubscriber` +- Tests have been implemented to ensure the package works correctly throughout development ## v0.1 diff --git a/tests/Feature/AuthenticationLogSubscriberTest.php b/tests/Feature/AuthenticationLogSubscriberTest.php new file mode 100644 index 0000000..9a6769a --- /dev/null +++ b/tests/Feature/AuthenticationLogSubscriberTest.php @@ -0,0 +1,76 @@ +id = 1; + + $event = new Login('web', $user, false); + + Event::dispatch($event); + + $this->assertDatabaseHas('authentication_log_records', [ + 'authenticatable_id' => $user->id, + 'authenticatable_type' => get_class($user), + 'eventType' => get_class($event) + ]); + } + + public function test_a_log_record_is_created_when_a_logout_event_is_fired() + { + $user = new User; + $user->id = 1; + + $event = new Logout('web', $user); + + Event::dispatch($event); + + $this->assertDatabaseHas('authentication_log_records', [ + 'authenticatable_id' => $user->id, + 'authenticatable_type' => get_class($user), + 'eventType' => get_class($event) + ]); + } + + public function test_a_log_record_is_created_when_a_failed_event_is_fired() + { + $credentials = [ + 'name' => 'notJohn', + ]; + + $event = new Failed('web', null, $credentials); + + Event::dispatch($event); + + $this->assertDatabaseHas('authentication_log_records', [ + 'credentials' => json_encode($credentials), + 'eventType' => get_class($event) + ]); + } +} \ No newline at end of file diff --git a/tests/Models/User.php b/tests/Models/User.php new file mode 100644 index 0000000..85b9743 --- /dev/null +++ b/tests/Models/User.php @@ -0,0 +1,22 @@ + 1, 'authenticatable_type' => "Test Type", + 'eventType' => 'testEvent', 'recorded_at' => $timeLog ];