-
-
Save sethunath/4343150 to your computer and use it in GitHub Desktop.
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 characters
<?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 | |
*/ | |
abstract 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment