You are here

public function AnnotatedClassDiscoveryTest::testGetDefinitions in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php \Drupal\Tests\Component\Annotation\AnnotatedClassDiscoveryTest::testGetDefinitions()

@covers ::getDefinitions @covers ::prepareAnnotationDefinition @covers ::getAnnotationReader

File

core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php, line 47

Class

AnnotatedClassDiscoveryTest
@coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery @group Annotation @runTestsInSeparateProcesses

Namespace

Drupal\Tests\Component\Annotation

Code

public function testGetDefinitions() {
  $discovery = new AnnotatedClassDiscovery([
    'com\\example' => [
      __DIR__ . '/Fixtures',
    ],
  ]);
  $this
    ->assertEquals([
    'discovery_test_1' => [
      'id' => 'discovery_test_1',
      'class' => 'com\\example\\PluginNamespace\\DiscoveryTest1',
    ],
  ], $discovery
    ->getDefinitions());
  $custom_annotation_discovery = new AnnotatedClassDiscovery([
    'com\\example' => [
      __DIR__ . '/Fixtures',
    ],
  ], CustomPlugin::class, [
    'Drupal\\Tests\\Component\\Annotation',
  ]);
  $this
    ->assertEquals([
    'discovery_test_1' => [
      'id' => 'discovery_test_1',
      'class' => 'com\\example\\PluginNamespace\\DiscoveryTest1',
      'title' => 'Discovery test plugin',
    ],
  ], $custom_annotation_discovery
    ->getDefinitions());
  $empty_discovery = new AnnotatedClassDiscovery([
    'com\\example' => [
      __DIR__ . '/Fixtures',
    ],
  ], CustomPlugin2::class, [
    'Drupal\\Tests\\Component\\Annotation',
  ]);
  $this
    ->assertEquals([], $empty_discovery
    ->getDefinitions());
}