1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \HttpFoundation \Request ;
1616use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
17+ use Symfony \Component \Security \Core \User \InMemoryUserProvider ;
1718use Symfony \Component \Security \Core \User \User ;
18- use Symfony \Component \Security \Core \User \UserProviderInterface ;
1919use Symfony \Component \Security \Http \Authenticator \X509Authenticator ;
2020
2121class X509AuthenticatorTest extends TestCase
@@ -25,7 +25,7 @@ class X509AuthenticatorTest extends TestCase
2525
2626 protected function setUp (): void
2727 {
28- $ this ->userProvider = $ this -> createMock (UserProviderInterface::class );
28+ $ this ->userProvider = new InMemoryUserProvider ( );
2929 $ this ->authenticator = new X509Authenticator ($ this ->userProvider , new TokenStorage (), 'main ' );
3030 }
3131
@@ -45,10 +45,7 @@ public function testAuthentication($username, $credentials)
4545 $ request = $ this ->createRequest ($ serverVars );
4646 $ this ->assertTrue ($ this ->authenticator ->supports ($ request ));
4747
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 ));
5249
5350 $ passport = $ this ->authenticator ->authenticate ($ request );
5451 $ this ->assertEquals ($ username , $ passport ->getUser ()->getUsername ());
@@ -69,10 +66,7 @@ public function testAuthenticationNoUser($emailAddress, $credentials)
6966
7067 $ this ->assertTrue ($ this ->authenticator ->supports ($ request ));
7168
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 ));
7670
7771 $ passport = $ this ->authenticator ->authenticate ($ request );
7872 $ this ->assertEquals ($ emailAddress , $ passport ->getUser ()->getUsername ());
@@ -105,10 +99,7 @@ public function testAuthenticationCustomUserKey()
10599 ]);
106100 $ this ->assertTrue ($ authenticator ->supports ($ request ));
107101
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 ));
112103
113104 $ passport = $ this ->authenticator ->authenticate ($ request );
114105 $ this ->assertEquals ('TheUser ' , $ passport ->getUser ()->getUsername ());
@@ -123,10 +114,7 @@ public function testAuthenticationCustomCredentialsKey()
123114 ]);
124115 $ this ->assertTrue ($ authenticator ->supports ($ request ));
125116
126- $ this ->userProvider ->expects ($ this ->once ())
127- ->method ('loadUserByUsername ' )
128- ->with ('cert@example.com ' )
129- ->willReturn (new User ('cert@example.com ' , null ));
117+ $ this ->userProvider ->createUser (new User ('cert@example.com ' , null ));
130118
131119 $ passport = $ authenticator ->authenticate ($ request );
132120 $ this ->assertEquals ('cert@example.com ' , $ passport ->getUser ()->getUsername ());
0 commit comments