Commit d7b5f9e3 authored by catch's avatar catch
Browse files

Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...

Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan, xjm: Changing plugins from annotations to attributes in contrib leads to error if plugin extends from a missing dependency

(cherry picked from commit 618aeb60)
parent 791ab90f
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ parameters:
    - modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/ExtendingNonInstalledClass.php
    - modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/custom_annotation/UsingNonInstalledTraitClass.php
    - modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/custom_annotation/ExtendingNonInstalledClass.php
    - tests/Drupal/Tests/Component/Plugin/Attribute/Fixtures/Plugins/PluginNamespace/AttributeDiscoveryTest2.php

  ignoreErrors:
    # new static() is a best practice in Drupal, so we cannot fix that.
+3 −3
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ protected function setUp(): void {
    FileCacheFactory::setPrefix('prefix');

    // Normally the attribute classes would be autoloaded.
    include_once __DIR__ . '/Fixtures/CustomPlugin.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';

    $additionalClassLoader = new ClassLoader();
    $additionalClassLoader->addPsr4("com\\example\\PluginNamespace\\", __DIR__ . "/Fixtures/Plugins/PluginNamespace");
    $additionalClassLoader->addPsr4("com\\example\\PluginNamespace\\", __DIR__ . "/../../../../../fixtures/plugins/Plugin/PluginNamespace");
    $additionalClassLoader->register(TRUE);
  }

@@ -43,7 +43,7 @@ protected function setUp(): void {
   */
  public function testGetDefinitions(): void {
    // Path to the classes which we'll discover and parse annotation.
    $discovery_path = __DIR__ . '/Fixtures/Plugins';
    $discovery_path = __DIR__ . "/../../../../../fixtures/plugins/Plugin";
    // File path that should be discovered within that directory.
    $file_path = $discovery_path . '/PluginNamespace/AttributeDiscoveryTest1.php';
    // Define a file path within the directory that should not be discovered.
+5 −7
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@
use Drupal\Component\Plugin\Discovery\AttributeClassDiscovery;
use Drupal\Component\FileCache\FileCacheFactory;
use PHPUnit\Framework\TestCase;
use com\example\PluginNamespace\CustomPlugin;
use com\example\PluginNamespace\CustomPlugin2;

/**
 * @coversDefaultClass \Drupal\Component\Plugin\Discovery\AttributeClassDiscovery
@@ -30,10 +28,10 @@ protected function setUp(): void {
    FileCacheFactory::setPrefix('prefix');

    // Normally the attribute classes would be autoloaded.
    include_once __DIR__ . '/Fixtures/CustomPlugin.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';

    $additionalClassLoader = new ClassLoader();
    $additionalClassLoader->addPsr4("com\\example\\PluginNamespace\\", __DIR__ . "/Fixtures/Plugins/PluginNamespace");
    $additionalClassLoader->addPsr4("com\\example\\PluginNamespace\\", __DIR__ . "/../../../../../fixtures/plugins/Plugin/PluginNamespace");
    $additionalClassLoader->register(TRUE);
  }

@@ -57,7 +55,7 @@ public function testGetPluginNamespaces(): void {
   * @covers ::prepareAttributeDefinition
   */
  public function testGetDefinitions(): void {
    $discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . '/Fixtures/Plugins']]);
    $discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . "/../../../../../fixtures/plugins/Plugin"]]);
    $this->assertEquals([
      'discovery_test_1' => [
        'id' => 'discovery_test_1',
@@ -65,7 +63,7 @@ public function testGetDefinitions(): void {
      ],
    ], $discovery->getDefinitions());

    $custom_annotation_discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . '/Fixtures/Plugins']], CustomPlugin::class);
    $custom_annotation_discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . "/../../../../../fixtures/plugins/Plugin"]], 'com\example\PluginNamespace\CustomPlugin');
    $this->assertEquals([
      'discovery_test_1' => [
        'id' => 'discovery_test_1',
@@ -74,7 +72,7 @@ public function testGetDefinitions(): void {
      ],
    ], $custom_annotation_discovery->getDefinitions());

    $empty_discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . '/Fixtures/Plugins']], CustomPlugin2::class);
    $empty_discovery = new AttributeClassDiscovery(['com\example' => [__DIR__ . "/../../../../../fixtures/plugins/Plugin"]], 'com\example\PluginNamespace\CustomPlugin2');
    $this->assertEquals([], $empty_discovery->getDefinitions());
  }

+4 −4
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ class AttributeBridgeDecoratorTest extends TestCase {
   */
  public function testGetDefinitions(): void {
    // Normally the attribute classes would be autoloaded.
    include_once __DIR__ . '/../Attribute/Fixtures/CustomPlugin.php';
    include_once __DIR__ . '/../Attribute/Fixtures/Plugins/PluginNamespace/AttributeDiscoveryTest1.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/Plugin/PluginNamespace/AttributeDiscoveryTest1.php';

    $definitions = [];
    $definitions['object'] = new ObjectDefinition(['id' => 'foo']);
@@ -51,8 +51,8 @@ public function testGetDefinitions(): void {
   */
  public function testOtherMethod(): void {
    // Normally the attribute classes would be autoloaded.
    include_once __DIR__ . '/../Attribute/Fixtures/CustomPlugin.php';
    include_once __DIR__ . '/../Attribute/Fixtures/Plugins/PluginNamespace/AttributeDiscoveryTest1.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';
    include_once __DIR__ . '/../../../../../fixtures/plugins/Plugin/PluginNamespace/AttributeDiscoveryTest1.php';

    $discovery = $this->createMock(ExtendedDiscoveryInterface::class);
    $discovery->expects($this->exactly(2))
Loading