简体   繁体   中英

Symfony 5 - Panther : invalid cookie domain

I'm trying to use Panther for PhpUnit Tests in my Symfony 5 application.

When I try to log an user, like this:

$client = static::createPantherClient();

/** @var User $user */
$user = $this->getSuperAdminAccount();

$session = self::$container->get('session');

$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$session->set('_security_main', serialize($token));
$session->save();

$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);

when I run the test, I get:

Panther Facebook\WebDriver\Exception\InvalidCookieDomainException: invalid cookie domain

Can someone help me please?

if anyone has the same problem, I found a solution on Github: https://github.com/symfony/panther/issues/283#issuecomment-674524048

Just request domain before adding a cookie:

$client->request('GET', 'https://www.google.com/');
$client->getCookieJar()->set(new Cookie('my_cookie', 'hello', domain: '.google.com'));
$client->request('GET', 'https://www.google.com/');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM