gallery-api/test/AppTest/Action/HomePageActionTest.php

53 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2017-07-21 19:59:16 +02:00
<?php
namespace AppTest\Action;
2020-04-23 18:26:12 +02:00
use App\Handler\HomePage;
2017-07-21 19:59:16 +02:00
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Http\Message\ServerRequestInterface;
2020-05-01 13:46:59 +02:00
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
2017-07-21 19:59:16 +02:00
class HomePageActionTest extends TestCase
{
/** @var RouterInterface */
protected $router;
protected function setUp()
{
$this->router = $this->prophesize(RouterInterface::class);
}
public function testReturnsJsonResponseWhenNoTemplateRendererProvided()
{
2020-04-23 18:26:12 +02:00
$homePage = new HomePage($this->router->reveal(), null);
2017-07-21 19:59:16 +02:00
$response = $homePage->process(
$this->prophesize(ServerRequestInterface::class)->reveal(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertInstanceOf(JsonResponse::class, $response);
}
public function testReturnsHtmlResponseWhenTemplateRendererProvided()
{
$renderer = $this->prophesize(TemplateRendererInterface::class);
$renderer
->render('app::home-page', Argument::type('array'))
->willReturn('');
2020-04-23 18:26:12 +02:00
$homePage = new HomePage($this->router->reveal(), $renderer->reveal());
2017-07-21 19:59:16 +02:00
$response = $homePage->process(
$this->prophesize(ServerRequestInterface::class)->reveal(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertInstanceOf(HtmlResponse::class, $response);
}
}