9
9
* file that was distributed with this source code.
10
10
*/
11
11
12
- namespace Middleware \IdleConnection ;
12
+ namespace Symfony \ Bridge \ Doctrine \ Tests \ Middleware \IdleConnection ;
13
13
14
14
use Doctrine \DBAL \Connection as ConnectionInterface ;
15
15
use PHPUnit \Framework \TestCase ;
16
16
use Symfony \Bridge \Doctrine \Middleware \IdleConnection \Listener ;
17
17
use Symfony \Component \DependencyInjection \ContainerInterface ;
18
18
use Symfony \Component \HttpKernel \Event \RequestEvent ;
19
+ use Symfony \Component \HttpKernel \HttpKernelInterface ;
19
20
20
21
class ListenerTest extends TestCase
21
22
{
@@ -34,10 +35,24 @@ public function testOnKernelRequest()
34
35
->willReturn ($ connectionOneMock );
35
36
36
37
$ listener = new Listener ($ connectionExpiries , $ containerMock );
38
+ $ event = $ this ->createMock (RequestEvent::class);
39
+ $ event ->method ('getRequestType ' )->willReturn (HttpKernelInterface::MAIN_REQUEST );
37
40
38
- $ listener ->onKernelRequest ($ this -> createMock (RequestEvent::class) );
41
+ $ listener ->onKernelRequest ($ event );
39
42
40
43
$ this ->assertArrayNotHasKey ('connectionone ' , (array ) $ connectionExpiries );
41
44
$ this ->assertArrayHasKey ('connectiontwo ' , (array ) $ connectionExpiries );
42
45
}
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
+ }
43
58
}
0 commit comments