TestBrowserToken example



namespace Symfony\Bundle\FrameworkBundle\Tests\Test;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\TestBrowserToken;

final class TestBrowserTokenTest extends TestCase
{
    public function testCanBeSerializedAndUnserialized()
    {
        $token = unserialize(serialize(new TestBrowserToken()));

        $this->assertSame('main', $token->getFirewallName());
    }
}

        $tokenAttributes = 2 < \func_num_args() ? func_get_arg(2) : [];

        if (!interface_exists(UserInterface::class)) {
            throw new \LogicException(sprintf('"%s" requires symfony/security-core to be installed. Try running "composer require symfony/security-core".', __METHOD__));
        }

        if (!$user instanceof UserInterface) {
            throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::classget_debug_type($user)));
        }

        $token = new TestBrowserToken($user->getRoles()$user$firewallContext);
        $token->setAttributes($tokenAttributes);
        // required for compatibility with Symfony 5.4         if (method_exists($token, 'isAuthenticated')) {
            $token->setAuthenticated(true, false);
        }

        $container = $this->getContainer();
        $container->get('security.untracked_token_storage')->setToken($token);

        if (!$container->has('session.factory')) {
            return $this;
        }
Home | Imprint | This part of the site doesn't use cookies.