【发布时间】:2020-07-29 16:10:42
【问题描述】:
我正在使用 Symfony Panther 进行一些测试。
当我想记录这样的用户时:
protected function setUpPanther()
{
$client = static::createPantherClient(['readinessPath' => '/error']);
$client->manage()->window()->maximize();
$this->client = $client;
}
protected function loginPantherClient(Client $client, User $user)
{
$client->request('GET', '/error');
$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);
}
public function testUpdateProductDetails()
{
$this->setUpPanther();
$admin = $this->getSuperAdminAccount();
$this->loginPantherClient($this->client, $admin);
$this->client->request('GET', '/');
$this->assertSelectorExists('div.form-group');
}
一个奇怪的现象发生了。
-
我的客户端进入错误页面初始化cookie(必填)
-
这里我的印象是我的客户端的身份验证没有考虑到,因为如果你仔细看,在我的测试中,我然后提出一个请求
$this->client->request('GET', '/');
但不是将我重定向到请求的页面,而是将我重定向到 / login,好像在请求期间,用户未经过身份验证,因此被重定向到登录页面,而在我的代码中,我验证了之前的用户
有人遇到过这个问题吗?
【问题讨论】:
标签: php symfony authentication testing phpunit