Route resolving: Show better error message when method is not callable
This commit is contained in:
parent
7f2f5ab7ed
commit
b17dbf46e0
|
@ -15,7 +15,7 @@ trait ResolvesMiddlewareTrait
|
||||||
* Resolve the middleware with the container
|
* Resolve the middleware with the container
|
||||||
*/
|
*/
|
||||||
protected function resolveMiddleware(
|
protected function resolveMiddleware(
|
||||||
string|callable|MiddlewareInterface|RequestHandlerInterface $middleware
|
string|callable|array|MiddlewareInterface|RequestHandlerInterface $middleware
|
||||||
): MiddlewareInterface|RequestHandlerInterface {
|
): MiddlewareInterface|RequestHandlerInterface {
|
||||||
if ($this->isMiddleware($middleware)) {
|
if ($this->isMiddleware($middleware)) {
|
||||||
return $middleware;
|
return $middleware;
|
||||||
|
|
|
@ -12,6 +12,7 @@ use InvalidArgumentException;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class ResolvesMiddlewareTraitTest extends TestCase
|
class ResolvesMiddlewareTraitTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -51,6 +52,20 @@ class ResolvesMiddlewareTraitTest extends TestCase
|
||||||
$middleware->callResolveMiddleware('UnresolvableClass');
|
$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
|
* @covers \Engelsystem\Middleware\ResolvesMiddlewareTrait::resolveMiddleware
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ResolvesMiddlewareTraitImplementation
|
||||||
}
|
}
|
||||||
|
|
||||||
public function callResolveMiddleware(
|
public function callResolveMiddleware(
|
||||||
string|callable|MiddlewareInterface|RequestHandlerInterface $middleware
|
string|callable|array|MiddlewareInterface|RequestHandlerInterface $middleware
|
||||||
): MiddlewareInterface|RequestHandlerInterface {
|
): MiddlewareInterface|RequestHandlerInterface {
|
||||||
return $this->resolveMiddleware($middleware);
|
return $this->resolveMiddleware($middleware);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue