fixup! chore(app framework)!: catch missing non-optional controller parameter

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
chore/catch-missing-non-optional-controller-parameter
Christoph Wurst 1 year ago
parent 9b9dd6f963
commit 0a2b7c4788
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8

@ -46,7 +46,6 @@ use OCP\IRequest;
use Psr\Log\LoggerInterface;
use ReflectionMethod;
use ReflectionNamedType;
use TypeError;
use function get_class;
/**
@ -213,9 +212,10 @@ class Dispatcher {
}
$value = $this->request->getParam($paramName, $defaultValue);
$type = $param->getType();
$typeName = null;
if ($type instanceof ReflectionNamedType) {
$typeName = $type->getName();
} else {
$typeName = $this->reflector->getType($paramName);
}
// if this is submitted using GET or a POST form, 'false' should be

@ -62,6 +62,9 @@ class TestController extends Controller {
return [$int, $bool, $test, $test2];
}
public function execTyped(int $int, bool $bool, string $str, ?int $opt = 42): array {
return [$int, $bool, $str, $opt];
}
/**
* @param int $int
@ -370,7 +373,35 @@ class DispatcherTest extends \Test\TestCase {
$this->assertEquals('[3,true,4,7]', $response[3]);
}
public function testTypedControllerParameters(): void {
$this->request = new Request(
[
'post' => [
'int' => '3',
'bool' => 'false',
'str' => '7',
],
'method' => 'POST',
],
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
$this->request,
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
$this->eventLogger
);
$controller = new TestController('app', $this->request);
// reflector is supposed to be called once
$this->dispatcherPassthrough();
$response = $this->dispatcher->dispatch($controller, 'execTyped');
$this->assertEquals('[3,true,"7",42]', $response[3]);
}
public function testResponseTransformedByUrlFormat() {
$this->request = new Request(

Loading…
Cancel
Save