|
4 | 4 |
|
5 | 5 | namespace LightTest\Unit\Page; |
6 | 6 |
|
| 7 | +use Light\Page\Handler\PageHandler; |
7 | 8 | use Light\Page\RoutesDelegator; |
8 | 9 | use Mezzio\Application; |
| 10 | +use Mezzio\Router\Route; |
9 | 11 | use PHPUnit\Framework\MockObject\Exception; |
10 | 12 | use PHPUnit\Framework\TestCase; |
11 | 13 | use Psr\Container\ContainerInterface; |
12 | 14 |
|
| 15 | +use function sprintf; |
| 16 | + |
13 | 17 | class RoutesDelegatorTest extends TestCase |
14 | 18 | { |
15 | 19 | /** |
16 | 20 | * @throws Exception |
17 | 21 | */ |
18 | 22 | public function testWillInvoke(): void |
19 | 23 | { |
20 | | - $application = (new RoutesDelegator())( |
21 | | - $this->createMock(ContainerInterface::class), |
| 24 | + $moduleName = 'test'; |
| 25 | + $routeName = 'test_route_name'; |
| 26 | + $routeUri = sprintf('/%s/%s', $moduleName, $routeName); |
| 27 | + $templateName = sprintf('%s::%s', $moduleName, $routeName); |
| 28 | + |
| 29 | + $container = $this->createMock(ContainerInterface::class); |
| 30 | + $app = $this->createMock(Application::class); |
| 31 | + |
| 32 | + $app->method('get')->willReturn($this->createMock(Route::class)); |
| 33 | + $app |
| 34 | + ->expects($this->exactly(1)) |
| 35 | + ->method('get') |
| 36 | + ->willReturnCallback(function (...$args) use ($routeUri, $templateName) { |
| 37 | + $this->assertSame($routeUri, $args[0]); |
| 38 | + $this->assertSame([[PageHandler::class]], [$args[1]]); |
| 39 | + $this->assertSame($templateName, $args[2]); |
| 40 | + }); |
| 41 | + |
| 42 | + $container->method('get')->with('config')->willReturn([ |
| 43 | + 'routes' => [ |
| 44 | + $moduleName => [ |
| 45 | + $routeName => $routeName, |
| 46 | + ], |
| 47 | + ], |
| 48 | + ]); |
| 49 | + |
| 50 | + $application = (new RoutesDelegator())( |
| 51 | + $container, |
22 | 52 | '', |
23 | | - function () { |
24 | | - return $this->createMock(Application::class); |
| 53 | + $callback = function () use ($app) { |
| 54 | + return $app; |
25 | 55 | } |
26 | 56 | ); |
27 | 57 |
|
|
0 commit comments