You are here

class DevelGenerateManagerTest in Devel 8.3

Same name and namespace in other branches
  1. 8.2 devel_generate/tests/src/Unit/DevelGenerateManagerTest.php \Drupal\Tests\devel_generate\Unit\DevelGenerateManagerTest
  2. 4.x devel_generate/tests/src/Unit/DevelGenerateManagerTest.php \Drupal\Tests\devel_generate\Unit\DevelGenerateManagerTest

@coversDefaultClass \Drupal\devel_generate\DevelGeneratePluginManager @group devel_generate

Hierarchy

Expanded class hierarchy of DevelGenerateManagerTest

File

devel_generate/tests/src/Unit/DevelGenerateManagerTest.php, line 13

Namespace

Drupal\Tests\devel_generate\Unit
View source
class DevelGenerateManagerTest extends UnitTestCase {

  /**
   * The plugin discovery.
   *
   * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $discovery;

  /**
   * A list of devel generate plugin definitions.
   *
   * @var array
   */
  protected $definitions = [
    'devel_generate_example' => [
      'id' => 'devel_generate_example',
      'class' => 'Drupal\\devel_generate_example\\Plugin\\DevelGenerate\\ExampleDevelGenerate',
      'url' => 'devel_generate_example',
      'dependencies' => [],
    ],
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Mock a Discovery object to replace AnnotationClassDiscovery.
    $this->discovery = $this
      ->createMock('Drupal\\Component\\Plugin\\Discovery\\DiscoveryInterface');
    $this->discovery
      ->expects($this
      ->any())
      ->method('getDefinitions')
      ->will($this
      ->returnValue($this->definitions));
  }

  /**
   * Test creating an instance of the DevelGenerateManager.
   */
  public function testCreateInstance() {
    $namespaces = new \ArrayObject([
      'Drupal\\devel_generate_example' => realpath(dirname(__FILE__) . '/../../../modules/devel_generate_example/lib'),
    ]);
    $cache_backend = $this
      ->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $module_handler = $this
      ->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $manager = new TestDevelGeneratePluginManager($namespaces, $cache_backend, $module_handler);
    $manager
      ->setDiscovery($this->discovery);
    $example_instance = $manager
      ->createInstance('devel_generate_example');
    $plugin_def = $example_instance
      ->getPluginDefinition();
    $this
      ->assertInstanceOf('Drupal\\devel_generate_example\\Plugin\\DevelGenerate\\ExampleDevelGenerate', $example_instance);
    $this
      ->assertArrayHasKey('url', $plugin_def);
    $this
      ->assertTrue($plugin_def['url'] == 'devel_generate_example');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DevelGenerateManagerTest::$definitions protected property A list of devel generate plugin definitions.
DevelGenerateManagerTest::$discovery protected property The plugin discovery.
DevelGenerateManagerTest::setUp protected function Overrides UnitTestCase::setUp
DevelGenerateManagerTest::testCreateInstance public function Test creating an instance of the DevelGenerateManager.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.