diff --git a/src/Commands/Application/Concerns/InteractsWithConsoleInApplication.php b/src/Commands/Application/Concerns/InteractsWithConsoleInApplication.php deleted file mode 100644 index a061747..0000000 --- a/src/Commands/Application/Concerns/InteractsWithConsoleInApplication.php +++ /dev/null @@ -1,30 +0,0 @@ -getNamespace()) - ); - } - - public function resolvePlaceholders(): PlaceholderData - { - return new PlaceholderData( - namespace: Str::ucfirst(string: $this->getNamespace()), - class: $this->getClassName(), - ); - } -} diff --git a/src/Commands/Application/DataTransferObjectMakeCommand.php b/src/Commands/Application/DataTransferObjectMakeCommand.php index b972eb3..547780b 100644 --- a/src/Commands/Application/DataTransferObjectMakeCommand.php +++ b/src/Commands/Application/DataTransferObjectMakeCommand.php @@ -3,28 +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 DataTransferObjectMakeCommand extends Command implements Console { - use HasArguments, HasOptions, InteractsWithConsoleInApplication; + use HasArguments, HasOptions, InteractsWithConsole; protected $signature = 'application:make:data-transfer-object {name} {domain} {--force}'; protected $description = 'Create a new Data Transfer Object'; + public function beforeCreate(): void + { + $this->info(string: 'Generating action file to your project'); + } + + public function afterCreate(): void + { + $this->info(string: 'Successfully generate action file'); + } + public function getNamespace(): string { return Source::resolveNamespace( data: new NamespaceData( - structures: Source::resolveApplicationPath() . '\\DataTransferObjects', domainArgument: $this->resolveDomainArgument(), + structures: Source::resolveApplicationPath(), nameArgument: $this->resolveNameArgument(), + endsWith: 'DataTransferObjects', ) ); } @@ -34,13 +46,11 @@ public function getStubPath(): string return Source::resolveStubForPath(name: 'application/data-transfer-object'); } - public function beforeCreate(): void + public function resolvePlaceholders(): PlaceholderData { - $this->info(string: 'Generating data transfer object file to your project'); - } - - public function afterCreate(): void - { - $this->info(string: 'Successfully generate data transfer object file'); + return new PlaceholderData( + namespace: $this->getNamespace(), + class: $this->getClassName(), + ); } } diff --git a/src/Commands/Infrastructure/ProviderMakeCommand.php b/src/Commands/Application/ProviderMakeCommand.php similarity index 85% rename from src/Commands/Infrastructure/ProviderMakeCommand.php rename to src/Commands/Application/ProviderMakeCommand.php index 63c620c..079098d 100644 --- a/src/Commands/Infrastructure/ProviderMakeCommand.php +++ b/src/Commands/Application/ProviderMakeCommand.php @@ -1,6 +1,6 @@ resolveDomainArgument(), + structures: Source::resolveApplicationPath(), nameArgument: $this->resolveNameArgument(), endsWith: 'Providers', ) @@ -44,7 +44,7 @@ public function getNamespace(): string public function getStubPath(): string { - return Source::resolveStubForPath(name: 'infrastructure/provider'); + return Source::resolveStubForPath(name: 'application/provider'); } public function resolvePlaceholders(): PlaceholderData 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/src/Commands/Application/ResourceMakeCommand.php b/src/Commands/Application/ResourceMakeCommand.php index 111ba86..77761c1 100644 --- a/src/Commands/Application/ResourceMakeCommand.php +++ b/src/Commands/Application/ResourceMakeCommand.php @@ -3,10 +3,9 @@ namespace KoalaFacade\DiamondConsole\Commands\Application; use Illuminate\Console\Command; -use Illuminate\Support\Str; -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; @@ -14,48 +13,49 @@ class ResourceMakeCommand extends Command implements Console { - use HasArguments, HasOptions, InteractsWithConsoleInApplication; + use HasArguments, HasOptions, InteractsWithConsole; protected $signature = 'application:make:resource {name} {domain} {--model=} {--force}'; - protected $description = 'Create a new resource'; + protected $description = 'Create a new Resource'; public function beforeCreate(): void { - $this->info(string: 'Generating resource file to your project'); + $this->info(string: 'Generating action file to your project'); } public function afterCreate(): void { - $this->info(string: 'Successfully generate resource file'); + $this->info(string: 'Successfully generate action file'); } public function getNamespace(): string { return Source::resolveNamespace( data: new NamespaceData( - structures: Source::resolveApplicationPath() . '\\Http', - domainArgument: 'Resources\\' . $this->resolveDomainArgument(), + domainArgument: $this->resolveDomainArgument(), + structures: Source::resolveApplicationPath(), nameArgument: $this->resolveNameArgument(), + endsWith: 'Resources', ) ); } public function getStubPath(): string { - $stub = 'application/resource'; + $stubs = 'application/resource'; if ($this->resolveModelOption()) { - $stub .= '-model'; + $stubs .= '-model'; } - return Source::resolveStubForPath(name: $stub); + return Source::resolveStubForPath(name: $stubs); } public function resolvePlaceholders(): PlaceholderData { return new PlaceholderData( - namespace: Str::ucfirst(string: $this->getNamespace()), + namespace: $this->getNamespace(), class: $this->getClassName(), model: $this->resolveModelOption(), modelNamespace: $this->resolveModelNamespace() @@ -67,10 +67,10 @@ public function resolveModelNamespace(): ?string if ($this->resolveModelOption()) { $namespace = Source::resolveNamespace( data: new NamespaceData( - structures: Source::resolveDomainPath(), - domainArgument: 'Shared\\' . $this->resolveDomainArgument(), + domainArgument: $this->resolveDomainArgument(), + structures: Source::resolveInfrastructurePath(), nameArgument: $this->resolveModelOption(), - endsWith: 'Models\\' . $this->resolveModelOption(), + endsWith: 'Database\\Models', ) ); } diff --git a/stubs/infrastructure/provider.stub b/stubs/application/provider.stub similarity index 85% rename from stubs/infrastructure/provider.stub rename to stubs/application/provider.stub index 7a8623b..537ce0a 100644 --- a/stubs/infrastructure/provider.stub +++ b/stubs/application/provider.stub @@ -8,8 +8,6 @@ class {{ class }} extends ServiceProvider { /** * Register services. - * - * @return void */ public function register(): void { @@ -18,8 +16,6 @@ class {{ class }} extends ServiceProvider /** * Bootstrap services. - * - * @return void */ public function boot(): void { diff --git a/stubs/application/resource-model.stub b/stubs/application/resource-model.stub index f8d1217..dd020e1 100644 --- a/stubs/application/resource-model.stub +++ b/stubs/application/resource-model.stub @@ -2,7 +2,7 @@ namespace {{ namespace }}; -use {{ modelNamespace }}; +use {{ modelNamespace }}\{{ model }}; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; diff --git a/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php index a49b47d..25b4d7a 100644 --- a/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.php +++ b/tests/Feature/Commands/Application/DataTransferObjectMakeCommandTest.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 DTO') ->tap(function () { - $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); + $fileName = '/DataTransferObjects/PostData.php'; - expect(value: File::exists(path: $filePath))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install Post'); Artisan::call(command: 'application:make:data-transfer-object PostData Post'); - expect(value: File::exists(path: $filePath))->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $filePath), + haystack: fileGet(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) )->toBeFalse(); @@ -28,18 +27,17 @@ it(description: 'can generate new DTO with separator') ->tap(function () { - $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/Foo/BarData.php'); + $fileName = '/DataTransferObjects/Foo/BarData.php'; - expect(value: File::exists(path: $filePath))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install Post'); Artisan::call(command: 'application:make:data-transfer-object Foo/BarData Post'); - expect(value: File::exists(path: $filePath)) - ->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $filePath), + haystack: fileGet(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) ) @@ -49,18 +47,18 @@ it(description: 'can force generate exists DTO') ->tap(function () { - $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); + $fileName = '/DataTransferObjects/PostData.php'; - expect(value: File::exists(path: $filePath))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install Post'); Artisan::call(command: 'application:make:data-transfer-object PostData Post'); Artisan::call(command: 'application:make:data-transfer-object PostData Post --force'); - expect(value: File::exists(path: $filePath))->toBeTrue() + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeTrue() ->and( value: Str::contains( - haystack: File::get(path: $filePath), + haystack: fileGet(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()), needles: ['{{ class }}', '{{ namespace }}'] ) )->toBeFalse(); @@ -69,16 +67,18 @@ it(description: 'cannot generate the DTO, if the DTO already exists') ->tap(function () { - $filePath = base_path(path: applicationPath() . '/DataTransferObjects/Post/PostData.php'); + $fileName = '/DataTransferObjects/PostData.php'; - expect(value: File::exists(path: $filePath))->toBeFalse(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeFalse(); - Artisan::call(command: 'diamond:install'); + Artisan::call(command: 'domain:install Post'); Artisan::call(command: 'application:make:data-transfer-object PostData Post'); - expect(value: File::exists(path: $filePath))->toBeTrue(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeTrue(); Artisan::call(command: 'application:make:data-transfer-object PostData Post'); + + expect(value: fileExists(relativeFileName: $fileName, domain: 'Post', prefix: applicationPath()))->toBeTrue(); }) ->group(groups: 'commands') ->throws(exception: FileAlreadyExistException::class); diff --git a/tests/Feature/Commands/Application/ProviderMakeCommandTest.php b/tests/Feature/Commands/Application/ProviderMakeCommandTest.php new file mode 100644 index 0000000..b0b1b9a --- /dev/null +++ b/tests/Feature/Commands/Application/ProviderMakeCommandTest.php @@ -0,0 +1,62 @@ +tap(function () { + $fileName = '/Providers/FactoryServiceProvider.php'; + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); + + Artisan::call(command: 'domain:install User'); + Artisan::call(command: 'application:make:provider Factory User'); + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue() + ->and( + Str::contains( + haystack: $fileName, + needles: ['{{ class }}', '{{ namespace }}'] + ) + )->toBeFalse(); + }) + ->group(groups: 'commands'); + +it('can generate new Service Provider file with force') + ->tap(function () { + $fileName = '/Providers/FactoryServiceProvider.php'; + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); + + Artisan::call(command: 'domain:install User'); + Artisan::call(command: 'application:make:provider Factory User'); + Artisan::call(command: 'application:make:provider Factory User --force'); + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue() + ->and( + Str::contains( + haystack: $fileName, + needles: ['{{ class }}', '{{ namespace }}'] + ) + )->toBeFalse(); + }) + ->group(groups: 'commands'); + +it(description: 'cannot generate the Service Provider, if the Service Provider already exists') + ->tap(function () { + $fileName = '/Providers/FactoryServiceProvider.php'; + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); + + Artisan::call(command: 'domain:install User'); + Artisan::call(command: 'application:make:provider FactoryServiceProvider User'); + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue(); + + Artisan::call(command: 'application:make:provider FactoryServiceProvider User'); + + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeFalse(); + }) + ->group(groups: 'commands') + ->throws(exception: FileAlreadyExistException::class); 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); diff --git a/tests/Feature/Commands/Application/ResourceMakeCommandTest.php b/tests/Feature/Commands/Application/ResourceMakeCommandTest.php index 6139885..74b4b38 100644 --- a/tests/Feature/Commands/Application/ResourceMakeCommandTest.php +++ b/tests/Feature/Commands/Application/ResourceMakeCommandTest.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 Resource class') ->tap(function () { - $fileName = app_path(path: 'Http/Resources/User/UserResource.php'); + $fileName = 'Resources/UserResource.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:resource UserResource User --model=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 }}', '{{ model }}', '{{ modelNamespace }}'] ) )->toBeFalse(); @@ -28,17 +27,17 @@ it(description: 'can generate new Resource class with separator') ->tap(function () { - $fileName = app_path(path: 'Http/Resources/User/Foo/BarResource.php'); + $fileName = 'Resources/Foo/BarResource.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:resource Foo/BarResource User --model=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 }}', '{{ model }}', '{{ modelNamespace }}'] ) )->toBeFalse(); @@ -47,18 +46,18 @@ it(description: 'can force generate exists Resource class') ->tap(function () { - $fileName = app_path(path: 'Http/Resources/User/UserResource.php'); + $fileName = 'Resources/UserResource.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:resource UserResource User --model=User'); Artisan::call(command: 'application:make:resource UserResource User --model=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 }}', '{{ model }}', '{{ modelNamespace }}'] ) )->toBeFalse(); @@ -67,18 +66,18 @@ it(description: 'cannot generate the Resource, if the Resource already exists') ->tap(function () { - $fileName = app_path(path: 'Http/Resources/User/UserResource.php'); + $fileName = 'Resources/UserResource.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:resource UserResource User --model=User'); - expect(value: File::exists(path: $fileName))->toBeTrue(); + expect(value: fileExists(relativeFileName: $fileName, domain: 'User', prefix: applicationPath()))->toBeTrue(); Artisan::call(command: 'application:make:resource UserResource User --model=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); diff --git a/tests/Feature/Commands/Infrastructure/ProviderMakeCommandTest.php b/tests/Feature/Commands/Infrastructure/ProviderMakeCommandTest.php deleted file mode 100644 index 2947f13..0000000 --- a/tests/Feature/Commands/Infrastructure/ProviderMakeCommandTest.php +++ /dev/null @@ -1,62 +0,0 @@ -tap(function () { - $fileName = '/User/Providers/FactoryServiceProvider.php'; - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'infrastructure:make:provider Factory User'); - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeTrue() - ->and( - Str::contains( - haystack: $fileName, - needles: ['{{ class }}', '{{ namespace }}'] - ) - )->toBeFalse(); - }) - ->group(groups: 'commands'); - -it('can generate new Service Provider file with force') - ->tap(function () { - $fileName = '/User/Providers/FactoryServiceProvider.php'; - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'infrastructure:make:provider Factory User'); - Artisan::call(command: 'infrastructure:make:provider Factory User --force'); - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeTrue() - ->and( - Str::contains( - haystack: $fileName, - needles: ['{{ class }}', '{{ namespace }}'] - ) - )->toBeFalse(); - }) - ->group(groups: 'commands'); - -it(description: 'cannot generate the Service Provider, if the Service Provider already exists') - ->tap(function () { - $fileName = '/User/Providers/FactoryServiceProvider.php'; - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeFalse(); - - Artisan::call(command: 'diamond:install'); - Artisan::call(command: 'infrastructure:make:provider FactoryServiceProvider User'); - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeTrue(); - - Artisan::call(command: 'infrastructure:make:provider FactoryServiceProvider User'); - - expect(value: fileExists(relativeFileName: $fileName, prefix: infrastructurePath()))->toBeFalse(); - }) - ->group(groups: 'commands') - ->throws(exception: FileAlreadyExistException::class);