* uplift to latest expressive

This commit is contained in:
Danyi Dávid
2017-11-06 13:18:39 +01:00
parent b5c307166e
commit 8c5b58acd1
44 changed files with 3419 additions and 1022 deletions

View File

@@ -3,11 +3,16 @@
namespace AppTest\Action;
use App\Action\HomePageAction;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
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 \PHPUnit_Framework_TestCase
class HomePageActionTest extends TestCase
{
/** @var RouterInterface */
protected $router;
@@ -17,12 +22,31 @@ class HomePageActionTest extends \PHPUnit_Framework_TestCase
$this->router = $this->prophesize(RouterInterface::class);
}
public function testResponse()
public function testReturnsJsonResponseWhenNoTemplateRendererProvided()
{
$homePage = new HomePageAction($this->router->reveal(), null);
$response = $homePage(new ServerRequest(['/']), new Response(), function () {
});
$response = $homePage->process(
$this->prophesize(ServerRequestInterface::class)->reveal(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertTrue($response instanceof Response);
$this->assertInstanceOf(JsonResponse::class, $response);
}
public function testReturnsHtmlResponseWhenTemplateRendererProvided()
{
$renderer = $this->prophesize(TemplateRendererInterface::class);
$renderer
->render('app::home-page', Argument::type('array'))
->willReturn('');
$homePage = new HomePageAction($this->router->reveal(), $renderer->reveal());
$response = $homePage->process(
$this->prophesize(ServerRequestInterface::class)->reveal(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertInstanceOf(HtmlResponse::class, $response);
}
}