Browse Source

add unknown plugin flag to PluginConfig

Kevin Pfeifer 2 years ago
parent
commit
cd7e6fd74b

+ 6 - 0
src/Core/PluginConfig.php

@@ -101,6 +101,12 @@ class PluginConfig
             }
         }
 
+        $diff = array_diff(array_keys($pluginLoadConfig), $availablePlugins);
+        foreach ($diff as $unknownPlugin) {
+            $result[$unknownPlugin]['isLoaded'] = false;
+            $result[$unknownPlugin]['isUnknown'] = true;
+        }
+
         return $result;
     }
 }

+ 33 - 0
tests/TestCase/Command/PluginListCommandTest.php

@@ -17,6 +17,7 @@ namespace Cake\Test\TestCase\Command;
 
 use Cake\Console\CommandInterface;
 use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
+use Cake\Core\Exception\MissingPluginException;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -143,4 +144,36 @@ PHP;
         $this->assertOutputContains('TestPlugin');
         $this->assertOutputContains('OtherPlugin');
     }
+
+    /**
+     * Test listing unknown plugins throws an exception
+     */
+    public function testListUnknown(): void
+    {
+        $file = <<<PHP
+<?php
+declare(strict_types=1);
+return [
+    'plugins' => [
+        'TestPlugin' => '/config/path',
+        'OtherPlugin' => '/config/path'
+    ]
+];
+PHP;
+        file_put_contents($this->pluginsListPath, $file);
+
+        $config = <<<PHP
+<?php
+declare(strict_types=1);
+return [
+    'Unknown'
+];
+PHP;
+        file_put_contents($this->pluginsConfigPath, $config);
+
+        $this->expectException(MissingPluginException::class);
+        $this->expectExceptionMessage('Plugin `Unknown` could not be found.');
+
+        $this->exec('plugin list');
+    }
 }

+ 4 - 0
tests/TestCase/Core/PluginConfigTest.php

@@ -231,6 +231,10 @@ PHP;
             'OtherPlugin' => [
                 'isLoaded' => false,
             ],
+            'UnknownPlugin' => [
+                'isLoaded' => false,
+                'isUnknown' => true,
+            ],
         ], $config->getConfig());
     }
 }