On 21.12.2010, at 11:21, Lukas Kahwe Smith wrote:

> 
> On 21.12.2010, at 09:57, Lukas Kahwe Smith wrote:
> 
>> Hi,
>> 
>> I am wondering if someone has figured out how to best do functional tests 
>> that require a given user is logged in? I realize that for this it might be 
>> convenient to define the users via the in-memory provider. But I am not sure 
>> how to best go about writing the test since it requires multiple calls to 
>> the client with a real session. It seems like 
>> https://github.com/knplabs/TestSessionBundle might address this need, though 
>> it seems this should be handled by core.
> 
> 
> in my team someone also tries the following, but it didnt do the trick:
> $client = $this->createClient(array('environment' => 'test'));
> $user = 
> $client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('Application\JoizHardcoreBundle\Entity\User')->findOneBy(array('username'
>  =>'foo'));
> $token = new UsernamePasswordToken($user, null, 
> array('IS_AUTHENTICATED_FULLY', 'IS_AUTHENTICATED_ANONYMOUS'));
> $client->getContainer()->get('security.context')->setToken($token);


it seems that this approach doesnt work, since the token would have to be set 
into the session instead.
for now we got it working with:
$client->request('GET', $url, array(), array(), array('PHP_AUTH_USER' => 
$username 'PHP_AUTH_PW' => $password));

regards,
Lukas Kahwe Smith
[email protected]



-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to