Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge branch '2.6' into 2.7
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fabpot committed Feb 11, 2015
2 parents 7efc950 + a8d995f commit 6fa94f2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Http/Firewall/ContextListener.php
Expand Up @@ -115,6 +115,9 @@ public function onKernelResponse(FilterResponseEvent $event)
return;
}

$this->dispatcher->removeListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
$this->registered = false;

$request = $event->getRequest();
$session = $request->getSession();

Expand Down
36 changes: 33 additions & 3 deletions Http/Tests/Firewall/ContextListenerTest.php
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Firewall\ContextListener;
use Symfony\Component\EventDispatcher\EventDispatcher;

class ContextListenerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public function testOnKernelResponseWithoutSession()
new Response()
);

$listener = new ContextListener($tokenStorage, array(), 'session');
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);

$this->assertTrue($session->isStarted());
Expand All @@ -118,7 +119,7 @@ public function testOnKernelResponseWithoutSessionNorToken()
new Response()
);

$listener = new ContextListener(new TokenStorage(), array(), 'session');
$listener = new ContextListener(new TokenStorage(), array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);

$this->assertFalse($session->isStarted());
Expand Down Expand Up @@ -190,6 +191,35 @@ public function testHandleAddsKernelResponseListener()
$listener->handle($event);
}

public function testOnKernelResponseListenerRemovesItself()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
->disableOriginalConstructor()
->getMock();

$listener = new ContextListener($tokenStorage, 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('isMasterRequest')
->will($this->returnValue(true));
$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');
Expand Down Expand Up @@ -229,7 +259,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
new Response()
);

$listener = new ContextListener($tokenStorage, array(), 'session');
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
$listener->onKernelResponse($event);

return $session;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,5 +19,5 @@ Tests
You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/Security/
$ composer.phar install
$ composer install
$ phpunit

0 comments on commit 6fa94f2

Please sign in to comment.