2016-03-07 75 views
0

我想在我的網站上需要驗證的部分運行功能測試。我找到了Symfony 2.x here的解決方案。然而,這不適用於Symfony3工作,因爲這行現在已經過時:Symfony 3功能測試:驗證自己用戶類的用戶

self::$kernel->getContainer()->get('security.context')->setToken($token); 

我的問題是,我怎麼去解決這個,使其與Symfony3工作?謝謝。

回答

0

在Symfony 3中,SecurityContext被拆分爲TokenStorageAuthorizationChecker。因此,你需要使用security.token_storage服務:

self::$kernel->getContainer()->get('security.token_storage')->setToken($token); 

但是,一個簡單的方法是切換到HTTP基本身份驗證在你的測試和配置爲在http://symfony.com/doc/current/cookbook/testing/http_authentication.html描述登錄用戶。