summaryrefslogtreecommitdiffstats
path: root/Tests/Http/Firewall
diff options
context:
space:
mode:
authorDave Marshall <dave@atst.io>2015-01-20 13:50:10 +0000
committerFabien Potencier <fabien.potencier@gmail.com>2015-02-05 11:01:10 +0100
commitac536c333f676c6f55336fcfad2cb414a5a7c206 (patch)
tree2703a619e1c1bd7a7ec4e745770a3b271c4fd4e2 /Tests/Http/Firewall
parent21689b9e96aa820bcb2a2979d04685675497f736 (diff)
downloadsymfony-security-ac536c333f676c6f55336fcfad2cb414a5a7c206.zip
symfony-security-ac536c333f676c6f55336fcfad2cb414a5a7c206.tar.gz
symfony-security-ac536c333f676c6f55336fcfad2cb414a5a7c206.tar.bz2
[Security] Remove ContextListener's onKernelResponse listener as it is used
Diffstat (limited to 'Tests/Http/Firewall')
-rw-r--r--Tests/Http/Firewall/ContextListenerTest.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/Tests/Http/Firewall/ContextListenerTest.php b/Tests/Http/Firewall/ContextListenerTest.php
index f44c60a..6b4ef73 100644
--- a/Tests/Http/Firewall/ContextListenerTest.php
+++ b/Tests/Http/Firewall/ContextListenerTest.php
@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Http\Firewall\ContextListener;
+use Symfony\Component\EventDispatcher\EventDispatcher;
class ContextListenerTest extends \PHPUnit_Framework_TestCase
{
@@ -111,7 +112,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session');
+ $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertTrue($session->isStarted());
@@ -130,7 +131,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session');
+ $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
$this->assertFalse($session->isStarted());
@@ -202,6 +203,35 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($event);
}
+ public function testOnKernelResponseListenerRemovesItself()
+ {
+ $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
+
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $request->expects($this->any())
+ ->method('hasSession')
+ ->will($this->returnValue(true));
+
+ $event->expects($this->any())
+ ->method('getRequestType')
+ ->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
+ $event->expects($this->any())
+ ->method('getRequest')
+ ->will($this->returnValue($request));
+
+ $dispatcher->expects($this->once())
+ ->method('removeListener')
+ ->with(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
+
+ $listener->onKernelResponse($event);
+ }
+
public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -240,7 +270,7 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
new Response()
);
- $listener = new ContextListener($this->securityContext, array(), 'session');
+ $listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);
return $session;