Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e70dc64

Browse files
committed
bug #20755 [2.7][HttpKernel] Regression test for missing controller arguments (iltar)
This PR was merged into the 2.7 branch. Discussion ---------- [2.7][HttpKernel] Regression test for missing controller arguments | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20746 | License | MIT | Doc PR | ~ This fix should ensure that when an action has a mandatory parameter without a type, it will throw the exception instead of inserting null. This test was missing when adding nullable support in 2.7 and up (probably has to be added to 3.1 as well). Commits ------- d1a7164 Regression test for missing controller arguments
2 parents e0bd2a2 + d1a7164 commit e70dc64

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class ControllerResolver implements ControllerResolverInterface
3636
*/
3737
private $supportsVariadic;
3838

39+
/**
40+
* If scalar types exists.
41+
*
42+
* @var bool
43+
*/
44+
private $supportsScalarTypes;
45+
3946
/**
4047
* Constructor.
4148
*
@@ -46,6 +53,7 @@ public function __construct(LoggerInterface $logger = null)
4653
$this->logger = $logger;
4754

4855
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
56+
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
4957
}
5058

5159
/**
@@ -132,7 +140,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete
132140
$arguments[] = $request;
133141
} elseif ($param->isDefaultValueAvailable()) {
134142
$arguments[] = $param->getDefaultValue();
135-
} elseif ($param->allowsNull()) {
143+
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
136144
$arguments[] = null;
137145
} else {
138146
if (is_array($controller)) {

src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ public function testCreateControllerCanReturnAnyCallable()
223223
$mock->getController($request);
224224
}
225225

226+
/**
227+
* @expectedException \RuntimeException
228+
*/
229+
public function testIfExceptionIsThrownWhenMissingAnArgument()
230+
{
231+
$resolver = new ControllerResolver();
232+
$request = Request::create('/');
233+
234+
$controller = array($this, 'controllerMethod1');
235+
236+
$resolver->getArguments($request, $controller);
237+
}
238+
226239
/**
227240
* @requires PHP 7.1
228241
*/

0 commit comments

Comments
 (0)