public function ControllerResolverTest::testGetArguments in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/http-kernel/Tests/Controller/ControllerResolverTest.php \Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::testGetArguments()
- 8 core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php \Drupal\Tests\Core\Controller\ControllerResolverTest::testGetArguments()
Same name and namespace in other branches
- 8.0 vendor/symfony/http-kernel/Tests/Controller/ControllerResolverTest.php \Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::testGetArguments()
File
- vendor/
symfony/ http-kernel/ Tests/ Controller/ ControllerResolverTest.php, line 135
Class
Namespace
Symfony\Component\HttpKernel\Tests\ControllerCode
public function testGetArguments() {
$resolver = $this
->createControllerResolver();
$request = Request::create('/');
$controller = array(
new self(),
'testGetArguments',
);
$this
->assertEquals(array(), $resolver
->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$controller = array(
new self(),
'controllerMethod1',
);
$this
->assertEquals(array(
'foo',
), $resolver
->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$controller = array(
new self(),
'controllerMethod2',
);
$this
->assertEquals(array(
'foo',
null,
), $resolver
->getArguments($request, $controller), '->getArguments() uses default values if present');
$request->attributes
->set('bar', 'bar');
$this
->assertEquals(array(
'foo',
'bar',
), $resolver
->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$controller = function ($foo) {
};
$this
->assertEquals(array(
'foo',
), $resolver
->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$controller = function ($foo, $bar = 'bar') {
};
$this
->assertEquals(array(
'foo',
'bar',
), $resolver
->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$controller = new self();
$this
->assertEquals(array(
'foo',
null,
), $resolver
->getArguments($request, $controller));
$request->attributes
->set('bar', 'bar');
$this
->assertEquals(array(
'foo',
'bar',
), $resolver
->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$request->attributes
->set('foobar', 'foobar');
$controller = 'Symfony\\Component\\HttpKernel\\Tests\\Controller\\some_controller_function';
$this
->assertEquals(array(
'foo',
'foobar',
), $resolver
->getArguments($request, $controller));
$request = Request::create('/');
$request->attributes
->set('foo', 'foo');
$request->attributes
->set('foobar', 'foobar');
$controller = array(
new self(),
'controllerMethod3',
);
if (PHP_VERSION_ID === 50316) {
$this
->markTestSkipped('PHP 5.3.16 has a major bug in the Reflection sub-system');
}
else {
try {
$resolver
->getArguments($request, $controller);
$this
->fail('->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');
} catch (\Exception $e) {
$this
->assertInstanceOf('\\RuntimeException', $e, '->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');
}
}
$request = Request::create('/');
$controller = array(
new self(),
'controllerMethod5',
);
$this
->assertEquals(array(
$request,
), $resolver
->getArguments($request, $controller), '->getArguments() injects the request');
}