14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \HttpFoundation \Request ;
16
16
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
17
+ use Symfony \Component \Security \Core \User \InMemoryUserProvider ;
17
18
use Symfony \Component \Security \Core \User \User ;
18
- use Symfony \Component \Security \Core \User \UserProviderInterface ;
19
19
use Symfony \Component \Security \Http \Authenticator \X509Authenticator ;
20
20
21
21
class X509AuthenticatorTest extends TestCase
@@ -25,7 +25,7 @@ class X509AuthenticatorTest extends TestCase
25
25
26
26
protected function setUp (): void
27
27
{
28
- $ this ->userProvider = $ this -> createMock (UserProviderInterface::class );
28
+ $ this ->userProvider = new InMemoryUserProvider ( );
29
29
$ this ->authenticator = new X509Authenticator ($ this ->userProvider , new TokenStorage (), 'main ' );
30
30
}
31
31
@@ -45,10 +45,7 @@ public function testAuthentication($username, $credentials)
45
45
$ request = $ this ->createRequest ($ serverVars );
46
46
$ this ->assertTrue ($ this ->authenticator ->supports ($ request ));
47
47
48
- $ this ->userProvider ->expects ($ this ->any ())
49
- ->method ('loadUserByUsername ' )
50
- ->with ($ username )
51
- ->willReturn (new User ($ username , null ));
48
+ $ this ->userProvider ->createUser (new User ($ username , null ));
52
49
53
50
$ passport = $ this ->authenticator ->authenticate ($ request );
54
51
$ this ->assertEquals ($ username , $ passport ->getUser ()->getUsername ());
@@ -69,10 +66,7 @@ public function testAuthenticationNoUser($emailAddress, $credentials)
69
66
70
67
$ this ->assertTrue ($ this ->authenticator ->supports ($ request ));
71
68
72
- $ this ->userProvider ->expects ($ this ->once ())
73
- ->method ('loadUserByUsername ' )
74
- ->with ($ emailAddress )
75
- ->willReturn (new User ($ emailAddress , null ));
69
+ $ this ->userProvider ->createUser (new User ($ emailAddress , null ));
76
70
77
71
$ passport = $ this ->authenticator ->authenticate ($ request );
78
72
$ this ->assertEquals ($ emailAddress , $ passport ->getUser ()->getUsername ());
@@ -105,10 +99,7 @@ public function testAuthenticationCustomUserKey()
105
99
]);
106
100
$ this ->assertTrue ($ authenticator ->supports ($ request ));
107
101
108
- $ this ->userProvider ->expects ($ this ->once ())
109
- ->method ('loadUserByUsername ' )
110
- ->with ('TheUser ' )
111
- ->willReturn (new User ('TheUser ' , null ));
102
+ $ this ->userProvider ->createUser (new User ('TheUser ' , null ));
112
103
113
104
$ passport = $ this ->authenticator ->authenticate ($ request );
114
105
$ this ->assertEquals ('TheUser ' , $ passport ->getUser ()->getUsername ());
@@ -123,10 +114,7 @@ public function testAuthenticationCustomCredentialsKey()
123
114
]);
124
115
$ this ->assertTrue ($ authenticator ->supports ($ request ));
125
116
126
- $ this ->userProvider ->expects ($ this ->once ())
127
- ->method ('loadUserByUsername ' )
128
-
129
- ->
willReturn (
new User (
'[email protected] ' ,
null ));
117
+ $ this ->
userProvider ->
createUser (
new User (
'[email protected] ' ,
null ));
130
118
131
119
$ passport = $ authenticator ->authenticate ($ request );
132
120
$ this ->
assertEquals (
'[email protected] ' ,
$ passport->
getUser ()->
getUsername ());
0 commit comments