You are here

trait PluginManagerTestTrait in Purge 8.3

Testing helpers DIC plugin manager derivatives.

Hierarchy

See also

\Drupal\Tests\purge\Kernel\KernelPluginManagerTestBase

1 file declares its use of PluginManagerTestTrait
KernelPluginManagerTestBase.php in tests/src/Kernel/KernelPluginManagerTestBase.php

File

tests/src/Traits/PluginManagerTestTrait.php, line 14

Namespace

Drupal\Tests\purge\Traits
View source
trait PluginManagerTestTrait {

  /**
   * The name of the service as defined in services.yml.
   *
   * @var string
   */
  protected $pluginManagerClass = '';

  /**
   * Instance of the service being tested, instantiated by the container.
   *
   * @var null|\Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $pluginManager;

  /**
   * Set up the test.
   */
  public function setUp($switch_to_memory_queue = TRUE) : void {
    parent::setUp($switch_to_memory_queue);
    $this->pluginManager = new $this->pluginManagerClass($this->container
      ->get('container.namespaces'), $this->container
      ->get('cache.discovery'), $this->container
      ->get('module_handler'));
  }

  /**
   * Test if the plugin manager complies to the basic requirements.
   */
  public function testCodeContract() : void {
    $this
      ->assertTrue($this->pluginManager instanceof $this->pluginManagerClass);
    $this
      ->assertTrue($this->pluginManager instanceof PluginManagerInterface);
    $this
      ->assertTrue($this->pluginManager instanceof DefaultPluginManager);
    $this
      ->assertTrue($this->pluginManager instanceof CachedDiscoveryInterface);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginManagerTestTrait::$pluginManager protected property Instance of the service being tested, instantiated by the container.
PluginManagerTestTrait::$pluginManagerClass protected property The name of the service as defined in services.yml. 8
PluginManagerTestTrait::setUp public function Set up the test. 1
PluginManagerTestTrait::testCodeContract public function Test if the plugin manager complies to the basic requirements.