Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 4313453

Browse files
committedFeb 12, 2020
Add tests
1 parent a694831 commit 4313453

14 files changed

+251
-19
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ $logins = request()->user()->logins;
212212
#### Get the current login
213213

214214
```php
215-
$login = request()->user()->currentLogin;
215+
$login = request()->user()->current_login;
216216
```
217217

218218
### Check for the current login

‎composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
"require-dev": {
1818
"mockery/mockery": "^1.0",
1919
"phpunit/phpunit": "^8.0",
20-
"orchestra/testbench": "^4.6"
20+
"orchestra/testbench": "^4.6",
21+
"laravel/airlock": "^0.2.0",
22+
"laravel/passport": "^8.3",
23+
"whichbrowser/parser": "^2.0",
24+
"jenssegers/agent": "^2.6"
2125
},
2226
"autoload": {
2327
"psr-4": {

‎phpunit.xml.dist

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit backupGlobals="false"
33
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="false"
54
bootstrap="vendor/autoload.php"
65
colors="true"
76
convertErrorsToExceptions="true"
@@ -12,12 +11,22 @@
1211
>
1312
<testsuites>
1413
<testsuite name="Auth Tracker Test Suite">
15-
<directory suffix=".php">./tests/</directory>
14+
<directory suffix="Test.php">./tests/</directory>
1615
</testsuite>
1716
</testsuites>
1817
<filter>
19-
<whitelist>
18+
<whitelist processUncoveredFilesFromWhitelist="true">
2019
<directory suffix=".php">./src/</directory>
2120
</whitelist>
2221
</filter>
22+
<php>
23+
<server name="APP_ENV" value="testing"/>
24+
<server name="BCRYPT_ROUNDS" value="4"/>
25+
<server name="CACHE_DRIVER" value="array"/>
26+
<server name="MAIL_DRIVER" value="array"/>
27+
<server name="QUEUE_CONNECTION" value="sync"/>
28+
<server name="SESSION_DRIVER" value="array"/>
29+
<server name="DB_CONNECTION" value="sqlite"/>
30+
<server name="DB_DATABASE" value=":memory:"/>
31+
</php>
2332
</phpunit>

‎src/AuthTrackerServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function boot()
5353
], 'views');
5454

5555
// Load migrations
56-
$this->loadMigrationsFrom(__DIR__.'/../migrations');
56+
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
5757

