-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module make console command and auto register module command
- Loading branch information
Showing
7 changed files
with
239 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Console\Commands; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class ModuleMakeConsoleCommand extends ModuleMakerCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'module:make:console | ||
{name : The name of the command} | ||
{--module= : Name of module controller should belong to} | ||
{--force : Create the class even if the component already exists}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generate console command for a module'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Console'; | ||
|
||
public function handle() | ||
{ | ||
$module = $this->getModuleInput(); | ||
$filename = Str::studly($this->getNameInput()); | ||
$folder = $this->getFolderPath(); | ||
|
||
$name = $this->qualifyClass($module.'\\'.$folder.'\\'.$filename); | ||
|
||
if (! $path = $this->getFilePath(name: $name, force: $this->option('force'))) { | ||
return true; | ||
} | ||
|
||
$this->generateFile($path, $name); | ||
|
||
} | ||
|
||
protected function logFileCreated(string $path, ?string $type = null) | ||
{ | ||
parent::logFileCreated($path, 'Console command'); | ||
} | ||
|
||
protected function getFolderPath(): string | ||
{ | ||
return 'Console'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class {{ class }} extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = '{{moduleName}}:{{command}}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Tests\Commands; | ||
|
||
use NorbyBaru\Modularize\Tests\MakeCommandTestCase; | ||
|
||
class MakeConsoleCommandTest extends MakeCommandTestCase | ||
{ | ||
public function test_it_should_create_a_console_command() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:console', | ||
parameters: [ | ||
'name' => 'SendEmails', | ||
'--module' => $this->moduleName, | ||
] | ||
)->assertSuccessful(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Console/SendEmails.php'); | ||
} | ||
|
||
public function test_it_should_create_a_console_command_with_force_option() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:console', | ||
parameters: [ | ||
'name' => 'SendEmails', | ||
'--module' => $this->moduleName, | ||
] | ||
)->assertSuccessful(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Console/SendEmails.php'); | ||
|
||
$this->artisan( | ||
command: 'module:make:console', | ||
parameters: [ | ||
'name' => 'SendEmails', | ||
'--module' => $this->moduleName, | ||
'--force' => true, | ||
] | ||
)->assertSuccessful(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Console/SendEmails.php'); | ||
} | ||
|
||
public function test_it_should_fail_to_create_console_command_on_duplicate_filename() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:console', | ||
parameters: [ | ||
'name' => 'SendEmails', | ||
'--module' => $this->moduleName, | ||
] | ||
)->assertSuccessful(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Console/SendEmails.php'); | ||
|
||
$this->artisan( | ||
command: 'module:make:console', | ||
parameters: [ | ||
'name' => 'SendEmails', | ||
'--module' => $this->moduleName, | ||
] | ||
)->assertFailed(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Console/SendEmails.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.