|
5 | 5 | use BabDev\WebSocketBundle\CacheWarmer\RouterCacheWarmer; |
6 | 6 | use PHPUnit\Framework\MockObject\MockObject; |
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | | -use Psr\Container\ContainerInterface; |
9 | | -use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; |
| 8 | +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; |
10 | 9 | use Symfony\Component\Routing\Generator\UrlGenerator; |
11 | 10 | use Symfony\Component\Routing\Matcher\UrlMatcher; |
12 | | -use Symfony\Component\Routing\RouterInterface; |
13 | 11 |
|
14 | 12 | final class RouterCacheWarmerTest extends TestCase |
15 | 13 | { |
16 | | - public function testWarmUpWithWarmableInterface(): void |
| 14 | + public function testWarmUpWithNoBuildDir(): void |
17 | 15 | { |
18 | | - $cachePath = '/tmp/cache'; |
| 16 | + $cacheDir = '/tmp/cache'; |
| 17 | + $cacheFolder = 'websocket-router'; |
19 | 18 |
|
20 | | - /** @var MockObject&testRouterInterfaceWithWarmableInterface $router */ |
21 | | - $router = $this->createMock(testRouterInterfaceWithWarmableInterface::class); |
| 19 | + /** @var MockObject&CacheWarmerInterface $innerCacheWarmer */ |
| 20 | + $innerCacheWarmer = $this->createMock(CacheWarmerInterface::class); |
22 | 21 |
|
23 | | - $router->expects(self::once()) |
| 22 | + $innerCacheWarmer->expects(self::once()) |
24 | 23 | ->method('warmUp') |
25 | | - ->with($cachePath) |
26 | | - ->willReturn( |
27 | | - [ |
28 | | - UrlGenerator::class, |
29 | | - UrlMatcher::class, |
30 | | - ] |
31 | | - ); |
32 | | - |
33 | | - /** @var MockObject&ContainerInterface $container */ |
34 | | - $container = $this->createMock(ContainerInterface::class); |
35 | | - $container->method('get') |
36 | | - ->with('babdev_websocket_server.router') |
37 | | - ->willReturn($router); |
| 24 | + ->with(sprintf('%s/%s', $cacheDir, $cacheFolder), null) |
| 25 | + ->willReturn([ |
| 26 | + UrlGenerator::class, |
| 27 | + UrlMatcher::class, |
| 28 | + ]); |
38 | 29 |
|
39 | 30 | self::assertSame([ |
40 | 31 | UrlGenerator::class, |
41 | 32 | UrlMatcher::class, |
42 | | - ], (new RouterCacheWarmer($container, $cachePath))->warmUp('/tmp')); |
| 33 | + ], (new RouterCacheWarmer($innerCacheWarmer, $cacheFolder))->warmUp($cacheDir, null)); |
43 | 34 | } |
44 | 35 |
|
45 | | - public function testWarmUpWithoutWarmableInterface(): void |
| 36 | + public function testWarmUpWithBuildDir(): void |
46 | 37 | { |
47 | | - $this->expectException(\LogicException::class); |
| 38 | + $buildDir = '/tmp/build'; |
| 39 | + $cacheDir = '/tmp/cache'; |
| 40 | + $cacheFolder = 'websocket-router'; |
48 | 41 |
|
49 | | - /** @var MockObject&testRouterInterfaceWithoutWarmableInterface $router */ |
50 | | - $router = $this->createMock(testRouterInterfaceWithoutWarmableInterface::class); |
| 42 | + /** @var MockObject&CacheWarmerInterface $innerCacheWarmer */ |
| 43 | + $innerCacheWarmer = $this->createMock(CacheWarmerInterface::class); |
51 | 44 |
|
52 | | - /** @var MockObject&ContainerInterface $container */ |
53 | | - $container = $this->createMock(ContainerInterface::class); |
54 | | - $container->method('get') |
55 | | - ->with('babdev_websocket_server.router') |
56 | | - ->willReturn($router); |
| 45 | + $innerCacheWarmer->expects(self::once()) |
| 46 | + ->method('warmUp') |
| 47 | + ->with(sprintf('%s/%s', $cacheDir, $cacheFolder), sprintf('%s/%s', $buildDir, $cacheFolder)) |
| 48 | + ->willReturn([ |
| 49 | + UrlGenerator::class, |
| 50 | + UrlMatcher::class, |
| 51 | + ]); |
57 | 52 |
|
58 | | - (new RouterCacheWarmer($container, '/tmp/cache'))->warmUp('/tmp'); |
| 53 | + self::assertSame([ |
| 54 | + UrlGenerator::class, |
| 55 | + UrlMatcher::class, |
| 56 | + ], (new RouterCacheWarmer($innerCacheWarmer, $cacheFolder))->warmUp($cacheDir, $buildDir)); |
59 | 57 | } |
60 | 58 | } |
61 | | - |
62 | | -interface testRouterInterfaceWithWarmableInterface extends RouterInterface, WarmableInterface {} |
63 | | - |
64 | | -interface testRouterInterfaceWithoutWarmableInterface extends RouterInterface {} |
0 commit comments