function ArgumentsResolverTest::testGetArgumentOrder

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php \Drupal\Tests\Component\Utility\ArgumentsResolverTest::testGetArgumentOrder()
  2. 10 core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php \Drupal\Tests\Component\Utility\ArgumentsResolverTest::testGetArgumentOrder()
  3. 11.x core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php \Drupal\Tests\Component\Utility\ArgumentsResolverTest::testGetArgumentOrder()

Tests getArgument() with a Route, Request, and Account object.

File

core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php, line 98

Class

ArgumentsResolverTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Utility%21ArgumentsResolver.php/class/ArgumentsResolver/9" title="Resolves the arguments to pass to a callable." class="local">\Drupal\Component\Utility\ArgumentsResolver</a> @group Access

Namespace

Drupal\Tests\Component\Utility

Code

public function testGetArgumentOrder() {
    $a1 = $this->getMockBuilder('\\Drupal\\Tests\\Component\\Utility\\Test1Interface')
        ->getMock();
    $a2 = $this->getMockBuilder('\\Drupal\\Tests\\Component\\Utility\\TestClass')
        ->getMock();
    $a3 = $this->getMockBuilder('\\Drupal\\Tests\\Component\\Utility\\Test2Interface')
        ->getMock();
    $objects = [
        't1' => $a1,
        'tc' => $a2,
    ];
    $wildcards = [
        $a3,
    ];
    $resolver = new ArgumentsResolver([], $objects, $wildcards);
    $callable = function (Test1Interface $t1, TestClass $tc, Test2Interface $t2) {
    };
    $arguments = $resolver->getArguments($callable);
    $this->assertSame([
        $a1,
        $a2,
        $a3,
    ], $arguments);
    // Test again, but with the arguments in a different order.
    $callable = function (Test2Interface $t2, TestClass $tc, Test1Interface $t1) {
    };
    $arguments = $resolver->getArguments($callable);
    $this->assertSame([
        $a3,
        $a2,
        $a1,
    ], $arguments);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.