13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \Security \Core \Authentication \Provider \RememberMeAuthenticationProvider ;
16
+ use Symfony \Component \Security \Core \Authentication \Token \RememberMeToken ;
16
17
use Symfony \Component \Security \Core \Exception \DisabledException ;
17
18
use Symfony \Component \Security \Core \Role \Role ;
19
+ use Symfony \Component \Security \Core \User \User ;
18
20
19
21
class RememberMeAuthenticationProviderTest extends TestCase
20
22
{
@@ -24,6 +26,7 @@ public function testSupports()
24
26
25
27
$ this ->assertTrue ($ provider ->supports ($ this ->getSupportedToken ()));
26
28
$ 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 ()));
27
30
}
28
31
29
32
public function testAuthenticateWhenTokenIsNotSupported ()
@@ -45,6 +48,17 @@ public function testAuthenticateWhenSecretsDoNotMatch()
45
48
$ provider ->authenticate ($ token );
46
49
}
47
50
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
+
48
62
public function testAuthenticateWhenPreChecksFails ()
49
63
{
50
64
$ this ->expectException ('Symfony\Component\Security\Core\Exception\DisabledException ' );
0 commit comments