-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from langleyfoxall/feature/writing-tests
Added tests correctly
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace LangleyFoxall\LaravelAuthenticationLog\Tests\Feature; | ||
|
||
use Illuminate\Auth\Authenticatable; | ||
use Illuminate\Auth\Events\Failed; | ||
use Illuminate\Auth\Events\Login; | ||
use Illuminate\Auth\Events\Logout; | ||
use Illuminate\Contracts\Auth\Authenticatable as AuthAuthenticatable; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Event; | ||
use LangleyFoxall\LaravelAuthenticationLog\Tests\TestCase; | ||
use LangleyFoxall\LaravelAuthenticationLog\Models\AuthenticationLogRecord; | ||
use LangleyFoxall\LaravelAuthenticationLog\Subscribers\AuthenticationLogSubscriber; | ||
use LangleyFoxall\LaravelAuthenticationLog\Tests\Models\User; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
|
||
class AuthenticationLogSubscriberTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function setUp() : void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
public function test_a_log_record_is_created_when_a_login_event_is_fired() | ||
{ | ||
$user = new User; | ||
$user->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) | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace LangleyFoxall\LaravelAuthenticationLog\Tests\Models; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class User implements Authenticatable | ||
{ | ||
public $id; | ||
|
||
// no-op -- method definitions given to comply with Authenticatable Interface, | ||
// purely for testing purposes only | ||
public function getAuthIdentifierName(){} | ||
public function getAuthIdentifier(){} | ||
public function getAuthPassword(){} | ||
public function getRememberToken(){} | ||
public function setRememberToken($value){} | ||
public function getRememberTokenName(){} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,6 @@ protected function getPackageProviders($app) | |
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters