You are here

public function ArgumentsResolverTest::testGetArgumentOrder in Drupal 10

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

Class

ArgumentsResolverTest
@coversDefaultClass \Drupal\Component\Utility\ArgumentsResolver @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);
}