From 39018f78d9a951b039b140ab36dbcf4db6ba4786 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Tue, 21 May 2024 22:33:17 -0400 Subject: [PATCH] Add the Test harness --- app/tests/TestCase.php | 76 +++++++++++++++++++++++++++++++++++++++++ app/tests/bootstrap.php | 2 ++ 2 files changed, 78 insertions(+) create mode 100644 app/tests/TestCase.php create mode 100644 app/tests/bootstrap.php diff --git a/app/tests/TestCase.php b/app/tests/TestCase.php new file mode 100644 index 0000000..3ddbe39 --- /dev/null +++ b/app/tests/TestCase.php @@ -0,0 +1,76 @@ +build(); + $app = AppFactory::setContainer($container); + + // add middleware + + // add routes + + return $app; + } + + /** + * @param string $method + * @param string path + * @param array $headers + * @param array $cookies + * @param array $serverParams + */ + protected function createRequest( + string $method, + string $path, + array $headers = [], + array $cookies = [], + array $serverParams = [] + ): Request { + $uri = new Uri('', '', 80, $path); + $handle = fopen('php://temp', 'w+'); + $stream = (new StreamFactory())->createStreamFromResource($handle); + + $h = new Headers(); + foreach ($headers as $name => $value) { + $h->addHeader($name, $value); + } + + return new SlimRequest( + $method, + $uri, + $h, + $cookies, + $serverParams, + $stream + ); + } +} diff --git a/app/tests/bootstrap.php b/app/tests/bootstrap.php new file mode 100644 index 0000000..a4abe2d --- /dev/null +++ b/app/tests/bootstrap.php @@ -0,0 +1,2 @@ +