Skip to content

Commit 78e1ecc

Browse files
Merge branch '3.1' into 3.2
* 3.1: (28 commits) Fix merge [Validator] add class name to the cache key [Serializer] Remove AbstractObjectNormalizer::isAttributeToNormalize Throw less misleading exception when property access not found [Twig] Fix deprecations with Twig 1.29 Fixed typo [FrameworkBundle] Removed the kernel.debug parameter from the cache pool namespace seed Fix email address fix the docblock in regard to the role argument Don't use the "app" global variable in the profiler [VarDumper] fix tests when xdebug is enabled Fix merge FIXED NON EXISTING TYPE DECLARATION [Cache] Fix dumping SplDoublyLinkedList iter mode [Console] fixed PHP7 Errors when not using Dispatcher Regression test for missing controller arguments (3.1) Regression test for missing controller arguments fix a test checking for a value [Form][DX] FileType "multiple" fixes fixed CS ...
2 parents 29d81a7 + 0f31276 commit 78e1ecc

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Controller/ArgumentResolver/DefaultValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class DefaultValueResolver implements ArgumentValueResolverInterface
2727
*/
2828
public function supports(Request $request, ArgumentMetadata $argument)
2929
{
30-
return $argument->hasDefaultValue() || ($argument->isNullable() && !$argument->isVariadic());
30+
return $argument->hasDefaultValue() || (null !== $argument->getType() && $argument->isNullable() && !$argument->isVariadic());
3131
}
3232

3333
/**

Controller/ControllerResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
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
/**
@@ -140,7 +148,7 @@ protected function doGetArguments(Request $request, $controller, array $paramete
140148
$arguments[] = $request;
141149
} elseif ($param->isDefaultValueAvailable()) {
142150
$arguments[] = $param->getDefaultValue();
143-
} elseif ($param->allowsNull()) {
151+
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
144152
$arguments[] = null;
145153
} else {
146154
if (is_array($controller)) {

Tests/Controller/ArgumentResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public function testGetArgumentWithoutArray()
203203
$resolver->getArguments($request, $controller);
204204
}
205205

206+
/**
207+
* @expectedException \RuntimeException
208+
*/
209+
public function testIfExceptionIsThrownWhenMissingAnArgument()
210+
{
211+
$request = Request::create('/');
212+
$controller = array($this, 'controllerWithFoo');
213+
214+
self::$resolver->getArguments($request, $controller);
215+
}
216+
206217
/**
207218
* @requires PHP 7.1
208219
*/

Tests/Controller/ControllerResolverTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public function testCreateControllerCanReturnAnyCallable()
227227
$mock->getController($request);
228228
}
229229

230+
/**
231+
* @expectedException \RuntimeException
232+
* @group legacy
233+
*/
234+
public function testIfExceptionIsThrownWhenMissingAnArgument()
235+
{
236+
$resolver = new ControllerResolver();
237+
$request = Request::create('/');
238+
239+
$controller = array($this, 'controllerMethod1');
240+
241+
$resolver->getArguments($request, $controller);
242+
}
243+
230244
/**
231245
* @requires PHP 7.1
232246
* @group legacy

0 commit comments

Comments
 (0)