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

Commit a8d995f

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: [FrameworkBundle] Fix title and placeholder rendering in php form templates. 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. [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 [Console][Table] Fix cell padding with multi-byte Conflicts: src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php src/Symfony/Bundle/FrameworkBundle/composer.json src/Symfony/Component/Console/Helper/TableHelper.php
2 parents 3ab3e7f + 41890dc commit a8d995f

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
@@ -113,6 +113,9 @@ public function onKernelResponse(FilterResponseEvent $event)
113113
return;
114114
}
115115

116+
$this->dispatcher->removeListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
117+
$this->registered = false;
118+
116119
if (null !== $this->logger) {
117120
$this->logger->debug('Write SecurityContext in the session');
118121
}

Http/Tests/Firewall/ContextListenerTest.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2323
use Symfony\Component\Security\Core\SecurityContext;
2424
use Symfony\Component\Security\Http\Firewall\ContextListener;
25+
use Symfony\Component\EventDispatcher\EventDispatcher;
2526

2627
class ContextListenerTest extends \PHPUnit_Framework_TestCase
2728
{
@@ -112,7 +113,7 @@ public function testOnKernelResponseWithoutSession()
112113
new Response()
113114
);
114115

115-
$listener = new ContextListener($this->securityContext, array(), 'session');
116+
$listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
116117
$listener->onKernelResponse($event);
117118

118119
$this->assertTrue($session->isStarted());
@@ -131,7 +132,7 @@ public function testOnKernelResponseWithoutSessionNorToken()
131132
new Response()
132133
);
133134

134-
$listener = new ContextListener($this->securityContext, array(), 'session');
135+
$listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
135136
$listener->onKernelResponse($event);
136137

137138
$this->assertFalse($session->isStarted());
@@ -203,6 +204,35 @@ public function testHandleAddsKernelResponseListener()
203204
$listener->handle($event);
204205
}
205206

207+
public function testOnKernelResponseListenerRemovesItself()
208+
{
209+
$context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
210+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
211+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
212+
->disableOriginalConstructor()
213+
->getMock();
214+
215+
$listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
216+
217+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
218+
$request->expects($this->any())
219+
->method('hasSession')
220+
->will($this->returnValue(true));
221+
222+
$event->expects($this->any())
223+
->method('getRequestType')
224+
->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
225+
$event->expects($this->any())
226+
->method('getRequest')
227+
->will($this->returnValue($request));
228+
229+
$dispatcher->expects($this->once())
230+
->method('removeListener')
231+
->with(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
232+
233+
$listener->onKernelResponse($event);
234+
}
235+
206236
public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
207237
{
208238
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -241,7 +271,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
241271
new Response()
242272
);
243273

244-
$listener = new ContextListener($this->securityContext, array(), 'session');
274+
$listener = new ContextListener($this->securityContext, array(), 'session', null, new EventDispatcher());
245275
$listener->onKernelResponse($event);
246276

247277
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)