Browse Source

Ensure plugin path config is loaded for each PluginCollection::findPath() call.

This is necessary primarily for testing because the Configure::clear() call
in TestCase::tearDown() wipes out all configuration including plugin paths config.

Reverts #14860. Closes #14889.
ADmad 5 years ago
parent
commit
e08bbba63f
2 changed files with 6 additions and 1 deletions
  1. 5 0
      src/Core/PluginCollection.php
  2. 1 1
      tests/TestCase/Core/PluginCollectionTest.php

+ 5 - 0
src/Core/PluginCollection.php

@@ -122,6 +122,11 @@ class PluginCollection implements Iterator, Countable
      */
     public function findPath(string $name): string
     {
+        // Ensure plugin config is loaded each time. This is necessary primarily
+        // for testing because the Configure::clear() call in TestCase::tearDown()
+        // wipes out all configuration including plugin paths config.
+        $this->loadConfig();
+
         $path = Configure::read('plugins.' . $name);
         if ($path) {
             return $path;

+ 1 - 1
tests/TestCase/Core/PluginCollectionTest.php

@@ -222,8 +222,8 @@ return [
 PHP;
         file_put_contents($configPath, $file);
 
-        Configure::delete('plugins');
         $plugins = new PluginCollection();
+        Configure::delete('plugins');
         $path = $plugins->findPath('TestPlugin');
         unlink($configPath);