diff --git a/src/Platform/Platform.php b/src/Platform/Platform.php index 7b90595..66e0840 100644 --- a/src/Platform/Platform.php +++ b/src/Platform/Platform.php @@ -115,7 +115,7 @@ protected function initHttp(array $services): void switch ($option['type']) { case 'param': $key = substr($key, stripos($key, ':') + 1); - $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']); + $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']); break; case 'injection': $hook->inject($option['name']); @@ -165,7 +165,7 @@ protected function initTasks(array $services): void switch ($option['type']) { case 'param': $key = substr($key, stripos($key, ':') + 1); - $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']); + $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']); break; case 'injection': $hook->inject($option['name']); @@ -222,7 +222,7 @@ protected function initWorker(array $services, string $workerName): void switch ($option['type']) { case 'param': $key = substr($key, stripos($key, ':') + 1); - $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']); + $hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']); break; case 'injection': $hook->inject($option['name']); diff --git a/tests/Platform/TestActionWithParams.php b/tests/Platform/TestActionWithParams.php new file mode 100644 index 0000000..4e2e7d1 --- /dev/null +++ b/tests/Platform/TestActionWithParams.php @@ -0,0 +1,26 @@ +httpPath = '/with-params'; + $this->httpMethod = 'GET'; + + $this + ->param('name', '', new Text(128), 'User name.', false, example: 'John Doe') + ->param('age', 0, new Range(0, 150), 'User age.', true, example: '25') + ->param('active', false, new Boolean(true), 'Is active.', true, deprecated: true, example: 'true') + ->inject('response') + ->callback(function ($name, $age, $active, $response) { + $response->send('OK'); + }); + } +} diff --git a/tests/Platform/TestService.php b/tests/Platform/TestService.php index edb5970..091de5f 100644 --- a/tests/Platform/TestService.php +++ b/tests/Platform/TestService.php @@ -13,5 +13,6 @@ public function __construct() $this->addAction('chunked', new TestActionChunked()); $this->addAction('redirect', new TestActionRedirect()); $this->addAction('initHook', new TestActionInit()); + $this->addAction('withParams', new TestActionWithParams()); } } diff --git a/tests/e2e/HTTPServicesTest.php b/tests/e2e/HTTPServicesTest.php index 0ef080c..5efa28d 100644 --- a/tests/e2e/HTTPServicesTest.php +++ b/tests/e2e/HTTPServicesTest.php @@ -106,4 +106,37 @@ public function testHook() $this->assertEquals('Hello World!', $result); $this->assertEquals('', ($response1->getHeaders()['x-init'] ?? '')); } + + public function testActionParamFieldsForwardedToRoute() + { + $routes = Http::getRoutes(); + + $route = null; + foreach ($routes as $method => $methodRoutes) { + foreach ($methodRoutes as $r) { + if ($r->getPath() === '/with-params') { + $route = $r; + break 2; + } + } + } + + $this->assertNotNull($route, 'Route /with-params should be registered'); + + $params = $route->getParams(); + + // Verify all Action::param() fields are forwarded to the Route + $actionParamKeys = ['default', 'validator', 'description', 'optional', 'injections', 'skipValidation', 'deprecated', 'example']; + + foreach ($params as $name => $param) { + foreach ($actionParamKeys as $key) { + $this->assertArrayHasKey($key, $param, "Param '{$name}' is missing '{$key}' on the Route. Platform must forward all Action param fields."); + } + } + + $this->assertEquals('John Doe', $params['name']['example']); + $this->assertFalse($params['name']['deprecated']); + $this->assertEquals('true', $params['active']['example']); + $this->assertTrue($params['active']['deprecated']); + } }