You are here

public function DefaultPluginManagerTest::testProviderExists in Drupal 9

Same name and namespace in other branches
  1. 8 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 379

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);
}