|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Middleware\IdleConnection; |
| 13 | + |
| 14 | +use Doctrine\DBAL\Connection as ConnectionInterface; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Listener; |
| 17 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 18 | +use Symfony\Component\HttpKernel\Event\RequestEvent; |
| 19 | + |
| 20 | +class ListenerTest extends TestCase |
| 21 | +{ |
| 22 | + public function testOnKernelRequest() |
| 23 | + { |
| 24 | + $containerMock = $this->createMock(ContainerInterface::class); |
| 25 | + $connectionExpiries = new \ArrayObject(['connectionone' => time() - 30, 'connectiontwo' => time() + 40]); |
| 26 | + |
| 27 | + $connectionOneMock = $this->getMockBuilder(ConnectionInterface::class) |
| 28 | + ->disableOriginalConstructor() |
| 29 | + ->getMock(); |
| 30 | + |
| 31 | + $containerMock->expects($this->exactly(1)) |
| 32 | + ->method('get') |
| 33 | + ->with('doctrine.dbal.connectionone_connection') |
| 34 | + ->willReturn($connectionOneMock); |
| 35 | + |
| 36 | + $listener = new Listener($connectionExpiries, $containerMock); |
| 37 | + |
| 38 | + $listener->onKernelRequest($this->createMock(RequestEvent::class)); |
| 39 | + |
| 40 | + $this->assertArrayNotHasKey('connectionone', (array) $connectionExpiries); |
| 41 | + $this->assertArrayHasKey('connectiontwo', (array) $connectionExpiries); |
| 42 | + } |
| 43 | +} |
0 commit comments