@@ -55,14 +55,13 @@ public function setUp()
55
55
{
56
56
parent ::setUp ();
57
57
58
- $ this ->authorizer = new Authorizer ();
59
- $ this ->user_repository = new UserRepository ([
60
- '[email protected] ' =>
new AuthenticatedUser (
1 ,
'[email protected] ' ,
'John Doe ' ,
'123 ' ),
61
- ]);
58
+ $ authenticated_user =
new AuthenticatedUser (
1 ,
'[email protected] ' ,
'John Doe ' ,
'123 ' );
59
+ $ this ->authorizer = new Authorizer ($ authenticated_user );
60
+ $ this ->
user_repository =
new UserRepository ([
'[email protected] ' =>
$ authenticated_user]);
62
61
$ this ->empty_user_repository = new UserRepository ();
63
62
$ this ->token_repository = new TokenRepository ([
64
- '123 ' =>
new Token (
123 ,
'[email protected] ' ),
]
65
- );
63
+ '123 ' =>
new Token (
123 ,
'[email protected] ' ),
64
+ ] );
66
65
$ this ->empty_token_repository = new TokenRepository ();
67
66
$ this ->
authenticated_user =
new AuthenticatedUser (
1 ,
'[email protected] ' ,
'John Doe ' ,
'123 ' );
68
67
$ this ->request = $ this ->request ->withHeader ('Authorization ' , 'Bearer 123 ' );
@@ -74,21 +73,14 @@ public function setUp()
74
73
*/
75
74
public function testForInvalidAdapterExceptionIsThrown ()
76
75
{
77
- new Authentication ([new stdClass ()], $ this -> authorizer );
76
+ new Authentication ([new stdClass ()]);
78
77
}
79
78
80
- /**
81
- * @expectedException ActiveCollab\Authentication\Exception\InvalidCredentialsException
82
- * @expectedExceptionMessage Invalid credentials provided
83
- */
84
- public function testForInvalidCredentialsExceptionIsThrown ()
79
+ public function testAdaptersNotInitializedReturnsRequest ()
85
80
{
86
- $ authentication = new Authentication (
87
- [new TokenBearer ($ this ->user_repository , $ this ->token_repository )],
88
- $ this ->authorizer
89
- );
81
+ $ request = (new Authentication ([]))->initialize ($ this ->request );
90
82
91
- $ authentication -> authorize ( $ this -> request ,
[ ' username ' => ' [email protected] ' ] );
83
+ $ this -> assertSame ( $ request , $ this -> request );
92
84
}
93
85
94
86
/**
@@ -99,7 +91,7 @@ public function testFailedAdapterInitializationThrowsException()
99
91
{
100
92
$ token_bearer = new TokenBearer ($ this ->empty_user_repository , $ this ->empty_token_repository );
101
93
102
- (new Authentication ([$ token_bearer ], $ this -> authorizer ))->initialize ($ this ->request );
94
+ (new Authentication ([$ token_bearer ]))->initialize ($ this ->request );
103
95
}
104
96
105
97
/**
@@ -116,27 +108,13 @@ public function testMultipleAdapterSuccessfullyInitializedThrowsException()
116
108
$ authentication ->initialize ($ this ->request );
117
109
}
118
110
119
- /**
120
- * @expectedException RuntimeException
121
- * @expectedExceptionMessage Authorizer object is not configured
122
- */
123
- public function testForNotConfiguredAuthorizerExceptionIsThrown ()
124
- {
125
- $ authentication = new Authentication ([new TokenBearer ($ this ->user_repository , $ this ->token_repository )], null );
126
-
127
- $ authentication->
authorize (
$ this ->
request , [
'username ' =>
'[email protected] ' ]);
128
- }
129
-
130
111
public function testUserIsAuthorized ()
131
112
{
132
- $ authentication = new Authentication (
133
- [new TokenBearer ($ this ->user_repository , $ this ->token_repository )],
134
- $ this ->authorizer
135
- );
113
+ $ token_bearer = new TokenBearer ($ this ->user_repository , $ this ->token_repository );
136
114
115
+ $ authentication = new Authentication ([$ token_bearer ]);
137
116
$ request = $ authentication ->initialize ($ this ->request );
138
-
139
- $ authentication_result =
$ authentication->
authorize (
$ request, [
'username ' =>
'[email protected] ' ]);
117
+ $ authentication_result =
$ authentication->
authorize (
$ this ->
authorizer ,
$ token_bearer, [
'username ' =>
'[email protected] ' ]);
140
118
141
119
$ this ->assertInstanceOf (AuthenticationResultInterface::class, $ authentication_result );
142
120
}
0 commit comments