Browse Source

Simplify pattern and fix mistakes.

Mark Story 7 years ago
parent
commit
b05bc8d4ed

+ 2 - 3
src/Console/CommandCollection.php

@@ -64,10 +64,9 @@ class CommandCollection implements IteratorAggregate, Countable
                 "Cannot use '$class' for command '$name' it is not a subclass of Cake\Console\Shell or Cake\Console\Command."
             );
         }
-        if (!preg_match('/^[\p{L}\p{N}\-_:.]+(?:(?: [\p{L}\p{N}\-_:.]+){1,2})?$/ui', $name)) {
+        if (!preg_match('/^[^\s]+(?:(?: [^\s]+){1,2})?$/ui', $name)) {
             throw new InvalidArgumentException(
-                "The command name `{$name}` is invalid. " .
-                'Names must use only letters/numbers + punctuation characters and be 3 words or fewer.'
+                "The command name `{$name}` is invalid. Names can only be a maximum of three words."
             );
         }
 

+ 2 - 1
tests/TestCase/Console/CommandCollectionTest.php

@@ -20,6 +20,7 @@ use Cake\Core\Plugin;
 use Cake\Shell\I18nShell;
 use Cake\Shell\RoutesShell;
 use Cake\TestSuite\TestCase;
+use InvalidArgumentException;
 use stdClass;
 use TestApp\Command\DemoCommand;
 
@@ -164,7 +165,7 @@ class CommandCollectionTest extends TestCase
     public function testAddCommandInvalidName($name)
     {
         $this->expectException(InvalidArgumentException::class);
-        $this->expectExceptionMessage('Invalid command name');
+        $this->expectExceptionMessage("The command name `$name` is invalid.");
         $collection = new CommandCollection();
         $collection->add($name, DemoCommand::class);
     }