use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Tests\Authentication\Token\Fixtures\CustomUser;
use Symfony\Component\Security\Core\User\InMemoryUser;
class SwitchUserTokenTest extends TestCase
{ public function testSerialize() { $originalToken =
new UsernamePasswordToken(new InMemoryUser('user', 'foo',
['ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'
]), 'provider-key',
['ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'
]);
$token =
new SwitchUserToken(new InMemoryUser('admin', 'bar',
['ROLE_USER'
]), 'provider-key',
['ROLE_USER'
],
$originalToken, 'https://symfony.com/blog'
);
$unserializedToken =
unserialize(serialize($token));
$this->
assertInstanceOf(SwitchUserToken::
class,
$unserializedToken);
$this->
assertSame('admin',
$unserializedToken->
getUserIdentifier());
$this->
assertSame('provider-key',
$unserializedToken->
getFirewallName());
$this->
assertEquals(['ROLE_USER'
],
$unserializedToken->
getRoleNames());
$this->
assertSame('https://symfony.com/blog',
$unserializedToken->
getOriginatedFromUri());
$unserializedOriginalToken =
$unserializedToken->
getOriginalToken();