Browse Source

Merge branch '5.x' into 5.next

Corey Taylor 2 years ago
parent
commit
63eda41108
2 changed files with 17 additions and 4 deletions
  1. 2 4
      src/Core/BasePlugin.php
  2. 15 0
      tests/TestCase/ORM/TableTest.php

+ 2 - 4
src/Core/BasePlugin.php

@@ -140,9 +140,8 @@ class BasePlugin implements PluginInterface
         }
         $parts = explode('\\', static::class);
         array_pop($parts);
-        $this->name = implode('/', $parts);
 
-        return $this->name;
+        return $this->name = implode('/', $parts);
     }
 
     /**
@@ -160,9 +159,8 @@ class BasePlugin implements PluginInterface
         if (str_ends_with($path, 'src')) {
             $path = substr($path, 0, -3);
         }
-        $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
 
-        return $this->path;
+        return $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
 
     /**

+ 15 - 0
tests/TestCase/ORM/TableTest.php

@@ -1907,6 +1907,21 @@ class TableTest extends TestCase
     }
 
     /**
+     * Test adding a plugin behavior to a table.
+     */
+    public function testAddBehaviorPlugin(): void
+    {
+        $table = new Table([
+            'table' => 'articles',
+        ]);
+        $result = $table->addBehavior('TestPlugin.PersisterOne', ['some' => 'key']);
+
+        $this->assertSame(['PersisterOne'], $result->behaviors()->loaded());
+        $className = $result->behaviors()->get('PersisterOne')->getConfig('className');
+        $this->assertSame('TestPlugin.PersisterOne', $className);
+    }
+
+    /**
      * Test adding a behavior that is a duplicate.
      */
     public function testAddBehaviorDuplicate(): void