1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
我相信您的問(wèn)題的根源是您正在使用多個(gè)容器實(shí)例。特別是,您的logIn()函數(shù)在客戶端的容器上運(yùn)行,但驗(yàn)證器來(lái)自您在setUp(). 因此,您logIn()對(duì)客戶端容器所做的更改不會(huì)影響您實(shí)際測(cè)試的驗(yàn)證器。
在任何地方使用相同的容器,例如來(lái)自客戶端的容器,應(yīng)該可以解決這個(gè)問(wèn)題。對(duì)存儲(chǔ)庫(kù)的以下更改使測(cè)試通過(guò):
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 關(guān)注
- 156 瀏覽
添加回答
舉報(bào)