Browse Source

fix PluginConfig not returning an array on non existent config file

Kevin Pfeifer 2 years ago
parent
commit
6ee24dfa5a
2 changed files with 27 additions and 3 deletions
  1. 2 0
      src/Core/PluginConfig.php
  2. 25 3
      tests/TestCase/Core/PluginConfigTest.php

+ 2 - 0
src/Core/PluginConfig.php

@@ -67,6 +67,8 @@ class PluginConfig
         $pluginLoadConfig = @include CONFIG . 'plugins.php';
         if (is_array($pluginLoadConfig)) {
             $pluginLoadConfig = Hash::normalize($pluginLoadConfig);
+        } else {
+            $pluginLoadConfig = [];
         }
 
         $result = [];

+ 25 - 3
tests/TestCase/Core/PluginConfigTest.php

@@ -55,9 +55,7 @@ class PluginConfigTest extends TestCase
         if (file_exists($this->pluginsListPath)) {
             unlink($this->pluginsListPath);
         }
-        if (file_exists($this->pluginsConfigPath)) {
-            file_put_contents($this->pluginsConfigPath, $this->originalPluginsConfigContent);
-        }
+        file_put_contents($this->pluginsConfigPath, $this->originalPluginsConfigContent);
     }
 
     public function testSimpleConfig(): void
@@ -233,4 +231,28 @@ PHP;
             ],
         ], PluginConfig::getAppConfig());
     }
+
+    public function testNoPluginConfig(): void
+    {
+        $file = <<<PHP
+<?php
+return [
+    'plugins' => [
+        'TestPlugin' => '/config/path',
+        'OtherPlugin' => '/config/path',
+    ]
+];
+PHP;
+        file_put_contents($this->pluginsListPath, $file);
+        unlink($this->pluginsConfigPath);
+
+        $this->assertSame([
+            'TestPlugin' => [
+                'isLoaded' => false,
+            ],
+            'OtherPlugin' => [
+                'isLoaded' => false,
+            ],
+        ], PluginConfig::getAppConfig());
+    }
 }