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:
Fabien Potencier 2016-12-05 08:53:58 +01:00
commit e70dc640cf
2 changed files with 22 additions and 1 deletions

View File

@ -36,6 +36,13 @@ class ControllerResolver implements ControllerResolverInterface
*/
private $supportsVariadic;
/**
* If scalar types exists.
*
* @var bool
*/
private $supportsScalarTypes;
/**
* Constructor.
*
@ -46,6 +53,7 @@ class ControllerResolver implements ControllerResolverInterface
$this->logger = $logger;
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
}
/**
@ -132,7 +140,7 @@ class ControllerResolver implements ControllerResolverInterface
$arguments[] = $request;
} elseif ($param->isDefaultValueAvailable()) {
$arguments[] = $param->getDefaultValue();
} elseif ($param->allowsNull()) {
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
$arguments[] = null;
} else {
if (is_array($controller)) {

View File

@ -223,6 +223,19 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
$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
*/