-
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.
- Loading branch information
1 parent
4abae5a
commit 5394d98
Showing
15 changed files
with
692 additions
and
225 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
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,154 @@ | ||
<?php | ||
|
||
/** | ||
* PHP version 8 | ||
* | ||
* @category Library | ||
* @package Middlewares | ||
* @author Made Mas Adi Winata <m45adiwinata@gmail.com> | ||
* @license https://mit-license.org/ MIT License | ||
* @version GIT: 0.0.6 | ||
* @link https://github.com/spotlibs | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spotlibs\PhpLib\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* ControllerMakeCommand | ||
* | ||
* Standard command | ||
* | ||
* @category Console | ||
* @package Commands | ||
* @author Made Mas Adi Winata <m45adiwinata@gmail.com> | ||
* @license https://mit-license.org/ MIT License | ||
* @link https://github.com/spotlibs | ||
*/ | ||
class ControllerMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:controller'; | ||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new controller class'; | ||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Controller'; | ||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
parent::handle(); | ||
$this->createSwagger(); | ||
$this->createTest(); | ||
} | ||
/** | ||
* Create a swagger file controller. | ||
* | ||
* @return void | ||
*/ | ||
protected function createSwagger() | ||
{ | ||
$className = class_basename($this->argument('name')); | ||
$this->call( | ||
'make:controller-swagger', | ||
[ | ||
'name' => $className | ||
] | ||
); | ||
} | ||
/** | ||
* Create a unit test file. | ||
* | ||
* @return void | ||
*/ | ||
protected function createTest() | ||
{ | ||
$className = class_basename($this->argument('name')); | ||
$this->call( | ||
'make:test', | ||
[ | ||
'name' => $className | ||
] | ||
); | ||
} | ||
/** | ||
* Get the destination class path. | ||
* | ||
* @param string $name name of the type | ||
* | ||
* @return string | ||
*/ | ||
protected function getPath($name) | ||
{ | ||
return parent::getPath($name . 'Controller'); | ||
} | ||
/** | ||
* ReplaceClass | ||
* | ||
* @param string $stub filename of stub file | ||
* @param string $name name of the type | ||
* | ||
* @return string|string[] | ||
*/ | ||
protected function replaceClass($stub, $name) | ||
{ | ||
$stub = parent::replaceClass($stub, $name); | ||
$stub = str_replace('DummyUsecase', Str::ucfirst($this->argument('name')) . 'Usecase', $stub); | ||
$stub = str_replace('dummyUsecase', Str::lower($this->argument('name')) . 'Usecase', $stub); | ||
return $stub; | ||
} | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('resource')) { | ||
return __DIR__ . '/stubs/controller.stub'; | ||
} | ||
return __DIR__ . '/stubs/controller.plain.stub'; | ||
} | ||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace namespace of root (generally App) | ||
* | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace . '\Http\Controllers'; | ||
} | ||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
['resource', null, InputOption::VALUE_NONE, 'Generate a resource controller class.'], | ||
]; | ||
} | ||
} |
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,88 @@ | ||
<?php | ||
|
||
/** | ||
* PHP version 8.0.30 | ||
* | ||
* @category Application | ||
* @package Commands | ||
* @author Made Mas Adi Winata <m45adiwinata@gmail.com> | ||
* @license https://mit-license.org/ MIT License | ||
* @version GIT: 0.0.1 | ||
* @link https://brispot.bri.co.id/ | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* CollectionMakeCommand | ||
* | ||
* Custom command | ||
* | ||
* @category Console | ||
* @package Commands | ||
* @author Made Mas Adi Winata <m45adiwinata@gmail.com> | ||
* @license https://mit-license.org/ MIT License | ||
* @link https://brispot.bri.co.id/ | ||
*/ | ||
class TestMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:test'; | ||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new test class'; | ||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Test'; | ||
/** | ||
* Get the destination class path. | ||
* | ||
* @param string $name name of the type | ||
* | ||
* @return string | ||
*/ | ||
protected function getPath($name) | ||
{ | ||
$name = Str::replaceFirst($this->laravel->getNamespace(), '', $name); | ||
return $this->laravel->basePath() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name . 'Test') . '.php'; | ||
} | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('resource')) { | ||
return __DIR__ . '/stubs/test.stub'; | ||
} | ||
return __DIR__ . '/stubs/test.plain.stub'; | ||
} | ||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
['resource', null, InputOption::VALUE_NONE, 'Generate a resource test class.'], | ||
]; | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
/** | ||
* PHP version 8.0.30 | ||
* | ||
* @category Application | ||
* @package Controllers | ||
* @author | ||
* @license https://mit-license.org/ MIT License | ||
* @version GIT: 0.0.1 | ||
* @link https://brispot.bri.co.id/ | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DummyNamespace; | ||
|
||
use stdClass; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use Spotlibs\PhpLib\Exceptions\ParameterException; | ||
use App\Usecases\DummyUsecase; | ||
|
||
/** | ||
* DummyClassController | ||
* | ||
* Request and response handler | ||
* | ||
* @category Collections | ||
* @package Collections | ||
* @author | ||
* @license https://mit-license.org/ MIT License | ||
* @link https://brispot.bri.co.id/ | ||
*/ | ||
class DummyClassController extends Controller | ||
{ | ||
private $dummyUsecase; | ||
private $output; | ||
|
||
public function __construct(DummyUsecase $dummyUsecase) | ||
{ | ||
parent::__construct(); | ||
$this->dummyUsecase = $dummyUsecase; | ||
$this->output = new stdClass(); | ||
$this->output->responseCode = ''; | ||
$this->output->responseDesc = ''; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
/** | ||
* PHP version 8.0.30 | ||
* | ||
* @category Application | ||
* @package Controllers | ||
* @author | ||
* @license https://mit-license.org/ MIT License | ||
* @version GIT: 0.0.1 | ||
* @link https://brispot.bri.co.id/ | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Tests\TestCase; | ||
|
||
class DummyClassTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function createApplication() | ||
{ | ||
return require realpath(env('LARAVEL_BASE_PATH')); | ||
} | ||
|
||
/** @test */ | ||
/** @runInSeparateProcess */ | ||
public function testDummyClassMethod() | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
Oops, something went wrong.