From b33f5aa66514d05706f024342c4fc23c1f623c32 Mon Sep 17 00:00:00 2001 From: Rougin Gutib Date: Tue, 26 Dec 2023 16:12:41 +0800 Subject: [PATCH] Improve type hinting in unit tests --- src/Routing/FastRouteRouter.php | 2 +- src/Routing/PhrouteRouter.php | 2 +- src/Routing/Router.php | 2 +- tests/Application/ApplicationTestCases.php | 2 +- tests/Component/CollectionTest.php | 1 + tests/Component/Server.php | 2 + tests/Container/ReflectionContainerTest.php | 3 +- .../Dispatching/FastRoute/DispatcherTest.php | 65 ++++++++++--------- tests/Dispatching/Phroute/DispatcherTest.php | 50 +++++++------- tests/Dispatching/Vanilla/DispatcherTest.php | 43 +++++++----- tests/Dispatching/Vanilla/RouterTest.php | 3 +- tests/Fixture/Classes/Container.php | 24 ++----- .../Classes/WithMultipleParameters.php | 16 ++--- tests/Fixture/Components/HttpComponent.php | 41 +++++------- .../Middlewares/BodyParametersMiddleware.php | 13 +++- tests/Fixture/Middlewares/CorsMiddleware.php | 11 ++++ tests/Fixture/Middlewares/EmptyMiddleware.php | 12 ++++ tests/Fixture/Middlewares/FinalMiddleware.php | 6 ++ tests/Fixture/Middlewares/FirstMiddleware.php | 7 ++ .../Fixture/Middlewares/InteropMiddleware.php | 7 +- tests/Fixture/Middlewares/LastMiddleware.php | 6 ++ .../Fixture/Middlewares/SecondMiddleware.php | 7 ++ tests/Previous/Server.php | 2 + tests/Sample/Server.php | 2 + 24 files changed, 198 insertions(+), 131 deletions(-) diff --git a/src/Routing/FastRouteRouter.php b/src/Routing/FastRouteRouter.php index 76e51791..8bf34300 100644 --- a/src/Routing/FastRouteRouter.php +++ b/src/Routing/FastRouteRouter.php @@ -26,7 +26,7 @@ class FastRouteRouter extends Router /** * Initializes the router instance. * - * @param array> $routes + * @param array> $routes */ public function __construct(array $routes = array()) { diff --git a/src/Routing/PhrouteRouter.php b/src/Routing/PhrouteRouter.php index 5ef442be..f6def3e4 100644 --- a/src/Routing/PhrouteRouter.php +++ b/src/Routing/PhrouteRouter.php @@ -24,7 +24,7 @@ class PhrouteRouter extends Router /** * Initializes the router instance. * - * @param array> $routes + * @param array> $routes */ public function __construct(array $routes = array()) { diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 39037254..397e91bb 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -30,7 +30,7 @@ class Router implements RouterInterface /** * Initializes the router instance. * - * @param array> $routes + * @param array> $routes */ public function __construct(array $routes = array()) { diff --git a/tests/Application/ApplicationTestCases.php b/tests/Application/ApplicationTestCases.php index 02c334cf..4b79cdd5 100644 --- a/tests/Application/ApplicationTestCases.php +++ b/tests/Application/ApplicationTestCases.php @@ -15,7 +15,7 @@ class ApplicationTestCases extends Testcase { /** - * @var \Rougin\Slytherin\Application + * @var \Rougin\Slytherin\System */ protected $application; diff --git a/tests/Component/CollectionTest.php b/tests/Component/CollectionTest.php index 23277dc0..7af72f9d 100644 --- a/tests/Component/CollectionTest.php +++ b/tests/Component/CollectionTest.php @@ -218,6 +218,7 @@ public function testSetTemplateMethod() $this->markTestSkipped('Twig is not installed.'); } + /** @var string */ $path = realpath(__DIR__ . '/../../Fixture/Templates'); $environment = $twig->load($path); diff --git a/tests/Component/Server.php b/tests/Component/Server.php index 8cbe4a13..b55b0be6 100644 --- a/tests/Component/Server.php +++ b/tests/Component/Server.php @@ -1,5 +1,6 @@ run(); +// @codeCoverageIgnoreEnd \ No newline at end of file diff --git a/tests/Container/ReflectionContainerTest.php b/tests/Container/ReflectionContainerTest.php index 17086d20..ff9d9d45 100644 --- a/tests/Container/ReflectionContainerTest.php +++ b/tests/Container/ReflectionContainerTest.php @@ -15,7 +15,7 @@ class ReflectionContainerTest extends Testcase { /** - * @var \Rougin\Slytherin\Container\ContainerInterface + * @var \Psr\Container\ContainerInterface */ protected $container; @@ -66,6 +66,7 @@ public function testGetMethodWithMultipleParameters() $expected = 'With multiple parameters'; + /** @var \Rougin\Slytherin\Fixture\Classes\ParameterClass */ $object = $this->container->get($class); $this->assertEquals($expected, $object->index()); diff --git a/tests/Dispatching/FastRoute/DispatcherTest.php b/tests/Dispatching/FastRoute/DispatcherTest.php index 52f462c8..0715ec3a 100644 --- a/tests/Dispatching/FastRoute/DispatcherTest.php +++ b/tests/Dispatching/FastRoute/DispatcherTest.php @@ -2,6 +2,7 @@ namespace Rougin\Slytherin\Dispatching\FastRoute; +use Rougin\Slytherin\Dispatching\Vanilla\Router as Vanilla; use Rougin\Slytherin\Fixture\Classes\NewClass; use Rougin\Slytherin\Routing\Route; use Rougin\Slytherin\Testcase; @@ -15,7 +16,7 @@ class DispatcherTest extends Testcase { /** - * @var \Rougin\Slytherin\Dispatching\DispatcherInterface + * @var \Rougin\Slytherin\Routing\DispatcherInterface */ protected $dispatcher; @@ -26,30 +27,21 @@ class DispatcherTest extends Testcase */ protected function doSetUp() { - if (! interface_exists('FastRoute\Dispatcher')) { + if (! interface_exists('FastRoute\Dispatcher')) + { $this->markTestSkipped('FastRoute is not installed.'); } - $routes = array( - array( - 'GET', - '/', - array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index'), - 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware' - ), - array('GET', '/hi', function () { - return 'Hi'; - }), - array('TEST', '/hello', function () { - return 'It must not go through here'; - }), - ); - - $router = new \Rougin\Slytherin\Dispatching\FastRoute\Router($routes); - - $dispatcher = new \Rougin\Slytherin\Dispatching\FastRoute\Dispatcher($router); - - $this->dispatcher = $dispatcher; + $middleware = 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware'; + + $routes = array(); + $routes[] = array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index'), $middleware); + $routes[] = array('GET', '/hi', function () { return 'Hi'; }); + $routes[] = array('TEST', '/hello', function () { return 'It must not go through here'; }); + + $router = new Router($routes); + + $this->dispatcher = new Dispatcher($router); } /** @@ -65,11 +57,17 @@ public function testDispatchMethod() $route = $this->dispatcher->dispatch('GET', '/'); - list($class, $method) = $route->getHandler(); + /** @var string */ + $handler = $route->getHandler(); + + $class = $handler[0]; $method = $handler[1]; + $params = (array) $route->getParams(); + + /** @var callable */ $object = array(new $class, $method); - $actual = call_user_func_array($object, $route->getParams()); + $actual = call_user_func_array($object, $params); $this->assertEquals($expected, $actual); } @@ -83,11 +81,12 @@ public function testDispatchMethodWithClosure() { $route = $this->dispatcher->dispatch('GET', '/hi'); + /** @var callable */ $callback = $route->getHandler(); - $parameters = $route->getParams(); + $params = $route->getParams(); - $actual = call_user_func($callback, $parameters); + $actual = call_user_func($callback, $params); $this->assertEquals('Hi', $actual); } @@ -147,14 +146,18 @@ public function testDispatcherInterface() */ public function testDispatchMethodWithDifferentRouter() { - $routes = array(array('GET', '/', 'Rougin\Slytherin\Fixture\Classes\NewClass@index', 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware')); + $middleware = 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware'; + + $routes = array(array('GET', '/', 'Rougin\Slytherin\Fixture\Classes\NewClass@index', $middleware)); - $router = new \Rougin\Slytherin\Dispatching\Vanilla\Router($routes); + $router = new Vanilla($routes); - $dispatcher = new \Rougin\Slytherin\Dispatching\FastRoute\Dispatcher($router); + $dispatcher = new Dispatcher($router); - $expected = new Route('GET', '/', 'Rougin\Slytherin\Fixture\Classes\NewClass@index', 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware'); + $expected = new Route('GET', '/', 'Rougin\Slytherin\Fixture\Classes\NewClass@index', $middleware); - $this->assertEquals($expected, $dispatcher->dispatch('GET', '/')); + $actual = $dispatcher->dispatch('GET', '/'); + + $this->assertEquals($expected, $actual); } } diff --git a/tests/Dispatching/Phroute/DispatcherTest.php b/tests/Dispatching/Phroute/DispatcherTest.php index f64c6ec1..a159d3c6 100644 --- a/tests/Dispatching/Phroute/DispatcherTest.php +++ b/tests/Dispatching/Phroute/DispatcherTest.php @@ -2,10 +2,8 @@ namespace Rougin\Slytherin\Dispatching\Phroute; -use Rougin\Slytherin\Container\Container; use Rougin\Slytherin\Dispatching\Vanilla\Router as Vanilla; use Rougin\Slytherin\Fixture\Classes\NewClass; -use Rougin\Slytherin\Routing\PhrouteResolver; use Rougin\Slytherin\Testcase; /** @@ -17,12 +15,12 @@ class DispatcherTest extends Testcase { /** - * @var \Rougin\Slytherin\Dispatching\DispatcherInterface + * @var \Rougin\Slytherin\Routing\DispatcherInterface */ protected $dispatcher; /** - * @var array + * @var array> */ protected $routes = array(); @@ -38,21 +36,16 @@ protected function doSetUp() $this->markTestSkipped('Phroute is not installed.'); } - $this->routes = array( - array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index')), - array('GET', '/hi', function () { - return 'Hi'; - }), - array('TEST', '/hello', function () { - return 'It must not go through here'; - }), - ); + $routes = array(); + $routes[] = array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index')); + $routes[] = array('GET', '/hi', function () { return 'Hi'; }); + $routes[] = array('TEST', '/hello', function () { return 'It must not go through here'; }); - $router = new Router($this->routes); + $this->routes = $routes; - $dispatcher = new Dispatcher($router); + $router = new Router($routes); - $this->dispatcher = $dispatcher; + $this->dispatcher = new Dispatcher($router); } /** @@ -68,11 +61,17 @@ public function testDispatchMethod() $route = $this->dispatcher->dispatch('GET', '/'); - list($class, $method) = $route->getHandler(); + /** @var string */ + $handler = $route->getHandler(); + + $class = $handler[0]; $method = $handler[1]; + + $params = (array) $route->getParams(); + /** @var callable */ $object = array(new $class, $method); - $actual = call_user_func_array($object, $route->getParams()); + $actual = call_user_func_array($object, $params); $this->assertEquals($expected, $actual); } @@ -86,11 +85,12 @@ public function testDispatchMethodWithClosure() { $route = $this->dispatcher->dispatch('GET', '/hi'); + /** @var callable */ $callback = $route->getHandler(); - $parameters = $route->getParams(); + $params = $route->getParams(); - $actual = call_user_func($callback, $parameters); + $actual = call_user_func($callback, $params); $this->assertEquals('Hi', $actual); } @@ -148,11 +148,17 @@ public function testDispatchMethodWithDifferentRouter() $route = $dispatcher->dispatch('GET', '/'); - list($class, $method) = $route->getHandler(); + /** @var string */ + $handler = $route->getHandler(); + + $class = $handler[0]; $method = $handler[1]; + + $params = (array) $route->getParams(); + /** @var callable */ $object = array(new $class, $method); - $actual = call_user_func_array($object, $route->getParams()); + $actual = call_user_func_array($object, $params); $this->assertEquals($expected, $actual); } diff --git a/tests/Dispatching/Vanilla/DispatcherTest.php b/tests/Dispatching/Vanilla/DispatcherTest.php index f45f6afa..2c35a74a 100644 --- a/tests/Dispatching/Vanilla/DispatcherTest.php +++ b/tests/Dispatching/Vanilla/DispatcherTest.php @@ -14,7 +14,7 @@ class DispatcherTest extends Testcase { /** - * @var \Rougin\Slytherin\Dispatching\DispatcherInterface + * @var \Rougin\Slytherin\Routing\DispatcherInterface */ protected $dispatcher; @@ -25,16 +25,12 @@ class DispatcherTest extends Testcase */ protected function doSetUp() { - $routes = array( - array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index')), - array('POST', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'store')), - array('GET', '/hi', function () { - return 'Hi'; - }), - array('TEST', '/hello', function () { - return 'It must not go through here'; - }), - ); + $routes = array(); + + $routes[] = array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index')); + $routes[] = array('POST', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'store')); + $routes[] = array('GET', '/hi', function () { return 'Hi'; }); + $routes[] = array('TEST', '/hello', function () { return 'It must not go through here'; }); $router = new Router($routes); @@ -56,11 +52,17 @@ public function testDispatchMethodWithClass() $route = $this->dispatcher->dispatch('GET', '/'); - list($class, $method) = $route->getHandler(); + /** @var string */ + $handler = $route->getHandler(); + + $class = $handler[0]; $method = $handler[1]; + + $params = (array) $route->getParams(); + /** @var callable */ $object = array(new $class, $method); - $actual = call_user_func_array($object, $route->getParams()); + $actual = call_user_func_array($object, $params); $this->assertEquals($expected, $actual); } @@ -78,11 +80,17 @@ public function testDispatchMethodWithClassAndPostMethod() $route = $this->dispatcher->dispatch('POST', '/'); - list($class, $method) = $route->getHandler(); + /** @var string */ + $handler = $route->getHandler(); + + $class = $handler[0]; $method = $handler[1]; + + $params = (array) $route->getParams(); + /** @var callable */ $object = array(new $class, $method); - $actual = call_user_func_array($object, $route->getParams()); + $actual = call_user_func_array($object, $params); $this->assertEquals($expected, $actual); } @@ -96,11 +104,12 @@ public function testDispatchMethodWithClosure() { $route = $this->dispatcher->dispatch('GET', '/hi'); + /** @var callable */ $callback = $route->getHandler(); - $parameters = $route->getParams(); + $params = $route->getParams(); - $actual = call_user_func($callback, $parameters); + $actual = call_user_func($callback, $params); $this->assertEquals('Hi', $actual); } diff --git a/tests/Dispatching/Vanilla/RouterTest.php b/tests/Dispatching/Vanilla/RouterTest.php index 9e0af086..30156ae9 100644 --- a/tests/Dispatching/Vanilla/RouterTest.php +++ b/tests/Dispatching/Vanilla/RouterTest.php @@ -13,7 +13,7 @@ class RouterTest extends \Rougin\Slytherin\Testcase { /** - * @var \Rougin\Slytherin\Dispatching\Router + * @var \Rougin\Slytherin\Routing\Router */ protected $router; @@ -111,6 +111,7 @@ public function testSetPrefixMethod() $expected = '/v1/slytherin/'; + /** @var \Rougin\Slytherin\Routing\RouteInterface */ $route = $this->router->getRoute($route->getMethod(), $expected); $actual = $route->getUri(); diff --git a/tests/Fixture/Classes/Container.php b/tests/Fixture/Classes/Container.php index a290dc61..ed94d25b 100644 --- a/tests/Fixture/Classes/Container.php +++ b/tests/Fixture/Classes/Container.php @@ -2,37 +2,21 @@ namespace Rougin\Slytherin\Fixture\Classes; +use Psr\Container\ContainerInterface; + /** * Container * * @package Slytherin * @author Rougin Gutib */ -class Container implements \Psr\Container\ContainerInterface, \Rougin\Slytherin\Container\DelegateInterface +class Container implements ContainerInterface { /** - * @var \Psr\Container\ContainerInterface - */ - protected $delegate; - - /** - * @var array + * @var array */ protected $instances = array(); - /** - * Delegate a container to be checked for services. - * - * @param \Psr\Container\ContainerInterface $container - * @return self - */ - public function delegate(PsrContainerInterface $container) - { - $this->delegate = $container; - - return $this; - } - /** * Finds an entry of the container by its identifier and returns it. * diff --git a/tests/Fixture/Classes/WithMultipleParameters.php b/tests/Fixture/Classes/WithMultipleParameters.php index 916e806a..b990c978 100644 --- a/tests/Fixture/Classes/WithMultipleParameters.php +++ b/tests/Fixture/Classes/WithMultipleParameters.php @@ -11,30 +11,30 @@ class WithMultipleParameters { /** - * @var array + * @var array */ protected $data = array(); /** - * @var array + * @var array */ protected $fields = array(); /** - * @var null + * @var string|null */ protected $lang = null; /** - * @var null + * @var string|null */ protected $dir = null; /** - * @param array $data - * @param array $fields - * @param string|null $lang - * @param string|null $dir + * @param array $data + * @param array $fields + * @param string|null $lang + * @param string|null $dir */ public function __construct($data = array(), $fields = array(), $lang = null, $dir = null) { diff --git a/tests/Fixture/Components/HttpComponent.php b/tests/Fixture/Components/HttpComponent.php index cf3ca909..67e10a2d 100644 --- a/tests/Fixture/Components/HttpComponent.php +++ b/tests/Fixture/Components/HttpComponent.php @@ -3,6 +3,9 @@ namespace Rougin\Slytherin\Fixture\Components; use Rougin\Slytherin\Component\AbstractComponent; +use Rougin\Slytherin\Http\Response; +use Rougin\Slytherin\Http\ServerRequest; +use Rougin\Slytherin\System; /** * HTTP Component @@ -39,34 +42,22 @@ class HttpComponent extends AbstractComponent public function get() { $slash = DIRECTORY_SEPARATOR; - $root = str_replace($slash . 'tests' . $slash . 'Fixture' . $slash . 'Components', '', __DIR__); - $server = array( - 'DOCUMENT_ROOT' => $root, - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_FILENAME' => '/var/www/html/slytherin/index.php', - 'SCRIPT_NAME' => '/slytherin/index.php', - 'SERVER_NAME' => 'localhost', - 'SERVER_PORT' => '8000', - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'GET', - ); + $root = str_replace($slash . 'tests' . $slash . 'Fixture' . $slash . 'Components', '', __DIR__); - $this->request = new \Rougin\Slytherin\Http\ServerRequest($server); - $this->response = new \Rougin\Slytherin\Http\Response; + $server = array('REQUEST_URI' => '/'); + $server['DOCUMENT_ROOT'] = $root; + $server['REMOTE_ADDR'] = '127.0.0.1'; + $server['SCRIPT_FILENAME'] = '/var/www/html/slytherin/index.php'; + $server['SCRIPT_NAME'] = '/slytherin/index.php'; + $server['SERVER_NAME'] = 'localhost'; + $server['SERVER_PORT'] = '8000'; + $server['REQUEST_METHOD'] = 'GET'; - return array($this->request, $this->response); - } + $this->request = new ServerRequest($server); - /** - * Sets the component. Can also add it to the container. - * - * @param \Psr\Container\ContainerInterface $container - * @return void - */ - public function set(\Psr\Container\ContainerInterface &$container) - { - $container->add('Psr\Http\Message\ServerRequestInterface', $this->request); - $container->add('Psr\Http\Message\ResponseInterface', $this->response); + $this->response = new Response; + + return array($this->request, $this->response); } } diff --git a/tests/Fixture/Middlewares/BodyParametersMiddleware.php b/tests/Fixture/Middlewares/BodyParametersMiddleware.php index 35281a6c..3983b326 100644 --- a/tests/Fixture/Middlewares/BodyParametersMiddleware.php +++ b/tests/Fixture/Middlewares/BodyParametersMiddleware.php @@ -12,8 +12,16 @@ */ class BodyParametersMiddleware implements MiddlewareInterface { + /** + * @var string[] + */ protected $complex = array('PUT', 'DELETE'); + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler + * @return \Psr\Http\Message\ResponseInterface + */ public function process(ServerRequestInterface $request, HandlerInterface $handler) { if (! in_array($request->getMethod(), $this->complex)) @@ -21,10 +29,13 @@ public function process(ServerRequestInterface $request, HandlerInterface $handl return $handler->handle($request); } + /** @var string */ $file = file_get_contents('php://input'); parse_str($file, $body); - return $request->withParsedBody($body); + $request = $request->withParsedBody($body); + + return $handler->handle($request); } } diff --git a/tests/Fixture/Middlewares/CorsMiddleware.php b/tests/Fixture/Middlewares/CorsMiddleware.php index dbd1c157..7ee0e677 100644 --- a/tests/Fixture/Middlewares/CorsMiddleware.php +++ b/tests/Fixture/Middlewares/CorsMiddleware.php @@ -13,10 +13,21 @@ */ class CorsMiddleware implements MiddlewareInterface { + /** + * @var string[] + */ protected $allowed = array('*'); + /** + * @var string[] + */ protected $methods = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'); + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler + * @return \Psr\Http\Message\ResponseInterface + */ public function process(ServerRequestInterface $request, HandlerInterface $handler) { $isOptions = $request->getMethod() === 'OPTIONS'; diff --git a/tests/Fixture/Middlewares/EmptyMiddleware.php b/tests/Fixture/Middlewares/EmptyMiddleware.php index 4a9b34d0..33da8938 100644 --- a/tests/Fixture/Middlewares/EmptyMiddleware.php +++ b/tests/Fixture/Middlewares/EmptyMiddleware.php @@ -13,11 +13,23 @@ */ class EmptyMiddleware implements MiddlewareInterface { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response + * @param callable|null $next + * @return \Psr\Http\Message\ResponseInterface + */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) { + /** @phpstan-ignore-next-line */ return $next($request, $response); } + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler + * @return \Psr\Http\Message\ResponseInterface + */ public function process(ServerRequestInterface $request, HandlerInterface $handler) { return $handler->handle($request); diff --git a/tests/Fixture/Middlewares/FinalMiddleware.php b/tests/Fixture/Middlewares/FinalMiddleware.php index e0cf731e..efc938df 100644 --- a/tests/Fixture/Middlewares/FinalMiddleware.php +++ b/tests/Fixture/Middlewares/FinalMiddleware.php @@ -11,6 +11,12 @@ */ class FinalMiddleware { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response + * @param callable|null $next + * @return \Psr\Http\Message\ResponseInterface + */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) { $response->getBody()->write('Loaded with middleware'); diff --git a/tests/Fixture/Middlewares/FirstMiddleware.php b/tests/Fixture/Middlewares/FirstMiddleware.php index b09ec1e0..5550d434 100644 --- a/tests/Fixture/Middlewares/FirstMiddleware.php +++ b/tests/Fixture/Middlewares/FirstMiddleware.php @@ -11,10 +11,17 @@ */ class FirstMiddleware { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response + * @param callable|null $next + * @return \Psr\Http\Message\ResponseInterface + */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) { $response->getBody()->write('First!'); + /** @phpstan-ignore-next-line */ return $next($request, $response); } } diff --git a/tests/Fixture/Middlewares/InteropMiddleware.php b/tests/Fixture/Middlewares/InteropMiddleware.php index e863fbad..8c494302 100644 --- a/tests/Fixture/Middlewares/InteropMiddleware.php +++ b/tests/Fixture/Middlewares/InteropMiddleware.php @@ -12,10 +12,15 @@ */ class InteropMiddleware implements MiddlewareInterface { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @return \Psr\Http\Message\ResponseInterface + */ public function process(ServerRequestInterface $request, DelegateInterface $delegate) { $response = $delegate->process($request)->withStatus(500); - return $response->withHeader('X-Slytherin', time()); + return $response->withHeader('X-Slytherin', (string) time()); } } diff --git a/tests/Fixture/Middlewares/LastMiddleware.php b/tests/Fixture/Middlewares/LastMiddleware.php index 24a13683..6e45d779 100644 --- a/tests/Fixture/Middlewares/LastMiddleware.php +++ b/tests/Fixture/Middlewares/LastMiddleware.php @@ -11,6 +11,12 @@ */ class LastMiddleware { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response + * @param callable|null $next + * @return \Psr\Http\Message\ResponseInterface + */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) { $response->getBody()->write(' Last!'); diff --git a/tests/Fixture/Middlewares/SecondMiddleware.php b/tests/Fixture/Middlewares/SecondMiddleware.php index 9f18477e..91e93f5b 100644 --- a/tests/Fixture/Middlewares/SecondMiddleware.php +++ b/tests/Fixture/Middlewares/SecondMiddleware.php @@ -11,10 +11,17 @@ */ class SecondMiddleware { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response + * @param callable|null $next + * @return \Psr\Http\Message\ResponseInterface + */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) { $response->getBody()->write(' Second!'); + /** @phpstan-ignore-next-line */ return $next($request, $response); } } diff --git a/tests/Previous/Server.php b/tests/Previous/Server.php index 0c02d5d8..2524cd22 100644 --- a/tests/Previous/Server.php +++ b/tests/Previous/Server.php @@ -1,5 +1,6 @@ make()->run(); +// @codeCoverageIgnoreENd \ No newline at end of file diff --git a/tests/Sample/Server.php b/tests/Sample/Server.php index 5264b631..037470f1 100644 --- a/tests/Sample/Server.php +++ b/tests/Sample/Server.php @@ -1,5 +1,6 @@ addHandler(new Cors); $builder->make()->run(); +// @codeCoverageIgnoreEnd \ No newline at end of file