* initial commit
This commit is contained in:
52
test/AppTest/Handler/HomePageHandlerFactoryTest.php
Normal file
52
test/AppTest/Handler/HomePageHandlerFactoryTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace AppTest\Handler;
|
||||
|
||||
use App\Handler\HomePageHandler;
|
||||
use App\Handler\HomePageHandlerFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
use Zend\Expressive\Template\TemplateRendererInterface;
|
||||
|
||||
class HomePageHandlerFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ContainerInterface|ObjectProphecy */
|
||||
protected $container;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$router = $this->prophesize(RouterInterface::class);
|
||||
|
||||
$this->container->get(RouterInterface::class)->willReturn($router);
|
||||
}
|
||||
|
||||
public function testFactoryWithoutTemplate()
|
||||
{
|
||||
$factory = new HomePageHandlerFactory();
|
||||
$this->container->has(TemplateRendererInterface::class)->willReturn(false);
|
||||
|
||||
$this->assertInstanceOf(HomePageHandlerFactory::class, $factory);
|
||||
|
||||
$homePage = $factory($this->container->reveal(), null, get_class($this->container->reveal()));
|
||||
|
||||
$this->assertInstanceOf(HomePageHandler::class, $homePage);
|
||||
}
|
||||
|
||||
public function testFactoryWithTemplate()
|
||||
{
|
||||
$this->container->has(TemplateRendererInterface::class)->willReturn(true);
|
||||
$this->container
|
||||
->get(TemplateRendererInterface::class)
|
||||
->willReturn($this->prophesize(TemplateRendererInterface::class));
|
||||
|
||||
$factory = new HomePageHandlerFactory();
|
||||
|
||||
$homePage = $factory($this->container->reveal(), null, get_class($this->container->reveal()));
|
||||
|
||||
$this->assertInstanceOf(HomePageHandler::class, $homePage);
|
||||
}
|
||||
}
|
||||
64
test/AppTest/Handler/HomePageHandlerTest.php
Normal file
64
test/AppTest/Handler/HomePageHandlerTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace AppTest\Handler;
|
||||
|
||||
use App\Handler\HomePageHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
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(
|
||||
$this->router->reveal(),
|
||||
null,
|
||||
get_class($this->container->reveal())
|
||||
);
|
||||
$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(
|
||||
$this->router->reveal(),
|
||||
$renderer->reveal(),
|
||||
get_class($this->container->reveal())
|
||||
);
|
||||
|
||||
$response = $homePage->handle(
|
||||
$this->prophesize(ServerRequestInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(HtmlResponse::class, $response);
|
||||
}
|
||||
}
|
||||
26
test/AppTest/Handler/PingHandlerTest.php
Normal file
26
test/AppTest/Handler/PingHandlerTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace AppTest\Handler;
|
||||
|
||||
use App\Handler\PingHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PingHandlerTest extends TestCase
|
||||
{
|
||||
public function testResponse()
|
||||
{
|
||||
$pingHandler = new PingHandler();
|
||||
$response = $pingHandler->handle(
|
||||
$this->prophesize(ServerRequestInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$json = json_decode((string) $response->getBody());
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertTrue(isset($json->ack));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user