function ArgumentsResolverTest::providerTestGetArgument

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

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public static 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 type hinted.
    $scalars = [
        'foo' => 'baz',
    ];
    $objects = [
        'foo' => new \stdClass(),
    ];
    $data[] = [
        function ($foo) {
        },
        $scalars,
        $objects,
        [],
        [
            'baz',
        ],
    ];
    // Test a static method string.
    $data[] = [
        TestStaticMethodClass::class . "::access",
        [],
        [
            'foo' => NULL,
        ],
        [],
        [
            NULL,
        ],
    ];
    return $data;
}

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