1212namespace Symfony \Component \Security \Core \Tests \Authentication ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
1516use Symfony \Component \Security \Core \Authentication \AuthenticationProviderManager ;
17+ use Symfony \Component \Security \Core \Authentication \Provider \AuthenticationProviderInterface ;
1618use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
1719use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
1820use Symfony \Component \Security \Core \AuthenticationEvents ;
@@ -35,7 +37,7 @@ public function testAuthenticateWithProvidersWithIncorrectInterface()
3537 $ this ->expectException (\InvalidArgumentException::class);
3638 (new AuthenticationProviderManager ([
3739 new \stdClass (),
38- ]))->authenticate ($ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
40+ ]))->authenticate ($ this ->createMock (TokenInterface::class));
3941 }
4042
4143 public function testAuthenticateWhenNoProviderSupportsToken ()
@@ -45,7 +47,7 @@ public function testAuthenticateWhenNoProviderSupportsToken()
4547 ]);
4648
4749 try {
48- $ manager ->authenticate ($ token = $ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
50+ $ manager ->authenticate ($ token = $ this ->createMock (TokenInterface::class));
4951 $ this ->fail ();
5052 } catch (ProviderNotFoundException $ e ) {
5153 $ this ->assertSame ($ token , $ e ->getToken ());
@@ -54,18 +56,18 @@ public function testAuthenticateWhenNoProviderSupportsToken()
5456
5557 public function testAuthenticateWhenProviderReturnsAccountStatusException ()
5658 {
57- $ secondAuthenticationProvider = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Provider \ AuthenticationProviderInterface::class)-> getMock ( );
59+ $ secondAuthenticationProvider = $ this ->createMock ( AuthenticationProviderInterface::class);
5860
5961 $ manager = new AuthenticationProviderManager ([
60- $ this ->getAuthenticationProvider (true , null , ' Symfony\Component\Security\Core\Exception\ AccountStatusException' ),
62+ $ this ->getAuthenticationProvider (true , null , AccountStatusException::class ),
6163 $ secondAuthenticationProvider ,
6264 ]);
6365
6466 // AccountStatusException stops authentication
6567 $ secondAuthenticationProvider ->expects ($ this ->never ())->method ('supports ' );
6668
6769 try {
68- $ manager ->authenticate ($ token = $ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
70+ $ manager ->authenticate ($ token = $ this ->createMock (TokenInterface::class));
6971 $ this ->fail ();
7072 } catch (AccountStatusException $ e ) {
7173 $ this ->assertSame ($ token , $ e ->getToken ());
@@ -75,11 +77,11 @@ public function testAuthenticateWhenProviderReturnsAccountStatusException()
7577 public function testAuthenticateWhenProviderReturnsAuthenticationException ()
7678 {
7779 $ manager = new AuthenticationProviderManager ([
78- $ this ->getAuthenticationProvider (true , null , ' Symfony\Component\Security\Core\Exception\ AuthenticationException' ),
80+ $ this ->getAuthenticationProvider (true , null , AuthenticationException::class ),
7981 ]);
8082
8183 try {
82- $ manager ->authenticate ($ token = $ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
84+ $ manager ->authenticate ($ token = $ this ->createMock (TokenInterface::class));
8385 $ this ->fail ();
8486 } catch (AuthenticationException $ e ) {
8587 $ this ->assertSame ($ token , $ e ->getToken ());
@@ -89,27 +91,27 @@ public function testAuthenticateWhenProviderReturnsAuthenticationException()
8991 public function testAuthenticateWhenOneReturnsAuthenticationExceptionButNotAll ()
9092 {
9193 $ manager = new AuthenticationProviderManager ([
92- $ this ->getAuthenticationProvider (true , null , ' Symfony\Component\Security\Core\Exception\ AuthenticationException' ),
93- $ this ->getAuthenticationProvider (true , $ expected = $ this ->getMockBuilder (TokenInterface::class)-> getMock ( )),
94+ $ this ->getAuthenticationProvider (true , null , AuthenticationException::class ),
95+ $ this ->getAuthenticationProvider (true , $ expected = $ this ->createMock (TokenInterface::class)),
9496 ]);
9597
96- $ token = $ manager ->authenticate ($ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
98+ $ token = $ manager ->authenticate ($ this ->createMock (TokenInterface::class));
9799 $ this ->assertSame ($ expected , $ token );
98100 }
99101
100102 public function testAuthenticateReturnsTokenOfTheFirstMatchingProvider ()
101103 {
102- $ second = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Provider \ AuthenticationProviderInterface::class)-> getMock ( );
104+ $ second = $ this ->createMock ( AuthenticationProviderInterface::class);
103105 $ second
104106 ->expects ($ this ->never ())
105107 ->method ('supports ' )
106108 ;
107109 $ manager = new AuthenticationProviderManager ([
108- $ this ->getAuthenticationProvider (true , $ expected = $ this ->getMockBuilder (TokenInterface::class)-> getMock ( )),
110+ $ this ->getAuthenticationProvider (true , $ expected = $ this ->createMock (TokenInterface::class)),
109111 $ second ,
110112 ]);
111113
112- $ token = $ manager ->authenticate ($ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
114+ $ token = $ manager ->authenticate ($ this ->createMock (TokenInterface::class));
113115 $ this ->assertSame ($ expected , $ token );
114116 }
115117
@@ -119,25 +121,25 @@ public function testEraseCredentialFlag()
119121 $ this ->getAuthenticationProvider (true , $ token = new UsernamePasswordToken ('foo ' , 'bar ' , 'key ' )),
120122 ]);
121123
122- $ token = $ manager ->authenticate ($ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
124+ $ token = $ manager ->authenticate ($ this ->createMock (TokenInterface::class));
123125 $ this ->assertEquals ('' , $ token ->getCredentials ());
124126
125127 $ manager = new AuthenticationProviderManager ([
126128 $ this ->getAuthenticationProvider (true , $ token = new UsernamePasswordToken ('foo ' , 'bar ' , 'key ' )),
127129 ], false );
128130
129- $ token = $ manager ->authenticate ($ this ->getMockBuilder (TokenInterface::class)-> getMock ( ));
131+ $ token = $ manager ->authenticate ($ this ->createMock (TokenInterface::class));
130132 $ this ->assertEquals ('bar ' , $ token ->getCredentials ());
131133 }
132134
133135 public function testAuthenticateDispatchesAuthenticationFailureEvent ()
134136 {
135137 $ token = new UsernamePasswordToken ('foo ' , 'bar ' , 'key ' );
136- $ provider = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Provider \ AuthenticationProviderInterface::class)-> getMock ( );
138+ $ provider = $ this ->createMock ( AuthenticationProviderInterface::class);
137139 $ provider ->expects ($ this ->once ())->method ('supports ' )->willReturn (true );
138140 $ provider ->expects ($ this ->once ())->method ('authenticate ' )->willThrowException ($ exception = new AuthenticationException ());
139141
140- $ dispatcher = $ this ->getMockBuilder (\ Symfony \ Component \ EventDispatcher \ EventDispatcherInterface::class)-> getMock ( );
142+ $ dispatcher = $ this ->createMock ( EventDispatcherInterface::class);
141143 $ dispatcher
142144 ->expects ($ this ->once ())
143145 ->method ('dispatch ' )
@@ -158,11 +160,11 @@ public function testAuthenticateDispatchesAuthenticationSuccessEvent()
158160 {
159161 $ token = new UsernamePasswordToken ('foo ' , 'bar ' , 'key ' );
160162
161- $ provider = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Provider \ AuthenticationProviderInterface::class)-> getMock ( );
163+ $ provider = $ this ->createMock ( AuthenticationProviderInterface::class);
162164 $ provider ->expects ($ this ->once ())->method ('supports ' )->willReturn (true );
163165 $ provider ->expects ($ this ->once ())->method ('authenticate ' )->willReturn ($ token );
164166
165- $ dispatcher = $ this ->getMockBuilder (\ Symfony \ Component \ EventDispatcher \ EventDispatcherInterface::class)-> getMock ( );
167+ $ dispatcher = $ this ->createMock ( EventDispatcherInterface::class);
166168 $ dispatcher
167169 ->expects ($ this ->once ())
168170 ->method ('dispatch ' )
@@ -176,7 +178,7 @@ public function testAuthenticateDispatchesAuthenticationSuccessEvent()
176178
177179 protected function getAuthenticationProvider ($ supports , $ token = null , $ exception = null )
178180 {
179- $ provider = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Provider \ AuthenticationProviderInterface::class)-> getMock ( );
181+ $ provider = $ this ->createMock ( AuthenticationProviderInterface::class);
180182 $ provider ->expects ($ this ->once ())
181183 ->method ('supports ' )
182184 ->willReturn ($ supports )
0 commit comments