The difficult role is that the test browser destroys the context object before each request (see sfBrowser :: call () ).
You can authenticate the user by introducing a listener that will call the user method signIn() when the context.load_factories event fires during context initialization:
function signin( sfEvent $event ) { if( ! $user = $event->getSubject()->getUser() ) { throw new RuntimeException('User object not created.'); } if( ! $user instanceof sfGuardSecurityUser ) { throw new LogicException(sprintf( 'Cannot log in %s; sfGuardSecurityUser expected.', get_class($user) )); } if( $user->isAuthenticated() ) { $user->signOut(); } $user->signIn($desired_user_to_log_in_as); $event->getSubject()->getEventDispatcher()->notify(new sfEvent( $this, 'application.log', array(sprintf('User is logged in as "%s".', $user->getUsername())) )); } $b->addListener('context.load_factories', 'signin');
This will cause the browser to log in to all subsequent requests. Note that sfBrowser does not have a removeListener() method.
Adapted from sfJwtPhpUnitPlugin (FD: I am the lead developer for this project).
user212218
source share