|
| 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 Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; |
| 13 | + |
| 14 | +use Psr\Container\ContainerInterface; |
| 15 | +use Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; |
| 18 | +use Symfony\Component\Routing\RouterInterface; |
| 19 | + |
| 20 | +class RouterCacheWarmerTest extends TestCase |
| 21 | +{ |
| 22 | + public function testWarmUpWithWarmebleInterface() |
| 23 | + { |
| 24 | + $containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(array('get', 'has'))->getMock(); |
| 25 | + |
| 26 | + $routerMock = $this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'getRouteCollection', 'warmUp'))->getMock(); |
| 27 | + $containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock); |
| 28 | + $routerCacheWarmer = new RouterCacheWarmer($containerMock); |
| 29 | + |
| 30 | + $routerCacheWarmer->warmUp('/tmp'); |
| 31 | + $routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn(''); |
| 32 | + $this->addToAssertionCount(1); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @expectedDeprecation Passing a Symfony\Component\Routing\RouterInterface without implementing Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface is deprecated since 4.1. |
| 37 | + * @group legacy |
| 38 | + */ |
| 39 | + public function testWarmUpWithoutWarmebleInterface() |
| 40 | + { |
| 41 | + $containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(array('get', 'has'))->getMock(); |
| 42 | + |
| 43 | + $routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'getRouteCollection'))->getMock(); |
| 44 | + $containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock); |
| 45 | + $routerCacheWarmer = new RouterCacheWarmer($containerMock); |
| 46 | + |
| 47 | + $class = \LogicException::class; |
| 48 | + if (method_exists($this, 'expectException')) { |
| 49 | + $this->expectExceptionMessage(sprintf('%s should implement Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface in order to trigger a warmUp.', get_class($routerMock))); |
| 50 | + $this->expectException($class); |
| 51 | + } else { |
| 52 | + $this->setExpectedException($class, sprintf('%s should implement Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface in order to trigger a warmUp.', get_class($routerMock))); |
| 53 | + } |
| 54 | + |
| 55 | + $routerCacheWarmer->warmUp('/tmp'); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +interface testRouterInterfaceWithWarmebleInterface extends RouterInterface, WarmableInterface |
| 60 | +{ |
| 61 | +} |
| 62 | + |
| 63 | +interface testRouterInterfaceWithoutWarmebleInterface extends RouterInterface |
| 64 | +{ |
| 65 | +} |
0 commit comments