function ControllerResolverTest::testGetArguments
Tests getArguments().
Ensure that doGetArguments uses converted arguments if available.
@group legacy @expectedDeprecation Drupal\Core\Controller\ControllerResolver::doGetArguments is deprecated as of 8.6.0 and will be removed in 9.0. Inject the "http_kernel.controller.argument_resolver" service instead.
See also
\Drupal\Core\Controller\ControllerResolver::getArguments()
\Drupal\Core\Controller\ControllerResolver::doGetArguments()
File
-
core/
tests/ Drupal/ Tests/ Core/ Controller/ ControllerResolverTest.php, line 79
Class
- ControllerResolverTest
- @coversDefaultClass \Drupal\Core\Controller\ControllerResolver @group Controller
Namespace
Drupal\Tests\Core\ControllerCode
public function testGetArguments() {
if (!in_array('Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface', class_implements('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver'))) {
$this->markTestSkipped("Do not test ::getArguments() method when it is not implemented by Symfony's ControllerResolver.");
}
$controller = function (EntityInterface $entity, $user, RouteMatchInterface $route_match, ServerRequestInterface $psr_7) {
};
$mock_entity = $this->getMockBuilder('Drupal\\Core\\Entity\\EntityBase')
->disableOriginalConstructor()
->getMock();
$mock_account = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
$request = new Request([], [], [
'entity' => $mock_entity,
'user' => $mock_account,
'_raw_variables' => new ParameterBag([
'entity' => 1,
'user' => 1,
]),
], [], [], [
'HTTP_HOST' => 'drupal.org',
]);
$arguments = $this->controllerResolver
->getArguments($request, $controller);
$this->assertEquals($mock_entity, $arguments[0]);
$this->assertEquals($mock_account, $arguments[1]);
$this->assertEquals(RouteMatch::createFromRequest($request), $arguments[2], 'Ensure that the route match object is passed along as well');
$this->assertInstanceOf(ServerRequestInterface::class, $arguments[3], 'Ensure that the PSR-7 object is passed along as well');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.