Symfony 5 - Panther : invalid cookie domain

Viewed 395

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 ?

1 Answers

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/');
Related