function ArgumentsResolverTest::testGetArgumentOrder

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php \Drupal\Tests\Component\Utility\ArgumentsResolverTest::testGetArgumentOrder()
  2. 8.9.x 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 104

Class

ArgumentsResolverTest
@coversDefaultClass \Drupal\Component\Utility\ArgumentsResolver @group Access

Namespace

Drupal\Tests\Component\Utility

Code

public function testGetArgumentOrder() : void {
    $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.