Browse Source

Fix auth adapter loading without App.namespace (#16260)

Fix type error when App.namespace config is not set.

Co-authored-by: ADmad <admad.coder@gmail.com>
Michael Hoffmann 4 years ago
parent
commit
7b17f37d58
2 changed files with 19 additions and 5 deletions
  1. 8 5
      src/Core/App.php
  2. 11 0
      tests/TestCase/Core/AppTest.php

+ 8 - 5
src/Core/App.php

@@ -59,13 +59,16 @@ class App
         }
 
         [$plugin, $name] = pluginSplit($class);
-        $base = $plugin ?: Configure::read('App.namespace');
-        $base = str_replace('/', '\\', rtrim($base, '\\'));
         $fullname = '\\' . str_replace('/', '\\', $type . '\\' . $name) . $suffix;
 
-        if (static::_classExistsInBase($fullname, $base)) {
-            /** @var class-string */
-            return $base . $fullname;
+        $base = $plugin ?: Configure::read('App.namespace');
+        if ($base !== null) {
+            $base = str_replace('/', '\\', rtrim($base, '\\'));
+
+            if (static::_classExistsInBase($fullname, $base)) {
+                /** @var class-string */
+                return $base . $fullname;
+            }
         }
 
         if ($plugin || !static::_classExistsInBase($fullname, 'Cake')) {

+ 11 - 0
tests/TestCase/Core/AppTest.php

@@ -73,6 +73,17 @@ class AppTest extends TestCase
     }
 
     /**
+     * @link https://github.com/cakephp/cakephp/issues/16258
+     */
+    public function testClassNameWithAppNamespaceUnset(): void
+    {
+        Configure::delete('App.namespace');
+
+        $result = App::className('Mysql', 'Database/Driver');
+        $this->assertSame(Mysql::class, $result);
+    }
+
+    /**
      * testShortName
      *
      * @param string $class Class name