-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageHandlerTest.php
More file actions
69 lines (55 loc) · 2.06 KB
/
Copy pathPageHandlerTest.php
File metadata and controls
69 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace LightTest\Unit\Page\Handler;
use Laminas\Diactoros\Response\HtmlResponse;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Light\Page\Handler\GetPageViewHandler;
use LightTest\Unit\UnitTest;
use Mezzio\Router\RouteResult;
use Mezzio\Template\TemplateRendererInterface;
use PHPUnit\Framework\MockObject\Exception;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class PageHandlerTest extends UnitTest
{
/**
* @throws Exception
*/
public function testWillInstantiate(): void
{
$handler = $this->createStub(GetPageViewHandler::class);
$this->assertContainsOnlyInstancesOf(RequestHandlerInterface::class, [$handler]);
}
/**
* @throws Exception
*/
public function testHandle(): void
{
$routeName = 'test_route_name';
$request = $this->createStub(ServerRequestInterface::class);
$template = $this->createStub(TemplateRendererInterface::class);
$routeResult = $this->createStub(RouteResult::class);
$postRepository = $this->createStub(PostRepository::class);
$categoryRepository = $this->createStub(CategoryRepository::class);
$postRepository
->method('getRecentPosts')
->willReturn([]);
$categoryRepository
->method('getCategories')
->willReturn([]);
$routeResult
->method('getMatchedRouteName')
->willReturn($routeName);
$request
->method('getAttribute')
->willReturn($routeResult);
$template
->method('render')
->willReturn('<p>' . $routeName . '</p>');
$handler = new GetPageViewHandler($template, $categoryRepository, $postRepository);
$response = $handler->handle($request);
$this->assertInstanceOf(HtmlResponse::class, $response);
$this->assertSame('<p>' . $routeName . '</p>', $response->getBody()->getContents());
}
}