99 * file that was distributed with this source code.
1010 */
1111
12- namespace Middleware \IdleConnection ;
12+ namespace Symfony \ Bridge \ Doctrine \ Tests \ Middleware \IdleConnection ;
1313
1414use Doctrine \DBAL \Connection as ConnectionInterface ;
1515use PHPUnit \Framework \TestCase ;
1616use Symfony \Bridge \Doctrine \Middleware \IdleConnection \Listener ;
1717use Symfony \Component \DependencyInjection \ContainerInterface ;
1818use Symfony \Component \HttpKernel \Event \RequestEvent ;
19+ use Symfony \Component \HttpKernel \HttpKernelInterface ;
1920
2021class 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