/** * @param Request $request * @param null|AuthenticationException $authException * @return Response */ public function start(Request $request, AuthenticationException $authException = null) { $action = $this->config['login_action']; $manager = $this->factory->getManager($this->config['manager'], $request->getUriForPath($this->config['check_path'])); if ($action) { return $this->httpKernel->forward($action, array('manager' => $manager, 'request' => $request, 'exception' => $authException)); } return new RedirectResponse($manager->getServer()->getLoginUrl()); }
/** * @param Request $request * @param null|AuthenticationException $authException * * @return Response */ public function onLogoutSuccess(Request $request) { $action = $this->config['logout_action']; $manager = $this->factory->getManager($this->config['manager'], $request->getUriForPath($this->config['check_path'])); if ($action) { return $this->httpKernel->forward($action, array('manager' => $manager, 'request' => $request)); } return new RedirectResponse($manager->getServer()->getLogoutUrl()); }
public function testGenerateInternalUriHandlesNullValues() { $request = new Request(); $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->at(0))->method('get')->with($this->equalTo('router'))->will($this->returnValue($router)); $container->expects($this->at('1'))->method('get')->with($this->equalTo('request'))->will($this->returnValue($request)); $controller = 'AController'; $attributes = array('anAttribute' => null); $query = array('aQueryParam' => null); $expectedPath = 'none'; $routeParameters = array('controller' => $controller, 'path' => $expectedPath, '_format' => 'html'); $router->expects($this->once())->method('generate')->with($this->equalTo('_internal'), $this->equalTo($routeParameters))->will($this->returnValue('GENERATED_URI')); $dispatcher = new EventDispatcher(); $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); $kernel = new HttpKernel($dispatcher, $container, $resolver); $uri = $kernel->generateInternalUri($controller, $attributes, $query); $this->assertEquals('GENERATED_URI', $uri); }
/** * @dataProvider getProviderTypes */ public function testHandleRestoresThePreviousRequestOnException($type) { $request = new Request(); $expected = new \Exception(); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->once())->method('enterScope')->with($this->equalTo('request')); $container->expects($this->once())->method('leaveScope')->with($this->equalTo('request')); $container->expects($this->once())->method('set')->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request')); $dispatcher = new EventDispatcher(); $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); $kernel = new HttpKernel($dispatcher, $container, $resolver); $controller = function () use($expected) { throw $expected; }; $resolver->expects($this->once())->method('getController')->with($request)->will($this->returnValue($controller)); $resolver->expects($this->once())->method('getArguments')->with($request, $controller)->will($this->returnValue(array())); try { $kernel->handle($request, $type); $this->fail('->handle() suppresses the controller exception'); } catch (\Exception $actual) { $this->assertSame($expected, $actual, '->handle() throws the controller exception'); } }
public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() { if (version_compare(phpversion(), '5.3.3', '<')) { $this->markTestSkipped('Test fails with PHP 5.3.2 due to https://bugs.php.net/bug.php?id=50563'); } $request = new Request(); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->at(0))->method('getParameter')->with($this->equalTo('kernel.debug'))->will($this->returnValue(false)); $container->expects($this->at(1))->method('has')->with($this->equalTo('esi'))->will($this->returnValue(false)); $container->expects($this->at(2))->method('get')->with($this->equalTo('request'))->will($this->returnValue($request)); $dispatcher = new EventDispatcher(); $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () { ob_start(); echo 'bar'; throw new \RuntimeException(); })); $resolver->expects($this->once())->method('getArguments')->will($this->returnValue(array())); $kernel = new HttpKernel($dispatcher, $container, $resolver); // simulate a main request with output buffering ob_start(); echo 'Foo'; // simulate a sub-request with output buffering and an exception $kernel->render('/'); $this->assertEquals('Foo', ob_get_clean()); }
/** * @expectedException \InvalidArgumentException */ public function testRenderOnlyAllowScalarAttributes() { $dispatcher = new EventDispatcher(); $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $kernel = new HttpKernel($dispatcher, $container, $resolver); $kernel->render('/', array('attributes' => array('foo' => array('bar' => new \stdClass())))); }