Skip to content

Commit a2cbc12

Browse files
Merge branch '7.2' into 7.3
* 7.2: [DoctrineBridge] Prevent idle connection listener from running on subrequests [Routing] Add test to validate that default value is allowed to not match requirement fix handling required options Fix @var phpdoc [Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority [FrameworkBundle] fix phpdoc in `MicroKernelTrait` Fixed validator translations for Albanian
2 parents f112b30 + ef8b215 commit a2cbc12

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Middleware/IdleConnection/Listener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1616
use Symfony\Component\HttpKernel\Event\RequestEvent;
17+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718
use Symfony\Component\HttpKernel\KernelEvents;
1819

1920
final class Listener implements EventSubscriberInterface
@@ -29,6 +30,9 @@ public function __construct(
2930

3031
public function onKernelRequest(RequestEvent $event): void
3132
{
33+
if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) {
34+
return;
35+
}
3236
$timestamp = time();
3337

3438
foreach ($this->connectionExpiries as $name => $expiry) {

Tests/Middleware/IdleConnection/ListenerTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Middleware\IdleConnection;
12+
namespace Symfony\Bridge\Doctrine\Tests\Middleware\IdleConnection;
1313

1414
use Doctrine\DBAL\Connection as ConnectionInterface;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Listener;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
1818
use Symfony\Component\HttpKernel\Event\RequestEvent;
19+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1920

2021
class ListenerTest extends TestCase
2122
{
@@ -34,10 +35,24 @@ public function testOnKernelRequest()
3435
->willReturn($connectionOneMock);
3536

3637
$listener = new Listener($connectionExpiries, $containerMock);
38+
$event = $this->createMock(RequestEvent::class);
39+
$event->method('getRequestType')->willReturn(HttpKernelInterface::MAIN_REQUEST);
3740

38-
$listener->onKernelRequest($this->createMock(RequestEvent::class));
41+
$listener->onKernelRequest($event);
3942

4043
$this->assertArrayNotHasKey('connectionone', (array) $connectionExpiries);
4144
$this->assertArrayHasKey('connectiontwo', (array) $connectionExpiries);
4245
}
46+
47+
public function testOnKernelRequestShouldSkipSubrequests()
48+
{
49+
self::expectNotToPerformAssertions();
50+
$arrayObj = $this->createMock(\ArrayObject::class);
51+
$arrayObj->method('getIterator')->willThrowException(new \Exception('Invalid behavior'));
52+
$listener = new Listener($arrayObj, $this->createMock(ContainerInterface::class));
53+
54+
$event = $this->createMock(RequestEvent::class);
55+
$event->method('getRequestType')->willReturn(HttpKernelInterface::SUB_REQUEST);
56+
$listener->onKernelRequest($event);
57+
}
4358
}

0 commit comments

Comments
 (0)