diff --git a/src/Commands/Application/RequestMakeCommand.php b/src/Commands/Application/RequestMakeCommand.php index 886c71b..11f5536 100644 --- a/src/Commands/Application/RequestMakeCommand.php +++ b/src/Commands/Application/RequestMakeCommand.php @@ -3,38 +3,40 @@ namespace KoalaFacade\DiamondConsole\Commands\Application; use Illuminate\Console\Command; -use KoalaFacade\DiamondConsole\Commands\Application\Concerns\InteractsWithConsoleInApplication; use KoalaFacade\DiamondConsole\Commands\Concerns\HasArguments; use KoalaFacade\DiamondConsole\Commands\Concerns\HasOptions; +use KoalaFacade\DiamondConsole\Commands\Concerns\InteractsWithConsole; use KoalaFacade\DiamondConsole\Contracts\Console; use KoalaFacade\DiamondConsole\DataTransferObjects\NamespaceData; +use KoalaFacade\DiamondConsole\DataTransferObjects\PlaceholderData; use KoalaFacade\DiamondConsole\Support\Source; class RequestMakeCommand extends Command implements Console { - use HasArguments, HasOptions, InteractsWithConsoleInApplication; + use HasArguments, HasOptions, InteractsWithConsole; protected $signature = 'application:make:request {name} {domain} {--force}'; - protected $description = 'Create a new request'; + protected $description = 'Create a new Request'; public function beforeCreate(): void { - $this->info(string: 'Generating request file to your project'); + $this->info(string: 'Generating action file to your project'); } public function afterCreate(): void { - $this->info(string: 'Successfully generate request file'); + $this->info(string: 'Successfully generate action file'); } public function getNamespace(): string { return Source::resolveNamespace( data: new NamespaceData( - structures: Source::resolveApplicationPath() . '\\Http', - domainArgument: 'Requests\\' . $this->resolveDomainArgument(), + domainArgument: $this->resolveDomainArgument(), + structures: Source::resolveApplicationPath(), nameArgument: $this->resolveNameArgument(), + endsWith: 'Requests', ) ); } @@ -43,4 +45,12 @@ public function getStubPath(): string { return Source::resolveStubForPath(name: 'application/request'); } + + public function resolvePlaceholders(): PlaceholderData + { + return new PlaceholderData( + namespace: $this->getNamespace(), + class: $this->getClassName(), + ); + } } diff --git a/tests/Feature/Commands/Application/RequestMakeCommandTest.php b/tests/Feature/Commands/Application/RequestMakeCommandTest.php index 42de53d..0a8e52e 100644 --- a/tests/Feature/Commands/Application/RequestMakeCommandTest.php +++ b/tests/Feature/Commands/Application/RequestMakeCommandTest.php @@ -3,23 +3,22 @@ namespace Tests\Feature\Commands; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException; it(description: 'can generate new Request class') ->tap(function () { - $fileName = app_path(path: 'Http/Requests/User/StoreUserRequest.php'); + $fileName = 'Requests/StoreUserRequest.php'; - expect(value: File::exists(path: $fileName))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install User'); Artisan::call(command: 'application:make:request StoreUserRequest User'); - expect(value: File::exists(path: $fileName))->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $fileName), + haystack: fileGet(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) )->toBeFalse(); @@ -28,17 +27,17 @@ it(description: 'can generate new Request class with separator') ->tap(function () { - $fileName = app_path(path: 'Http/Requests/User/Foo/BarRequest.php'); + $fileName = 'Requests/Foo/BarRequest.php'; - expect(value: File::exists(path: $fileName))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install User'); Artisan::call(command: 'application:make:request Foo/BarRequest User'); - expect(value: File::exists(path: $fileName))->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $fileName), + haystack: fileGet(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) )->toBeFalse(); @@ -47,18 +46,18 @@ it(description: 'can force generate exists Request class') ->tap(function () { - $fileName = app_path(path: 'Http/Requests/User/StoreUserRequest.php'); + $fileName = 'Requests/StoreUserRequest.php'; - expect(value: File::exists(path: $fileName))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install User'); Artisan::call(command: 'application:make:request StoreUserRequest User'); Artisan::call(command: 'application:make:request StoreUserRequest User --force'); - expect(value: File::exists(path: $fileName))->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $fileName), + haystack: fileGet(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) )->toBeFalse(); @@ -67,18 +66,18 @@ it(description: 'cannot generate the Request, if the Request already exists') ->tap(function () { - $fileName = app_path(path: 'Http/Requests/User/StoreUserRequest.php'); + $fileName = 'Requests/StoreUserRequest.php'; - expect(value: File::exists(path: $fileName))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install User'); Artisan::call(command: 'application:make:request StoreUserRequest User'); - expect(value: File::exists(path: $fileName))->toBeTrue(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue(); Artisan::call(command: 'application:make:request StoreUserRequest User'); - expect(value: File::exists(path: $fileName))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); }) ->group(groups: 'commands') ->throws(exception: FileAlreadyExistException::class);