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 关注
- 175 浏览
添加回答
举报
