function DefaultPluginManagerTest::testProviderExists

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testProviderExists()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testProviderExists()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testProviderExists()

@covers ::findDefinitions @covers ::extractProviderFromDefinition

File

core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php, line 380

Class

DefaultPluginManagerTest
Tests the DefaultPluginManager.

Namespace

Drupal\Tests\Core\Plugin

Code

public function testProviderExists() {
    $definitions = [];
    $definitions['array_based_found'] = [
        'provider' => 'module_found',
    ];
    $definitions['array_based_missing'] = [
        'provider' => 'module_missing',
    ];
    $definitions['stdclass_based_found'] = (object) [
        'provider' => 'module_found',
    ];
    $definitions['stdclass_based_missing'] = (object) [
        'provider' => 'module_missing',
    ];
    $definitions['classed_object_found'] = new ObjectDefinition([
        'provider' => 'module_found',
    ]);
    $definitions['classed_object_missing'] = new ObjectDefinition([
        'provider' => 'module_missing',
    ]);
    $expected = [];
    $expected['array_based_found'] = $definitions['array_based_found'];
    $expected['stdclass_based_found'] = $definitions['stdclass_based_found'];
    $expected['classed_object_found'] = $definitions['classed_object_found'];
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module_handler->moduleExists('module_found')
        ->willReturn(TRUE)
        ->shouldBeCalled();
    $module_handler->moduleExists('module_missing')
        ->willReturn(FALSE)
        ->shouldBeCalled();
    $plugin_manager = new TestPluginManager($this->namespaces, $definitions, $module_handler->reveal());
    $result = $plugin_manager->getDefinitions();
    $this->assertEquals($expected, $result);
}

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