1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \Security \Core \Authentication \Provider \RememberMeAuthenticationProvider ;
16+ use Symfony \Component \Security \Core \Authentication \Token \RememberMeToken ;
1617use Symfony \Component \Security \Core \Exception \DisabledException ;
1718use Symfony \Component \Security \Core \Role \Role ;
19+ use Symfony \Component \Security \Core \User \User ;
1820
1921class RememberMeAuthenticationProviderTest extends TestCase
2022{
@@ -24,6 +26,7 @@ public function testSupports()
2426
2527 $ this ->assertTrue ($ provider ->supports ($ this ->getSupportedToken ()));
2628 $ this ->assertFalse ($ provider ->supports ($ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ()));
29+ $ this ->assertFalse ($ provider ->supports ($ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken ' )->disableOriginalConstructor ()->getMock ()));
2730 }
2831
2932 public function testAuthenticateWhenTokenIsNotSupported ()
@@ -45,6 +48,17 @@ public function testAuthenticateWhenSecretsDoNotMatch()
4548 $ provider ->authenticate ($ token );
4649 }
4750
51+ public function testAuthenticateThrowsOnNonUserInterfaceInstance ()
52+ {
53+ $ this ->expectException ('Symfony\Component\Security\Core\Exception\LogicException ' );
54+ $ this ->expectExceptionMessage ('Method "Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::getUser()" must return a "Symfony\Component\Security\Core\User\UserInterface" instance, "string" returned. ' );
55+
56+ $ provider = $ this ->getProvider ();
57+ $ token = new RememberMeToken (new User ('dummyuser ' , null ), 'foo ' , 'test ' );
58+ $ token ->setUser ('stringish-user ' );
59+ $ provider ->authenticate ($ token );
60+ }
61+
4862 public function testAuthenticateWhenPreChecksFails ()
4963 {
5064 $ this ->expectException ('Symfony\Component\Security\Core\Exception\DisabledException ' );
0 commit comments