function PluginManagerBaseTest::testCreateInstance

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

Class

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

Namespace

Drupal\Tests\Component\Plugin

Code

public function testCreateInstance() : void {
    $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->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']);
}

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