diff --git a/src/Controller/ControllerFactory.php b/src/Controller/ControllerFactory.php index f38719a8557..835a056c98e 100644 --- a/src/Controller/ControllerFactory.php +++ b/src/Controller/ControllerFactory.php @@ -268,7 +268,7 @@ protected function coerceStringToType(string $argument, ReflectionNamedType $typ case 'float': return is_numeric($argument) ? (float)$argument : null; case 'int': - return filter_var($argument, FILTER_VALIDATE_INT) ? (int)$argument : null; + return filter_var($argument, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); case 'bool': return $argument === '0' ? false : ($argument === '1' ? true : null); case 'array': diff --git a/tests/TestCase/Controller/ControllerFactoryTest.php b/tests/TestCase/Controller/ControllerFactoryTest.php index a82ed010b18..7802cfa737e 100644 --- a/tests/TestCase/Controller/ControllerFactoryTest.php +++ b/tests/TestCase/Controller/ControllerFactoryTest.php @@ -748,14 +748,14 @@ public function testInvokePassedParametersCoercion(): void 'plugin' => null, 'controller' => 'Dependencies', 'action' => 'requiredTyped', - 'pass' => ['1.0', '2', '0', ''], + 'pass' => ['1.0', '0', '0', ''], ], ]); $controller = $this->factory->create($request); $result = $this->factory->invoke($controller); $data = json_decode((string)$result->getBody(), true); - $this->assertSame(['one' => 1.0, 'two' => 2, 'three' => false, 'four' => []], $data); + $this->assertSame(['one' => 1.0, 'two' => 0, 'three' => false, 'four' => []], $data); $request = new ServerRequest([ 'url' => 'test_plugin_three/dependencies/requiredTyped',