Skip to content

Commit 35817a1

Browse files
Merge branch '6.0' into 6.1
* 6.0: [Console] Better required argument check in InputArgument [EventDispatcher] Fix removing listeners when using first-class callable syntax
2 parents 09e90f7 + 6548626 commit 35817a1

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Tests/Firewall/ContextListenerTest.php

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

325+
public function testOnKernelResponseRemoveListener()
326+
{
327+
$tokenStorage = new TokenStorage();
328+
$tokenStorage->setToken(new UsernamePasswordToken(new InMemoryUser('test1', 'pass1'), 'phpunit', ['ROLE_USER']));
329+
330+
$request = new Request();
331+
$request->attributes->set('_security_firewall_run', '_security_session');
332+
333+
$session = new Session(new MockArraySessionStorage());
334+
$request->setSession($session);
335+
336+
$dispatcher = new EventDispatcher();
337+
$httpKernel = $this->createMock(HttpKernelInterface::class);
338+
339+
$listener = new ContextListener($tokenStorage, [], 'session', null, $dispatcher, null, $tokenStorage->getToken(...)));
340+
$this->assertEmpty($dispatcher->getListeners());
341+
342+
$listener(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
343+
$this->assertNotEmpty($dispatcher->getListeners());
344+
345+
$listener->onKernelResponse(new ResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()));
346+
$this->assertEmpty($dispatcher->getListeners());
347+
}
348+
325349
protected function runSessionOnKernelResponse($newToken, $original = null)
326350
{
327351
$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;
@@ -179,6 +180,18 @@ public function testLogoutException()
179180
$this->assertEquals(403, $event->getThrowable()->getStatusCode());
180181
}
181182

183+
public function testUnregister()
184+
{
185+
$listener = $this->createExceptionListener();
186+
$dispatcher = new EventDispatcher();
187+
188+
$listener->register($dispatcher);
189+
$this->assertNotEmpty($dispatcher->getListeners());
190+
191+
$listener->unregister($dispatcher);
192+
$this->assertEmpty($dispatcher->getListeners());
193+
}
194+
182195
public function getAccessDeniedExceptionProvider()
183196
{
184197
return [

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"psr/log": "^1|^2|^3"
3333
},
3434
"conflict": {
35-
"symfony/event-dispatcher": "<5.4",
35+
"symfony/event-dispatcher": "<5.4.9",
3636
"symfony/security-bundle": "<5.4",
3737
"symfony/security-csrf": "<5.4"
3838
},

0 commit comments

Comments
 (0)