This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
forked from samsonasik/expressive-composer-installer
/
HomePageHandlerTest.php
65 lines (53 loc) · 1.86 KB
/
HomePageHandlerTest.php
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
<?php
declare(strict_types=1);
namespace AppTest\Handler;
use App\Handler\HomePageHandler;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\Router\RouterInterface;
use Zend\Expressive\Template\TemplateRendererInterface;
class HomePageHandlerTest extends TestCase
{
/** @var ContainerInterface|ObjectProphecy */
protected $container;
/** @var RouterInterface|ObjectProphecy */
protected $router;
protected function setUp()
{
$this->container = $this->prophesize(ContainerInterface::class);
$this->router = $this->prophesize(RouterInterface::class);
}
public function testReturnsJsonResponseWhenNoTemplateRendererProvided()
{
$homePage = new HomePageHandler(
get_class($this->container->reveal()),
$this->router->reveal(),
null
);
$response = $homePage->handle(
$this->prophesize(ServerRequestInterface::class)->reveal()
);
$this->assertInstanceOf(JsonResponse::class, $response);
}
public function testReturnsHtmlResponseWhenTemplateRendererProvided()
{
$renderer = $this->prophesize(TemplateRendererInterface::class);
$renderer
->render('app::home-page', Argument::type('array'))
->willReturn('');
$homePage = new HomePageHandler(
get_class($this->container->reveal()),
$this->router->reveal(),
$renderer->reveal()
);
$response = $homePage->handle(
$this->prophesize(ServerRequestInterface::class)->reveal()
);
$this->assertInstanceOf(HtmlResponse::class, $response);
}
}