diff --git a/src/Middleware/ResolvesMiddlewareTrait.php b/src/Middleware/ResolvesMiddlewareTrait.php index 2f21a81b..55605f39 100644 --- a/src/Middleware/ResolvesMiddlewareTrait.php +++ b/src/Middleware/ResolvesMiddlewareTrait.php @@ -15,7 +15,7 @@ trait ResolvesMiddlewareTrait * Resolve the middleware with the container */ protected function resolveMiddleware( - string|callable|MiddlewareInterface|RequestHandlerInterface $middleware + string|callable|array|MiddlewareInterface|RequestHandlerInterface $middleware ): MiddlewareInterface|RequestHandlerInterface { if ($this->isMiddleware($middleware)) { return $middleware; diff --git a/tests/Unit/Middleware/ResolvesMiddlewareTraitTest.php b/tests/Unit/Middleware/ResolvesMiddlewareTraitTest.php index 57970a5f..52b7c392 100644 --- a/tests/Unit/Middleware/ResolvesMiddlewareTraitTest.php +++ b/tests/Unit/Middleware/ResolvesMiddlewareTraitTest.php @@ -12,6 +12,7 @@ use InvalidArgumentException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Server\MiddlewareInterface; +use stdClass; class ResolvesMiddlewareTraitTest extends TestCase { @@ -51,6 +52,20 @@ class ResolvesMiddlewareTraitTest extends TestCase $middleware->callResolveMiddleware('UnresolvableClass'); } + /** + * @covers \Engelsystem\Middleware\ResolvesMiddlewareTrait::resolveMiddleware + */ + public function testResolveMiddlewareNotCallable(): void + { + /** @var Application|MockObject $container */ + $container = $this->createMock(Application::class); + + $middleware = new ResolvesMiddlewareTraitImplementation($container); + + $this->expectException(InvalidArgumentException::class); + $middleware->callResolveMiddleware([new stdClass(), 'test']); + } + /** * @covers \Engelsystem\Middleware\ResolvesMiddlewareTrait::resolveMiddleware */ diff --git a/tests/Unit/Middleware/Stub/ResolvesMiddlewareTraitImplementation.php b/tests/Unit/Middleware/Stub/ResolvesMiddlewareTraitImplementation.php index a4c9b1f1..57d56c42 100644 --- a/tests/Unit/Middleware/Stub/ResolvesMiddlewareTraitImplementation.php +++ b/tests/Unit/Middleware/Stub/ResolvesMiddlewareTraitImplementation.php @@ -18,7 +18,7 @@ class ResolvesMiddlewareTraitImplementation } public function callResolveMiddleware( - string|callable|MiddlewareInterface|RequestHandlerInterface $middleware + string|callable|array|MiddlewareInterface|RequestHandlerInterface $middleware ): MiddlewareInterface|RequestHandlerInterface { return $this->resolveMiddleware($middleware); }