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
This commit is contained in:
commit
e70dc640cf
@ -36,6 +36,13 @@ class ControllerResolver implements ControllerResolverInterface
|
|||||||
*/
|
*/
|
||||||
private $supportsVariadic;
|
private $supportsVariadic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If scalar types exists.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $supportsScalarTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -46,6 +53,7 @@ class ControllerResolver implements ControllerResolverInterface
|
|||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
|
||||||
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
|
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
|
||||||
|
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +140,7 @@ class ControllerResolver implements ControllerResolverInterface
|
|||||||
$arguments[] = $request;
|
$arguments[] = $request;
|
||||||
} elseif ($param->isDefaultValueAvailable()) {
|
} elseif ($param->isDefaultValueAvailable()) {
|
||||||
$arguments[] = $param->getDefaultValue();
|
$arguments[] = $param->getDefaultValue();
|
||||||
} elseif ($param->allowsNull()) {
|
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
|
||||||
$arguments[] = null;
|
$arguments[] = null;
|
||||||
} else {
|
} else {
|
||||||
if (is_array($controller)) {
|
if (is_array($controller)) {
|
||||||
|
@ -223,6 +223,19 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
|||||||
$mock->getController($request);
|
$mock->getController($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
*/
|
||||||
|
public function testIfExceptionIsThrownWhenMissingAnArgument()
|
||||||
|
{
|
||||||
|
$resolver = new ControllerResolver();
|
||||||
|
$request = Request::create('/');
|
||||||
|
|
||||||
|
$controller = array($this, 'controllerMethod1');
|
||||||
|
|
||||||
|
$resolver->getArguments($request, $controller);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires PHP 7.1
|
* @requires PHP 7.1
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user