-
-
Save fpapadopou/417b0e0576a55ffbdeffc16cfef60b78 to your computer and use it in GitHub Desktop.
Revisions
-
fpapadopou revised this gist
Sep 3, 2017 . No changes.There are no files selected for viewing
-
beberlei created this gist
Sep 17, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <?php use Liip\FunctionalTestBundle\Test\WebTestCase; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\User\UserInterface; /** * @group functional */ class MyWebTestCase extends WebTestCase { abstract protected function getCurrentUser(); /** * @param string $firewallName * @param array $options * @param array $server * @return Symfony\Component\BrowserKit\Client */ protected function createClientWithAuthentication($firewallName, array $options = array(), array $server = array()) { /* @var $client \Symfony\Component\BrowserKit\Client */ $client = $this->createClient($options, $server); // has to be set otherwise "hasPreviousSession" in Request returns false. $client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie(session_name(), true)); /* @var $user UserInterface */ $user = $this->getCurrentUser(); $token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles()); self::$kernel->getContainer()->get('session')->set('_security_' . $firewallName, serialize($token)); return $client; } }