Skip to content

Commit

Permalink
bug #20755 [2.7][HttpKernel] Regression test for missing controller a…
Browse files Browse the repository at this point in the history
…rguments (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
  • Loading branch information
fabpot committed Dec 5, 2016
2 parents e0bd2a2 + d1a7164 commit e70dc64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -36,6 +36,13 @@ class ControllerResolver implements ControllerResolverInterface
*/
private $supportsVariadic;

/**
* If scalar types exists.
*
* @var bool
*/
private $supportsScalarTypes;

/**
* Constructor.
*
Expand All @@ -46,6 +53,7 @@ public function __construct(LoggerInterface $logger = null)
$this->logger = $logger;

$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
}

/**
Expand Down Expand Up @@ -132,7 +140,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete
$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)) {
Expand Down
Expand Up @@ -223,6 +223,19 @@ public function testCreateControllerCanReturnAnyCallable()
$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
*/
Expand Down

0 comments on commit e70dc64

Please sign in to comment.