You are here

public function PluginManagerBaseTest::testCreateInstance in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php \Drupal\Tests\Component\Plugin\PluginManagerBaseTest::testCreateInstance()

Tests createInstance() with no fallback methods.

@covers ::createInstance

File

core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php, line 50

Class

PluginManagerBaseTest
@coversDefaultClass \Drupal\Component\Plugin\PluginManagerBase @group Plugin

Namespace

Drupal\Tests\Component\Plugin

Code

public function testCreateInstance() {
  $manager = $this
    ->getMockBuilder('Drupal\\Component\\Plugin\\PluginManagerBase')
    ->getMockForAbstractClass();

  // PluginManagerBase::createInstance() looks for a factory object and then
  // calls createInstance() on it. So we have to mock a factory object.
  $factory_ref = new \ReflectionProperty($manager, 'factory');
  $factory_ref
    ->setAccessible(TRUE);
  $factory_ref
    ->setValue($manager, $this
    ->getMockFactoryInterface(1));

  // Finally the test.
  $configuration_array = [
    'config' => 'something',
  ];
  $result = $manager
    ->createInstance('valid', $configuration_array);
  $this
    ->assertEquals('valid', $result['plugin_id']);
  $this
    ->assertEquals($configuration_array, $result['configuration']);
}