67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace AppTest\Handler;
|
|
|
|
use App\Handler\HomePageHandler;
|
|
use Laminas\Diactoros\Response\HtmlResponse;
|
|
use Laminas\Diactoros\Response\JsonResponse;
|
|
use Mezzio\Router\RouterInterface;
|
|
use Mezzio\Template\TemplateRendererInterface;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Container\ContainerInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
class HomePageHandlerTest extends TestCase
|
|
{
|
|
/** @var ContainerInterface&MockObject */
|
|
protected $container;
|
|
|
|
/** @var RouterInterface&MockObject */
|
|
protected $router;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->container = $this->createMock(ContainerInterface::class);
|
|
$this->router = $this->createMock(RouterInterface::class);
|
|
}
|
|
|
|
public function testReturnsJsonResponseWhenNoTemplateRendererProvided(): void
|
|
{
|
|
$homePage = new HomePageHandler(
|
|
$this->container::class,
|
|
$this->router,
|
|
null
|
|
);
|
|
$response = $homePage->handle(
|
|
$this->createMock(ServerRequestInterface::class)
|
|
);
|
|
|
|
self::assertInstanceOf(JsonResponse::class, $response);
|
|
}
|
|
|
|
public function testReturnsHtmlResponseWhenTemplateRendererProvided(): void
|
|
{
|
|
$renderer = $this->createMock(TemplateRendererInterface::class);
|
|
$renderer
|
|
->expects($this->once())
|
|
->method('render')
|
|
->with('app::home-page', $this->isType('array'))
|
|
->willReturn('');
|
|
|
|
$homePage = new HomePageHandler(
|
|
$this->container::class,
|
|
$this->router,
|
|
$renderer
|
|
);
|
|
|
|
$response = $homePage->handle(
|
|
$this->createMock(ServerRequestInterface::class)
|
|
);
|
|
|
|
self::assertInstanceOf(HtmlResponse::class, $response);
|
|
}
|
|
}
|