Browse Source

Always add long alias for plugin shells.

Always add the long alias for plugin shells for backwards compatibility
reasons. The ShellDispatcher implementatino would allow plugin shells to
either be called with their long name or short name if there were no
conflicts. Because we're building the list ahead of dispatch time we
need to include all the aliases now.

Bump up the logging as not being able to load classes is something
people will want to know.
Mark Story 8 years ago
parent
commit
dd21cada60
2 changed files with 28 additions and 19 deletions
  1. 21 13
      src/Console/CommandCollection.php
  2. 7 6
      tests/TestCase/Console/CommandCollectionTest.php

+ 21 - 13
src/Console/CommandCollection.php

@@ -158,23 +158,31 @@ class CommandCollection implements IteratorAggregate, Countable
         $shells = $scanner->scanAll();
 
         $adder = function ($shells, $key) {
-            if (!empty($shells[$key])) {
-                foreach ($shells[$key] as $info) {
-                    $name = $info['name'];
-                    // If the short name has been used, use the full name.
-                    // This allows app shells to have name preference.
-                    // and app shells to overwrite core shells.
-                    if ($this->has($name) && $name !== $info['fullName']) {
-                        $name = $info['fullName'];
-                    }
-                    try {
-                        $this->add($name, $info['class']);
-                    } catch (InvalidArgumentException $e) {
-                        Log::debug("Could not add {$info['class']} via autodiscovery. " . $e->getMessage());
+            if (empty($shells[$key])) {
+                return;
+            }
+            foreach ($shells[$key] as $info) {
+                $name = $info['name'];
+                $addLong = $name !== $info['fullName'];
+
+                // If the short name has been used, use the full name.
+                // This allows app shells to have name preference.
+                // and app shells to overwrite core shells.
+                if ($this->has($name) && $addLong) {
+                    $name = $info['fullName'];
+                }
+
+                try {
+                    $this->add($name, $info['class']);
+                    if ($addLong) {
+                        $this->add($info['fullName'], $info['class']);
                     }
+                } catch (InvalidArgumentException $e) {
+                    Log::warn("Could not add {$info['class']} via autodiscovery. " . $e->getMessage());
                 }
             }
         };
+
         $adder($shells, 'CORE');
         $adder($shells, 'app');
         foreach (array_keys($shells['plugins']) as $key) {

+ 7 - 6
tests/TestCase/Console/CommandCollectionTest.php

@@ -234,9 +234,9 @@ class CommandCollectionTest extends TestCase
             $collection->has('example'),
             'Used short name for unique plugin shell'
         );
-        $this->assertFalse(
+        $this->assertTrue(
             $collection->has('test_plugin.example'),
-            'Long names not stored for unique shells'
+            'Long names are stored for unique shells'
         );
         $this->assertTrue(
             $collection->has('sample'),
@@ -246,16 +246,17 @@ class CommandCollectionTest extends TestCase
             $collection->has('test_plugin.sample'),
             'Duplicate shell was given a full alias'
         );
-        $this->assertFalse(
-            $collection->has('company/test_plugin_three.company'),
-            'Long names not stored for unique shells'
-        );
         $this->assertTrue(
             $collection->has('company'),
             'Used short name for unique plugin shell'
         );
+        $this->assertTrue(
+            $collection->has('company/test_plugin_three.company'),
+            'Long names are stored as well'
+        );
 
         $this->assertEquals('TestPlugin\Shell\ExampleShell', $collection->get('example'));
+        $this->assertEquals($collection->get('example'), $collection->get('test_plugin.example'));
         $this->assertEquals(
             'TestApp\Shell\SampleShell',
             $collection->get('sample'),