1 回答
TA貢獻1828條經驗 獲得超13個贊
我相信您的問題的根源是您正在使用多個容器實例。特別是,您的logIn()函數在客戶端的容器上運行,但驗證器來自您在setUp(). 因此,您logIn()對客戶端容器所做的更改不會影響您實際測試的驗證器。
在任何地方使用相同的容器,例如來自客戶端的容器,應該可以解決這個問題。對存儲庫的以下更改使測試通過:
diff --git a/tests/AppBundle/Validator/UserTest.php b/tests/AppBundle/Validator/UserTest.php
index f15c854..603e566 100644
--- a/tests/AppBundle/Validator/UserTest.php
+++ b/tests/AppBundle/Validator/UserTest.php
@@ -44,10 +44,7 @@ class UserTest extends WebTestCase{
$this->container = $this->client->getContainer();
$this->entityManager = $this->container->get('doctrine.orm.entity_manager');
- // Set validator
- $kernel = $this->createKernel();
- $kernel->boot();
- $this->validator = $kernel->getContainer()->get('validator');
+ $this->validator = $this->client->getContainer()->get('validator');
// Create one user
$this->createOneUser();
@@ -100,7 +97,7 @@ class UserTest extends WebTestCase{
// you may need to use a different token class depending on your application.
// for example, when using Guard authentication you must instantiate PostAuthenticationGuardToken
$token = new PostAuthenticationGuardToken($user, $firewallName, [new Role('ROLE_CLIENT')]);
- self::$kernel->getContainer()->get('security.token_storage')->setToken($token);
+ $this->client->getContainer()->get('security.token_storage')->setToken($token);
$session->set('_security_'.$firewallName, serialize($token));
$session->save();
- 1 回答
- 0 關注
- 171 瀏覽
添加回答
舉報