5858
// Register extended Eloquent user provider
5959
Auth::provider('eloquent-extended', function ($app, array $config) {

‎tests/AirlockUser.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace ALajusticia\AuthTracker\Tests;
4+
5+
use ALajusticia\AuthTracker\Traits\AuthTracking;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
use Laravel\Airlock\HasApiTokens;
8+
9+
class AirlockUser extends Authenticatable
10+
{
11+
use AuthTracking, HasApiTokens;
12+
13+
protected $table = 'users';
14+
15+
protected $fillable = [
16+
'id', 'name', 'email', 'password',
17+
];
18+
19+
protected $hidden = [
20+
'password', 'remember_token',
21+
];
22+
23+
protected $casts = [
24+
'email_verified_at' => 'datetime',
25+
];
26+
}

‎tests/InitialTest.php

-13
This file was deleted.

‎tests/PassportUser.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace ALajusticia\AuthTracker\Tests;
4+
5+
use ALajusticia\AuthTracker\Traits\AuthTracking;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
use Laravel\Passport\HasApiTokens;
8+
9+
class PassportUser extends Authenticatable
10+
{
11+
use AuthTracking, HasApiTokens;
12+
13+
protected $table = 'users';
14+
15+
protected $fillable = [
16+
'id', 'name', 'email', 'password',
17+
];
18+
19+
protected $hidden = [
20+
'password', 'remember_token',
21+
];
22+
23+
protected $casts = [
24+
'email_verified_at' => 'datetime',
25+
];
26+
}

‎tests/SessionTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ALajusticia\AuthTracker\Tests;
4+
5+
use Illuminate\Support\Facades\Auth;
6+
7+
class SessionTest extends TestCase
8+
{
9+
public function test_login_is_tracked()
10+
{
11+
// Create user
12+
$user = factory(User::class)->create();
13+
14+
// Authenticate user to dispatch login event
15+
Auth::login($user);
16+
17+
// Check that current login exists
18+
$currentLogin = $user->logins()
19+
->where('session_id', session()->getId())
20+
->first();
21+
22+
$this->assertNotNull($currentLogin);
23+
}
24+
}

‎tests/TestCase.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace ALajusticia\AuthTracker\Tests;
4+
5+
use ALajusticia\AuthTracker\AuthTrackerServiceProvider;
6+
use ALajusticia\Expirable\ExpirableServiceProvider;
7+
use Laravel\Airlock\AirlockServiceProvider;
8+
use Laravel\Passport\PassportServiceProvider;
9+
10+
abstract class TestCase extends \Orchestra\Testbench\TestCase
11+
{
12+
/**
13+
* Setup the test environment.
14+
*
15+
* @return void
16+
*/
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->loadLaravelMigrations();
22+
23+
$this->artisan('migrate')->run();
24+
25+
$this->withFactories(__DIR__.'/database/factories');
26+
}
27+
28+
/**
29+
* Get package providers.
30+
*
31+
* @param \Illuminate\Foundation\Application $app
32+
*
33+
* @return array
34+
*/
35+
protected function getPackageProviders($app)
36+
{
37+
return [
38+
AuthTrackerServiceProvider::class,
39+
ExpirableServiceProvider::class,
40+
PassportServiceProvider::class,
41+
AirlockServiceProvider::class,
42+
];
43+
}
44+
45+
protected function getEnvironmentSetUp($app)
46+
{
47+
parent::getEnvironmentSetUp($app); // TODO: Change the autogenerated stub
48+
}
49+
}

‎tests/User.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ALajusticia\AuthTracker\Tests;
4+
5+
use ALajusticia\AuthTracker\Traits\AuthTracking;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
8+
class User extends Authenticatable
9+
{
10+
use AuthTracking;
11+
12+
protected $fillable = [
13+
'id', 'name', 'email', 'password',
14+
];
15+
16+
protected $hidden = [
17+
'password', 'remember_token',
18+
];
19+
20+
protected $casts = [
21+
'email_verified_at' => 'datetime',
22+
];
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use ALajusticia\AuthTracker\Tests\AirlockUser;
6+
use Faker\Generator as Faker;
7+
use Illuminate\Support\Str;
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Model Factories
12+
|--------------------------------------------------------------------------
13+
|
14+
| This directory should contain each of the model factory definitions for
15+
| your application. Factories provide a convenient way to generate new
16+
| model instances for testing / seeding your application's database.
17+
|
18+
*/
19+
20+
$factory->define(AirlockUser::class, function (Faker $faker) {
21+
return [
22+
'name' => $faker->name,
23+
'email' => $faker->unique()->safeEmail,
24+
'email_verified_at' => now(),
25+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
26+
'remember_token' => Str::random(10),
27+
];
28+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use ALajusticia\AuthTracker\Tests\PassportUser;
6+
use Faker\Generator as Faker;
7+
use Illuminate\Support\Str;
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Model Factories
12+
|--------------------------------------------------------------------------
13+
|
14+
| This directory should contain each of the model factory definitions for
15+
| your application. Factories provide a convenient way to generate new
16+
| model instances for testing / seeding your application's database.
17+
|
18+
*/
19+
20+
$factory->define(PassportUser::class, function (Faker $faker) {
21+
return [
22+
'name' => $faker->name,
23+
'email' => $faker->unique()->safeEmail,
24+
'email_verified_at' => now(),
25+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
26+
'remember_token' => Str::random(10),
27+
];
28+
});
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/** @var \Illuminate\Database\Eloquent\Factory $factory */
4+
5+
use ALajusticia\AuthTracker\Tests\User;
6+
use Faker\Generator as Faker;
7+
use Illuminate\Support\Str;
8+
9+
/*
10+
|--------------------------------------------------------------------------
11+
| Model Factories
12+
|--------------------------------------------------------------------------
13+
|
14+
| This directory should contain each of the model factory definitions for
15+
| your application. Factories provide a convenient way to generate new
16+
| model instances for testing / seeding your application's database.
17+
|
18+
*/
19+
20+
$factory->define(User::class, function (Faker $faker) {
21+
return [
22+
'name' => $faker->name,
23+
'email' => $faker->unique()->safeEmail,
24+
'email_verified_at' => now(),
25+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
26+
'remember_token' => Str::random(10),
27+
];
28+
});

0 commit comments

Comments
 (0)
This repository has been archived.