1212namespace Symfony \Bundle \FrameworkBundle \Tests \CacheWarmer ;
1313
1414use PHPUnit \Framework \TestCase ;
15- use Psr \Container \ContainerInterface ;
1615use Symfony \Bundle \FrameworkBundle \CacheWarmer \RouterCacheWarmer ;
16+ use Symfony \Component \DependencyInjection \Container ;
1717use Symfony \Component \HttpKernel \CacheWarmer \WarmableInterface ;
1818use Symfony \Component \Routing \RouterInterface ;
1919
2020class RouterCacheWarmerTest extends TestCase
2121{
2222 public function testWarmUpWithWarmableInterfaceWithBuildDir ()
2323 {
24- $ containerMock = $ this -> getMockBuilder (ContainerInterface::class)-> onlyMethods ([ ' get ' , ' has ' ])-> getMock ();
24+ $ container = new Container ();
2525
2626 $ routerMock = $ this ->getMockBuilder (testRouterInterfaceWithWarmableInterface::class)->onlyMethods (['match ' , 'generate ' , 'getContext ' , 'setContext ' , 'getRouteCollection ' , 'warmUp ' ])->getMock ();
27- $ containerMock -> expects ( $ this -> any ())-> method ( ' get ' )-> with ( ' router ')-> willReturn ( $ routerMock );
28- $ routerCacheWarmer = new RouterCacheWarmer ($ containerMock );
27+ $ container -> set ( ' router ', $ routerMock );
28+ $ routerCacheWarmer = new RouterCacheWarmer ($ container );
2929
3030 $ routerCacheWarmer ->warmUp ('/tmp/cache ' , '/tmp/build ' );
3131 $ routerMock ->expects ($ this ->any ())->method ('warmUp ' )->with ('/tmp/cache ' , '/tmp/build ' )->willReturn ([]);
@@ -34,23 +34,23 @@ public function testWarmUpWithWarmableInterfaceWithBuildDir()
3434
3535 public function testWarmUpWithoutWarmableInterfaceWithBuildDir ()
3636 {
37- $ containerMock = $ this -> getMockBuilder (ContainerInterface::class)-> onlyMethods ([ ' get ' , ' has ' ])-> getMock ();
37+ $ container = new Container ();
3838
3939 $ routerMock = $ this ->getMockBuilder (testRouterInterfaceWithoutWarmableInterface::class)->onlyMethods (['match ' , 'generate ' , 'getContext ' , 'setContext ' , 'getRouteCollection ' ])->getMock ();
40- $ containerMock -> expects ( $ this -> any ())-> method ( ' get ' )-> with ( ' router ')-> willReturn ( $ routerMock );
41- $ routerCacheWarmer = new RouterCacheWarmer ($ containerMock );
40+ $ container -> set ( ' router ', $ routerMock );
41+ $ routerCacheWarmer = new RouterCacheWarmer ($ container );
4242 $ this ->expectException (\LogicException::class);
4343 $ this ->expectExceptionMessage ('cannot be warmed up because it does not implement "Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface" ' );
4444 $ routerCacheWarmer ->warmUp ('/tmp/cache ' , '/tmp/build ' );
4545 }
4646
4747 public function testWarmUpWithWarmableInterfaceWithoutBuildDir ()
4848 {
49- $ containerMock = $ this -> getMockBuilder (ContainerInterface::class)-> onlyMethods ([ ' get ' , ' has ' ])-> getMock ();
49+ $ container = new Container ();
5050
5151 $ routerMock = $ this ->getMockBuilder (testRouterInterfaceWithWarmableInterface::class)->onlyMethods (['match ' , 'generate ' , 'getContext ' , 'setContext ' , 'getRouteCollection ' , 'warmUp ' ])->getMock ();
52- $ containerMock -> expects ( $ this -> any ())-> method ( ' get ' )-> with ( ' router ')-> willReturn ( $ routerMock );
53- $ routerCacheWarmer = new RouterCacheWarmer ($ containerMock );
52+ $ container -> set ( ' router ', $ routerMock );
53+ $ routerCacheWarmer = new RouterCacheWarmer ($ container );
5454
5555 $ preload = $ routerCacheWarmer ->warmUp ('/tmp ' );
5656 $ routerMock ->expects ($ this ->never ())->method ('warmUp ' );
@@ -60,11 +60,11 @@ public function testWarmUpWithWarmableInterfaceWithoutBuildDir()
6060
6161 public function testWarmUpWithoutWarmableInterfaceWithoutBuildDir ()
6262 {
63- $ containerMock = $ this -> getMockBuilder (ContainerInterface::class)-> onlyMethods ([ ' get ' , ' has ' ])-> getMock ();
63+ $ container = new Container ();
6464
6565 $ routerMock = $ this ->getMockBuilder (testRouterInterfaceWithoutWarmableInterface::class)->onlyMethods (['match ' , 'generate ' , 'getContext ' , 'setContext ' , 'getRouteCollection ' ])->getMock ();
66- $ containerMock -> expects ( $ this -> any ())-> method ( ' get ' )-> with ( ' router ')-> willReturn ( $ routerMock );
67- $ routerCacheWarmer = new RouterCacheWarmer ($ containerMock );
66+ $ container -> set ( ' router ', $ routerMock );
67+ $ routerCacheWarmer = new RouterCacheWarmer ($ container );
6868 $ preload = $ routerCacheWarmer ->warmUp ('/tmp ' );
6969 self ::assertSame ([], $ preload );
7070 }
0 commit comments