diff --git a/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php index 4392b3a..6f675cc 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Component\Annotation; +use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Tests\UnitTestCase; @@ -34,13 +35,55 @@ public function testGetPluginNamespaces() { * @covers ::getAnnotationReader */ public function testGetDefinitions() { - $discovery = new AnnotatedClassDiscovery(['com/example' => [__DIR__ . '/Fixtures']]); + $discovery = new AnnotatedClassDiscovery(['com\example' => [__DIR__ . '/Fixtures']]); $this->assertEquals([ 'discovery_test_1' => [ 'id' => 'discovery_test_1', - 'class' => 'com/example\com\example\DiscoveryTest1', + '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()); } } + +/** + * Custom plugin annotation. + * + * @Annotation + */ +class CustomPlugin extends Plugin { + + /** + * The plugin ID. + * + * @var string + */ + public $id; + + /** + * The plugin title. + * + * @ingroup plugin_translatable + */ + public $title = ''; + +} + +/** + * Custom plugin annotation. + * + * @Annotation + */ +class CustomPlugin2 extends Plugin {} diff --git a/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php b/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php index 5e02fdd..4c5eaa1 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php @@ -43,6 +43,7 @@ public function testSetClass() { } class AnnotationBaseStub extends AnnotationBase { - public function get() { - } + + public function get() {} + } diff --git a/core/tests/Drupal/Tests/Component/Annotation/Fixtures/com/example/DiscoveryTest1.php b/core/tests/Drupal/Tests/Component/Annotation/Fixtures/PluginNamespace/DiscoveryTest1.php similarity index 40% rename from core/tests/Drupal/Tests/Component/Annotation/Fixtures/com/example/DiscoveryTest1.php rename to core/tests/Drupal/Tests/Component/Annotation/Fixtures/PluginNamespace/DiscoveryTest1.php index 1c3bfc6..a2cbe0f 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/Fixtures/com/example/DiscoveryTest1.php +++ b/core/tests/Drupal/Tests/Component/Annotation/Fixtures/PluginNamespace/DiscoveryTest1.php @@ -1,10 +1,14 @@