Integration tests: Add lazy server helper

This allows sending requests directly in an integration test, without
having *explicitly* booted the app.
This commit is contained in:
Franz Liedke 2020-02-07 23:28:37 +01:00 committed by Alexander Skvortsov
parent 1ca610d96a
commit 23ad5bcc6b

View File

@ -16,6 +16,7 @@ use Laminas\Diactoros\CallbackStream;
use Laminas\Diactoros\ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
@ -24,11 +25,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
*/
protected $app;
/**
* @var \Psr\Http\Server\RequestHandlerInterface
*/
protected $server;
/**
* @return \Flarum\Foundation\InstalledApp
*/
@ -52,6 +48,20 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
return $this->app;
}
/**
* @var RequestHandlerInterface
*/
protected $server;
protected function server(): RequestHandlerInterface
{
if (is_null($this->server)) {
$this->server = $this->app()->getRequestHandler();
}
return $this->server;
}
protected $database;
protected function database(): ConnectionInterface
@ -103,7 +113,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
*/
protected function send(ServerRequestInterface $request): ResponseInterface
{
return $this->server->handle($request);
return $this->server()->handle($request);
}
/**