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

53 lines
1.6 KiB
PHP
Raw 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;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\Router\RouterInterface;
use Zend\Expressive\Template\TemplateRendererInterface;
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);
}
}