DefaultAuthenticationSuccessHandler example

class DefaultAuthenticationSuccessHandlerTest extends TestCase
{
    /** * @dataProvider getRequestRedirections */
    public function testRequestRedirections(Request $request$options$redirectedUrl)
    {
        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
        $urlGenerator->expects($this->any())->method('generate')->willReturn('http://localhost/login');
        $httpUtils = new HttpUtils($urlGenerator);
        $token = $this->createMock(TokenInterface::class);
        $handler = new DefaultAuthenticationSuccessHandler($httpUtils$options);
        if ($request->hasSession()) {
            $handler->setFirewallName('admin');
        }
        $this->assertSame('http://localhost'.$redirectedUrl$handler->onAuthenticationSuccess($request$token)->getTargetUrl());
    }

    public function testRequestRedirectionsWithTargetPathInSessions()
    {
        $session = $this->createMock(SessionInterface::class);
        $session->expects($this->once())->method('get')->with('_security.admin.target_path')->willReturn('/admin/dashboard');
        $session->expects($this->once())->method('remove')->with('_security.admin.target_path');
        
Home | Imprint | This part of the site doesn't use cookies.