Browse Source

Deprecate $plugin argument for App::path().

ADmad 6 years ago
parent
commit
6214b78e5f
2 changed files with 19 additions and 10 deletions
  1. 9 3
      src/Core/App.php
  2. 10 7
      tests/TestCase/Core/AppTest.php

+ 9 - 3
src/Core/App.php

@@ -170,13 +170,14 @@ class App
      * Will return the value of `App.paths.plugins` config.
      *
      * ```
-     * App::path('Model/Table', 'MyPlugin');
+     * App::path('Model/Table');
      * ```
      *
-     * Will return the path for tables under the 'MyPlugin' plugin.
+     * Will return the path for tables `src/Model/Table`.
      *
      * @param string $type type of path
-     * @param string|null $plugin name of plugin
+     * @param string|null $plugin This argument is deprecated.
+     *   Use \Cake\Core\Plugin::classPath()/templatePath() instead for plugin paths.
      * @return array
      * @link https://book.cakephp.org/3.0/en/core-libraries/app.html#finding-paths-to-namespaces
      */
@@ -190,6 +191,11 @@ class App
             return [APP . $type . DIRECTORY_SEPARATOR];
         }
 
+        deprecationWarning(
+            'Using App::path() with 2nd argument $plugin is deprecated.'
+            . ' Use \Cake\Core\Plugin::classPath()/templatePath() instead.'
+        );
+
         if ($type === 'templates') {
             return [Plugin::templatePath($plugin)];
         }

+ 10 - 7
tests/TestCase/Core/AppTest.php

@@ -220,16 +220,19 @@ class AppTest extends TestCase
      * test path() with a plugin.
      *
      * @return void
+     * @deprecated
      */
     public function testPathWithPlugins()
     {
-        $basepath = TEST_APP . 'Plugin' . DS;
-        $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
-        $result = App::path('Controller', 'TestPlugin');
-        $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'src' . DS . 'Controller' . DS, $result[0]);
-        $result = App::path('Controller', 'Company/TestPluginThree');
-        $expected = $basepath . 'Company' . DS . 'TestPluginThree' . DS . 'src' . DS . 'Controller' . DS;
-        $this->assertPathEquals($expected, $result[0]);
+        $this->deprecated(function () {
+            $basepath = TEST_APP . 'Plugin' . DS;
+            $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
+            $result = App::path('Controller', 'TestPlugin');
+            $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'src' . DS . 'Controller' . DS, $result[0]);
+            $result = App::path('Controller', 'Company/TestPluginThree');
+            $expected = $basepath . 'Company' . DS . 'TestPluginThree' . DS . 'src' . DS . 'Controller' . DS;
+            $this->assertPathEquals($expected, $result[0]);
+        });
     }
 
     /**