Skip to content

Commit 13c0d9c

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Console] Better required argument check in InputArgument [EventDispatcher] Fix removing listeners when using first-class callable syntax
2 parents 3d4b612 + f5b6fa2 commit 13c0d9c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Tests/Firewall/ContextListenerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,30 @@ public function testSessionIsNotReported()
381381
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST));
382382
}
383383

384+
public function testOnKernelResponseRemoveListener()
385+
{
386+
$tokenStorage = new TokenStorage();
387+
$tokenStorage->setToken(new UsernamePasswordToken(new InMemoryUser('test1', 'pass1'), 'phpunit', ['ROLE_USER']));
388+
389+
$request = new Request();
390+
$request->attributes->set('_security_firewall_run', '_security_session');
391+
392+
$session = new Session(new MockArraySessionStorage());
393+
$request->setSession($session);
394+
395+
$dispatcher = new EventDispatcher();
396+
$httpKernel = $this->createMock(HttpKernelInterface::class);
397+
398+
$listener = new ContextListener($tokenStorage, [], 'session', null, $dispatcher, null, \Closure::fromCallable([$tokenStorage, 'getToken']));
399+
$this->assertEmpty($dispatcher->getListeners());
400+
401+
$listener(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
402+
$this->assertNotEmpty($dispatcher->getListeners());
403+
404+
$listener->onKernelResponse(new ResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()));
405+
$this->assertEmpty($dispatcher->getListeners());
406+
}
407+
384408
protected function runSessionOnKernelResponse($newToken, $original = null)
385409
{
386410
$session = new Session(new MockArraySessionStorage());

Tests/Firewall/ExceptionListenerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\EventDispatcher\EventDispatcher;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
@@ -170,6 +171,18 @@ public function testLogoutException()
170171
$this->assertEquals(403, $event->getThrowable()->getStatusCode());
171172
}
172173

174+
public function testUnregister()
175+
{
176+
$listener = $this->createExceptionListener();
177+
$dispatcher = new EventDispatcher();
178+
179+
$listener->register($dispatcher);
180+
$this->assertNotEmpty($dispatcher->getListeners());
181+
182+
$listener->unregister($dispatcher);
183+
$this->assertEmpty($dispatcher->getListeners());
184+
}
185+
173186
public function getAccessDeniedExceptionProvider()
174187
{
175188
return [

0 commit comments

Comments
 (0)