function ReflectionFactoryTest::testGetInstanceArguments

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testGetInstanceArguments()
  2. 8.9.x core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testGetInstanceArguments()
  3. 11.x core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testGetInstanceArguments()

@covers ::getInstanceArguments
@dataProvider providerGetInstanceArguments

File

core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php, line 108

Class

ReflectionFactoryTest
@group Plugin @coversDefaultClass \Drupal\Component\Plugin\Factory\ReflectionFactory[[api-linebreak]]

Namespace

Drupal\Tests\Component\Plugin\Factory

Code

public function testGetInstanceArguments($expected, $reflector_name, $plugin_id, $plugin_definition, $configuration) : void {
  $reflection_factory = $this->getMockBuilder('Drupal\\Component\\Plugin\\Factory\\ReflectionFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $get_instance_arguments_ref = new \ReflectionMethod($reflection_factory, 'getInstanceArguments');
  // Special case for plugin class without a constructor.
  // getInstanceArguments() throws an exception if there's no constructor.
  // This is not a documented behavior of getInstanceArguments(), but allows
  // us to use one data set for this test method as well as
  // testCreateInstance().
  if ($plugin_id == 'arguments_no_constructor') {
    $this->expectException('\\ReflectionException');
  }
  // Finally invoke getInstanceArguments() on our mocked factory.
  $ref = new \ReflectionClass($reflector_name);
  $result = $get_instance_arguments_ref->invoke($reflection_factory, $ref, $plugin_id, $plugin_definition, $configuration);
  $this->assertEquals($expected, $result);
}

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