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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Controller%21ControllerResolver.php/class/ControllerResolver/8.9.x" title="ControllerResolver to enhance controllers beyond Symfony&#039;s basic handling." class="local">\Drupal\Core\Controller\ControllerResolver</a> @group Controller

Namespace

Drupal\Tests\Core\Controller

Code

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.