Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow command names to contain number #1207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/system/console/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ protected function prepareVars(): array

// More strict than the base Symfony validateName()
// method, make a PR if it's a problem for you
if (preg_match('/^[a-z]++(:[a-z]++)*$/', $command) !== 1) {
// Plugin and command names can contain a number, but they can't start with it.
if (preg_match('/^[a-z][\w]++(:[a-z][\w]++)*$/', $command) !== 1) {
throw new InvalidArgumentException(sprintf('Command name "%s" is invalid.', $command));
}

Expand Down
44 changes: 44 additions & 0 deletions modules/system/tests/console/CreateCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace System\Tests\Console;

use File;
use InvalidArgumentException;
use System\Tests\Bootstrap\TestCase;

class CreateCommandTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

$this->app->setPluginsPath(base_path() . '/modules/system/tests/fixtures/plugins/');
}

public function testCreatingCommand()
{
$this->artisan('create:command Winter.Tester TestCommand')
->assertExitCode(0);
$this->artisan('create:command Winter.Tester Test1Command')
->assertExitCode(0);

$this->artisan('create:command Winter.Tester4You TestCommand')
->assertExitCode(0);
$this->artisan('create:command Winter.Tester4You Test1Command')
->assertExitCode(0);
}

public function testNotCreatingCommandBeginingWithNumber()
{
$this->artisan('create:command Winter.Tester 1Command')->assertFailed();
$this->artisan('create:command Winter.Tester4You 1Command')->assertFailed();
}

protected function tearDown(): void
{
File::deleteDirectory(plugins_path('winter/tester/console'));
File::deleteDirectory(plugins_path('winter/tester4you'));

parent::tearDown();
}
}
Loading