@@ -652,6 +652,66 @@ public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself()
652652 $ kernel ->initializeBundles ();
653653 }
654654
655+ public function testTerminateReturnsSilentlyIfKernelIsNotBooted ()
656+ {
657+ $ kernel = $ this ->getMockBuilder ('Symfony\Tests\Component\HttpKernel\KernelForTest ' )
658+ ->disableOriginalConstructor ()
659+ ->setMethods (array ('getHttpKernel ' ))
660+ ->getMock ();
661+
662+ $ kernel ->expects ($ this ->never ())
663+ ->method ('getHttpKernel ' );
664+
665+ $ kernel ->setIsBooted (false );
666+ $ kernel ->terminate ();
667+ }
668+
669+ public function testTerminateDelegatesTerminationOnlyForTerminableInterface ()
670+ {
671+ // does not implement TerminableInterface
672+ $ httpKernelMock = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernelInterface ' )
673+ ->disableOriginalConstructor ()
674+ ->getMock ();
675+
676+ $ httpKernelMock
677+ ->expects ($ this ->never ())
678+ ->method ('terminate ' );
679+
680+ $ kernel = $ this ->getMockBuilder ('Symfony\Tests\Component\HttpKernel\KernelForTest ' )
681+ ->disableOriginalConstructor ()
682+ ->setMethods (array ('getHttpKernel ' ))
683+ ->getMock ();
684+
685+ $ kernel ->expects ($ this ->once ())
686+ ->method ('getHttpKernel ' )
687+ ->will ($ this ->returnValue ($ httpKernelMock ));
688+
689+ $ kernel ->setIsBooted (true );
690+ $ kernel ->terminate ();
691+
692+ // implements TerminableInterface
693+ $ httpKernelMock = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernel ' )
694+ ->disableOriginalConstructor ()
695+ ->setMethods (array ('terminate ' ))
696+ ->getMock ();
697+
698+ $ httpKernelMock
699+ ->expects ($ this ->once ())
700+ ->method ('terminate ' );
701+
702+ $ kernel = $ this ->getMockBuilder ('Symfony\Tests\Component\HttpKernel\KernelForTest ' )
703+ ->disableOriginalConstructor ()
704+ ->setMethods (array ('getHttpKernel ' ))
705+ ->getMock ();
706+
707+ $ kernel ->expects ($ this ->exactly (2 ))
708+ ->method ('getHttpKernel ' )
709+ ->will ($ this ->returnValue ($ httpKernelMock ));
710+
711+ $ kernel ->setIsBooted (true );
712+ $ kernel ->terminate ();
713+ }
714+
655715 protected function getBundle ($ dir = null , $ parent = null , $ className = null , $ bundleName = null )
656716 {
657717 $ bundle = $ this
0 commit comments