Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 6fa94f2

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: (21 commits) [FrameworkBundle] Fix title and placeholder rendering in php form templates. [TwigBridge] Removed duplicated code from TwigRenderer [Translator][Logging] implement TranslatorBagInterface. RequestDataCollector - small fix renamed composer.phar to composer to be consistent with the Symfony docs [FrameworkBundle] bumped min version of Routing to 2.3 removed composer --dev option everywhere fixed a test [Console] Fixed output bug, if escaped string in a formatted string. “console help” ignores --raw option Fix form icon position in web profiler [Security] Remove ContextListener's onKernelResponse listener as it is used Revert "minor #12652 [HttpFoundation] [Hackday] #9942 test: Request::getContent() for null value (skler)" Revert "fixed assertion" fixed assertion [HttpFoundation] [Hackday] #9942 test: Request::getContent() for null value fixed URL Add reference to documentation in FormEvents phpdocs [YAML] Fix one-liners to work with multiple new lines Keep "pre" meaning for var_dump quick-and-dirty debug ... Conflicts: src/Symfony/Bridge/Twig/composer.json src/Symfony/Bundle/FrameworkBundle/composer.json src/Symfony/Component/Security/Http/Firewall/ContextListener.php src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
2 parents 7efc950 + a8d995f commit 6fa94f2

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

Http/Firewall/ContextListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public function onKernelResponse(FilterResponseEvent $event)
115115
return;
116116
}
117117

118+
$this->dispatcher->removeListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
119+
$this->registered = false;
120+
118121
$request = $event->getRequest();
119122
$session = $request->getSession();
120123

Http/Tests/Firewall/ContextListenerTest.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
2222
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2323
use Symfony\Component\Security\Http\Firewall\ContextListener;
24+
use Symfony\Component\EventDispatcher\EventDispatcher;
2425

2526
class ContextListenerTest extends \PHPUnit_Framework_TestCase
2627
{
@@ -99,7 +100,7 @@ public function testOnKernelResponseWithoutSession()
99100
new Response()
100101
);
101102

102-
$listener = new ContextListener($tokenStorage, array(), 'session');
103+
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
103104
$listener->onKernelResponse($event);
104105

105106
$this->assertTrue($session->isStarted());
@@ -118,7 +119,7 @@ public function testOnKernelResponseWithoutSessionNorToken()
118119
new Response()
119120
);
120121

121-
$listener = new ContextListener(new TokenStorage(), array(), 'session');
122+
$listener = new ContextListener(new TokenStorage(), array(), 'session', null, new EventDispatcher());
122123
$listener->onKernelResponse($event);
123124

124125
$this->assertFalse($session->isStarted());
@@ -190,6 +191,35 @@ public function testHandleAddsKernelResponseListener()
190191
$listener->handle($event);
191192
}
192193

194+
public function testOnKernelResponseListenerRemovesItself()
195+
{
196+
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
197+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
198+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
199+
->disableOriginalConstructor()
200+
->getMock();
201+
202+
$listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
203+
204+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
205+
$request->expects($this->any())
206+
->method('hasSession')
207+
->will($this->returnValue(true));
208+
209+
$event->expects($this->any())
210+
->method('isMasterRequest')
211+
->will($this->returnValue(true));
212+
$event->expects($this->any())
213+
->method('getRequest')
214+
->will($this->returnValue($request));
215+
216+
$dispatcher->expects($this->once())
217+
->method('removeListener')
218+
->with(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
219+
220+
$listener->onKernelResponse($event);
221+
}
222+
193223
public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
194224
{
195225
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -229,7 +259,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
229259
new Response()
230260
);
231261

232-
$listener = new ContextListener($tokenStorage, array(), 'session');
262+
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
233263
$listener->onKernelResponse($event);
234264

235265
return $session;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ Tests
1919
You can run the unit tests with the following command:
2020

2121
$ cd path/to/Symfony/Component/Security/
22-
$ composer.phar install
22+
$ composer install
2323
$ phpunit

0 commit comments

Comments
 (0)