You are here

public function ArgumentsResolverTest::providerTestGetArgument in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php \Drupal\Tests\Component\Utility\ArgumentsResolverTest::providerTestGetArgument()

Provides test data to testGetArgument().

File

core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php, line 39
Contains \Drupal\Tests\Component\Utility\ArgumentsResolverTest.

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestGetArgument() {
  $data = [];

  // Test an optional parameter with no provided value.
  $data[] = [
    function ($foo = 'foo') {
    },
    [],
    [],
    [],
    [
      'foo',
    ],
  ];

  // Test an optional parameter with a provided value.
  $data[] = [
    function ($foo = 'foo') {
    },
    [
      'foo' => 'bar',
    ],
    [],
    [],
    [
      'bar',
    ],
  ];

  // Test with a provided value.
  $data[] = [
    function ($foo) {
    },
    [
      'foo' => 'bar',
    ],
    [],
    [],
    [
      'bar',
    ],
  ];

  // Test with an explicitly NULL value.
  $data[] = [
    function ($foo) {
    },
    [],
    [
      'foo' => NULL,
    ],
    [],
    [
      NULL,
    ],
  ];

  // Test with a raw value that overrides the provided upcast value, since
  // it is not typehinted.
  $scalars = [
    'foo' => 'baz',
  ];
  $objects = [
    'foo' => new \stdClass(),
  ];
  $data[] = [
    function ($foo) {
    },
    $scalars,
    $objects,
    [],
    [
      'baz',
    ],
  ];
  return $data;
}