From 23ad5bcc6b0f8159686808bc24f5f4d241aca240 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 7 Feb 2020 23:28:37 +0100 Subject: [PATCH] Integration tests: Add lazy server helper This allows sending requests directly in an integration test, without having *explicitly* booted the app. --- .../testing/tests/integration/TestCase.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/php-packages/testing/tests/integration/TestCase.php b/php-packages/testing/tests/integration/TestCase.php index 31d14199a..cdb3fdc9a 100644 --- a/php-packages/testing/tests/integration/TestCase.php +++ b/php-packages/testing/tests/integration/TestCase.php @@ -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); } /**