Skip to content

Commit bf1cc0f

Browse files
committed
Add fake app classes
1 parent 5aaf057 commit bf1cc0f

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Http\Controllers;
4+
5+
use Illuminate\Foundation\Bus\DispatchesJobs;
6+
use Illuminate\Routing\Controller as BaseController;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Http\Controllers\Identities\Auth;
4+
5+
use Tests\Fixtures\Http\Controllers\Controller;
6+
use Oneofftech\Identities\Auth\AuthenticatesUsersWithIdentity;
7+
8+
class LoginController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Login via Identity Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller handles authenticating users via their connected
16+
| identities provided by third party authentication services.
17+
| The controller uses a trait to conveniently provide its
18+
| functionality to your applications.
19+
|
20+
*/
21+
22+
use AuthenticatesUsersWithIdentity;
23+
24+
/**
25+
* Create a new controller instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
$this->middleware('guest');
32+
}
33+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Http\Controllers\Identities\Auth;
4+
5+
use Tests\Fixtures\User;
6+
use Illuminate\Support\Str;
7+
use Tests\Fixtures\Http\Controllers\Controller;
8+
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Support\Facades\Validator;
10+
use Oneofftech\Identities\Auth\RegistersUsersWithIdentity;
11+
12+
class RegisterController extends Controller
13+
{
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Register via Identity Controller
17+
|--------------------------------------------------------------------------
18+
|
19+
| This controller handles the registration of new users via identities
20+
| provided by third party authentication services. The controller
21+
| uses a trait to conveniently provide its functionality.
22+
|
23+
*/
24+
25+
use RegistersUsersWithIdentity;
26+
27+
/**
28+
* Create a new controller instance.
29+
*
30+
* @return void
31+
*/
32+
public function __construct()
33+
{
34+
$this->middleware('guest');
35+
}
36+
37+
/**
38+
* Get a validator for an incoming registration request.
39+
*
40+
* @param array $data
41+
* @return \Illuminate\Contracts\Validation\Validator
42+
*/
43+
protected function validator(array $data)
44+
{
45+
return Validator::make($data, [
46+
'name' => ['required', 'string', 'max:255'],
47+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
48+
'password' => ['sometimes', 'required', 'string', 'min:8', 'confirmed'],
49+
]);
50+
}
51+
52+
/**
53+
* Create a new user instance after a valid registration.
54+
*
55+
* @param array $data
56+
* @return \Illuminate\Contracts\Auth\Authenticatable|\App\User
57+
*/
58+
protected function create(array $data)
59+
{
60+
return User::create([
61+
'name' => $data['name'],
62+
'email' => $data['email'],
63+
'password' => Hash::make($data['password'] ?? Str::random(20)),
64+
]);
65+
}
66+
}

tests/Fixtures/Identity.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
use Oneofftech\Identities\Facades\Identity as IdentityFacade;
8+
9+
class Identity extends Model
10+
{
11+
12+
/**
13+
* @var array
14+
*/
15+
protected $casts = [
16+
'expires_at' => 'datetime',
17+
'registration' => 'bool',
18+
];
19+
20+
/**
21+
* @var array
22+
*/
23+
protected $fillable = [
24+
'user_id',
25+
'provider_id',
26+
'provider',
27+
'token',
28+
'refresh_token',
29+
'expires_at',
30+
'registration',
31+
];
32+
33+
/**
34+
* @var array
35+
*/
36+
protected $hidden = [
37+
'provider_id',
38+
'token',
39+
'refresh_token',
40+
'expires_at',
41+
];
42+
43+
/**
44+
*
45+
*/
46+
public function user()
47+
{
48+
return $this->belongsTo(IdentityFacade::userModel());
49+
}
50+
}

tests/Fixtures/User.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
use Oneofftech\Identities\WithIdentities;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
8+
class User extends Authenticatable
9+
{
10+
use WithIdentities;
11+
}

0 commit comments

Comments
 (0)