From 66ea649cfa164dddb43222cb8234f85396a31ed9 Mon Sep 17 00:00:00 2001 From: Shavonn Brown Date: Sun, 7 Jan 2024 01:20:06 -0500 Subject: [PATCH] refactoring (#37) --- src/Commands/ArtiMigrationCommand.php | 17 ++- src/Commands/DomainListCommand.php | 8 +- src/Commands/InitMicroserviceCommand.php | 42 +++--- src/Commands/InitStructureCommand.php | 7 +- src/Commands/LaracaGeneratorCommand.php | 58 ++----- src/Commands/MakeCastCommand.php | 9 +- src/Commands/MakeChannelCommand.php | 9 +- src/Commands/MakeCommandCommand.php | 31 ---- src/Commands/MakeComponentCommand.php | 20 ++- src/Commands/MakeConsoleCommand.php | 41 +++++ src/Commands/MakeControllerCommand.php | 20 ++- src/Commands/MakeEnumCommand.php | 7 +- src/Commands/MakeEventCommand.php | 9 +- src/Commands/MakeExceptionCommand.php | 9 +- src/Commands/MakeFactoryCommand.php | 11 +- src/Commands/MakeJobCommand.php | 20 ++- src/Commands/MakeListenerCommand.php | 20 ++- src/Commands/MakeMailCommand.php | 20 ++- src/Commands/MakeMiddlewareCommand.php | 20 ++- src/Commands/MakeModelCommand.php | 22 ++- src/Commands/MakeNotificationCommand.php | 20 ++- src/Commands/MakeObserverCommand.php | 9 +- src/Commands/MakePolicyCommand.php | 9 +- src/Commands/MakeProviderCommand.php | 9 +- src/Commands/MakeRequestCommand.php | 9 +- src/Commands/MakeResourceCommand.php | 9 +- src/Commands/MakeRuleCommand.php | 9 +- src/Commands/MakeScopeCommand.php | 9 +- src/Commands/MakeSeederCommand.php | 11 +- src/Commands/MakeStrategyCommand.php | 44 +++--- src/Commands/MakeTestCommand.php | 18 ++- src/Commands/MakeValueCommand.php | 30 ++-- src/Commands/MakeViewCommand.php | 49 +++++- src/Commands/TestClass.php | 7 + src/Commands/Traits/CreatesView.php | 2 +- src/Commands/Traits/Directable.php | 24 ++- .../Traits/{LaracaCommand.php => Shared.php} | 75 ++++----- src/Commands/Traits/UsesLaravelGenerator.php | 20 +++ src/Commands/stubs/interface.stub | 2 +- src/Exceptions/InvalidConfigKeyException.php | 2 +- src/LaracaServiceProvider.php | 13 +- src/Traits/GetsConfigValues.php | 110 +++++++------- src/Traits/Path.php | 56 +++++++ tests/Feature/ArtiMigrationCommandTest.php | 78 +++++++++- tests/Feature/DomainListTest.php | 12 +- tests/Feature/DomainsTest.php | 11 +- tests/Feature/InitMicroserviceCommandTest.php | 19 ++- tests/Feature/MakeCastCommandTest.php | 64 +++++++- tests/Feature/MakeChannelCommandTest.php | 64 +++++++- tests/Feature/MakeCommandCommandTest.php | 28 ---- tests/Feature/MakeComponentCommandTest.php | 142 ++++++++++++++++++ tests/Feature/MakeConsoleCommandTest.php | 133 ++++++++++++++++ tests/Feature/MakeControllerCommandTest.php | 127 ++++++++++++++-- tests/Feature/MakeEnumCommandTest.php | 64 +++++++- tests/Feature/MakeEventCommandTest.php | 64 +++++++- tests/Feature/MakeExceptionCommandTest.php | 64 +++++++- tests/Feature/MakeFactoryCommandTest.php | 64 +++++++- tests/Feature/MakeJobCommandTest.php | 113 +++++++++++++- tests/Feature/MakeListenerCommandTest.php | 113 +++++++++++++- tests/Feature/MakeMailCommandTest.php | 112 +++++++++++++- tests/Feature/MakeMiddlewareCommandTest.php | 113 +++++++++++++- tests/Feature/MakeModelCommandTest.php | 117 ++++++++++++++- tests/Feature/MakeNotificationCommandTest.php | 113 +++++++++++++- tests/Feature/MakeObserverCommandTest.php | 64 +++++++- tests/Feature/MakePolicyCommandTest.php | 64 +++++++- tests/Feature/MakeProviderCommandTest.php | 64 +++++++- tests/Feature/MakeRequestCommandTest.php | 64 +++++++- tests/Feature/MakeResourceCommandTest.php | 64 +++++++- tests/Feature/MakeRuleCommandTest.php | 64 +++++++- tests/Feature/MakeScopeCommandTest.php | 64 +++++++- tests/Feature/MakeSeederCommandTest.php | 66 +++++++- tests/Feature/MakeStrategyCommandTest.php | 139 ++++++++++++++++- tests/Feature/MakeTestCommandTest.php | 81 ++++++++-- tests/Feature/MakeValueCommandTest.php | 113 +++++++++++++- tests/Feature/MakeViewCommandTest.php | 93 +++++++++++- tests/LaracaTestCase.php | 19 +-- tests/Pest.php | 26 ++-- tests/Unit/ConfigPathTest.php | 8 +- 78 files changed, 2983 insertions(+), 571 deletions(-) delete mode 100644 src/Commands/MakeCommandCommand.php create mode 100644 src/Commands/MakeConsoleCommand.php create mode 100644 src/Commands/TestClass.php rename src/Commands/Traits/{LaracaCommand.php => Shared.php} (50%) create mode 100644 src/Commands/Traits/UsesLaravelGenerator.php create mode 100644 src/Traits/Path.php delete mode 100644 tests/Feature/MakeCommandCommandTest.php create mode 100644 tests/Feature/MakeComponentCommandTest.php create mode 100644 tests/Feature/MakeConsoleCommandTest.php diff --git a/src/Commands/ArtiMigrationCommand.php b/src/Commands/ArtiMigrationCommand.php index 32ed52d..ef3a983 100644 --- a/src/Commands/ArtiMigrationCommand.php +++ b/src/Commands/ArtiMigrationCommand.php @@ -3,7 +3,7 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; use Illuminate\Database\Console\Migrations\MigrateMakeCommand; use Illuminate\Database\Migrations\MigrationCreator; use Illuminate\Support\Composer; @@ -12,10 +12,9 @@ #[AsCommand(name: 'arti:migration')] class ArtiMigrationCommand extends MigrateMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared; /** - * signature * The console command signature. * * @var string @@ -27,6 +26,13 @@ class ArtiMigrationCommand extends MigrateMakeCommand {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths} {--fullpath : Output the full path of the migration (Deprecated)}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Migration'; + /** * Create a new migration install command instance. * @@ -46,19 +52,16 @@ public function __construct(MigrationCreator $creator, Composer $composer) } /** - * getMigrationPath * Get migration path (either specified by '--path' option or default location). */ protected function getMigrationPath(): string { - [$domain, $service] = $this->gatherPathAssets(); - if (! is_null($targetPath = $this->input->getOption('path'))) { return ! $this->usingRealPath() ? $this->laravel->basePath().'/'.$targetPath : $targetPath; } - return self::assembleFullPath('migration', $domain, $service); + return $this->getConfigPathWithOptions('migration'); } } diff --git a/src/Commands/DomainListCommand.php b/src/Commands/DomainListCommand.php index 4df98f9..3fc6f9f 100644 --- a/src/Commands/DomainListCommand.php +++ b/src/Commands/DomainListCommand.php @@ -2,7 +2,7 @@ namespace HandsomeBrown\Laraca\Commands; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Config; @@ -13,7 +13,7 @@ #[AsCommand(name: 'domain:list')] class DomainListCommand extends Command { - use LaracaCommand; + use Shared; /** * The console command name. @@ -51,7 +51,7 @@ public function __construct(Filesystem $files) /** * Execute the console command. * - * @return bool|null + * @return bool|void */ public function handle() { @@ -77,7 +77,5 @@ public function handle() $this->table(['Domain', 'Slug', 'Path'], array_map(function ($domain) { return [$domain['name'], $domain['slug'], $domain['path']]; }, $domains)); - - return Command::SUCCESS; } } diff --git a/src/Commands/InitMicroserviceCommand.php b/src/Commands/InitMicroserviceCommand.php index 75b3f02..15e56dd 100644 --- a/src/Commands/InitMicroserviceCommand.php +++ b/src/Commands/InitMicroserviceCommand.php @@ -3,7 +3,6 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use Illuminate\Console\Command; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; @@ -41,23 +40,14 @@ class InitMicroserviceCommand extends LaracaGeneratorCommand */ protected $serviceName = ''; - /** - * The microservice path. - * - * @var string - */ - protected $servicePath = ''; - /** * Execute the console command. * - * @return bool|null + * @return bool|void */ public function handle() { - $this->serviceName = $this->getClassName($this->input->getArgument('name')); - $servicePath = $this->getFullPath('microservice'); - $this->servicePath = "$servicePath/$this->serviceName"; + $this->serviceName = $this->formatName($this->input->getArgument('name')); if (! parent::handle()) { return false; @@ -74,8 +64,6 @@ public function handle() $this->components->bulletList($this->generated); $this->components->info('Microservice created successfully.'); $this->components->info('Don\'t forget to '.$this->serviceName.'ServiceProvider.php to providers in app.php'); - - return Command::SUCCESS; } /** @@ -83,11 +71,10 @@ public function handle() */ protected function replaceTags(string &$stub, string $name): string { - $namespace = $this->getDefaultNamespace($this->rootNamespace()); - $controllerNamespace = $this->assembleNamespace('controller', null, $this->serviceName); + $controllerNamespace = $this->getConfigNamespace('controller', null, $this->serviceName); $search = ['{{ namespace }}', '{{ slug }}', '{{ service }}', '{{ controller_namespace }}']; - $replace = [$namespace, Str::slug($this->serviceName), $this->serviceName, $controllerNamespace]; + $replace = [$this->getServiceNamespace(), Str::slug($this->serviceName), $this->serviceName, $controllerNamespace]; $stub = str_replace($search, $replace, $stub); @@ -119,7 +106,7 @@ protected function makeDirectories(): void 'view', ]; - $path = $this->servicePath.'/'; + $path = $this->getServicePath().'/'; foreach ($elements as $element) { $dir = ''; @@ -139,7 +126,7 @@ protected function makeDirectories(): void /** * Get the console command arguments. */ - protected function makeProviders() + protected function makeProviders(): void { // RouteServiceProvider $this->makeFile('RouteServiceProvider', __DIR__.'/stubs/serviceprovider-route.stub'); @@ -157,9 +144,9 @@ protected function makeProviders() */ protected function getPath(string $name): string { - $name = Str::of($name)->replaceFirst($this->getDefaultNamespace($this->rootNamespace()), '')->replace('\\', '/'); + $name = Str::of($name)->replaceFirst($this->getServiceNamespace(), '')->replace('\\', '/'); - $path = $this->servicePath.'/'; + $path = $this->getServicePath().'/'; switch ($name) { case 'BroadcastServiceProvider': @@ -181,13 +168,20 @@ protected function getPath(string $name): string return $path; } - protected function getDefaultNamespace($rootNamespace): string + protected function getServiceNamespace(): string { - $namespace = $this->getFullNamespace('microservice'); + $namespace = $this->getConfigNamespaceWithOptions($this->configKey); return "$namespace\\$this->serviceName"; } + protected function getServicePath(): string + { + $path = $this->getConfigPathWithOptions($this->configKey); + + return "$path/$this->serviceName"; + } + /** * Determine if the class already exists. * @@ -204,7 +198,7 @@ protected function alreadyExists($rawName) /** * Get the console command arguments. * - * @return array + * @return array> */ protected function getArguments() { diff --git a/src/Commands/InitStructureCommand.php b/src/Commands/InitStructureCommand.php index 098a12f..b6d08e8 100644 --- a/src/Commands/InitStructureCommand.php +++ b/src/Commands/InitStructureCommand.php @@ -26,7 +26,7 @@ class InitStructureCommand extends LaracaGeneratorCommand /** * Execute the console command. * - * @return bool|null + * @return bool|void */ public function handle() { @@ -34,6 +34,7 @@ public function handle() $this->components->info('Creating directory structure from Laraca config.'); + /** @var string $key */ foreach (array_keys($config) as $key) { if ($key == 'domain' && ! $config['domain']['enabled']) { continue; @@ -41,13 +42,11 @@ public function handle() continue; } - $fullPath = self::assembleFullPath($key); + $fullPath = $this->getConfigPathWithOptions($key); $this->makeEmptyDirectory($fullPath); } $this->components->info('Configured structure generated successfully.'); - - return Command::SUCCESS; } } diff --git a/src/Commands/LaracaGeneratorCommand.php b/src/Commands/LaracaGeneratorCommand.php index 7569858..6c68c4d 100644 --- a/src/Commands/LaracaGeneratorCommand.php +++ b/src/Commands/LaracaGeneratorCommand.php @@ -2,7 +2,7 @@ namespace HandsomeBrown\Laraca\Commands; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; @@ -10,7 +10,7 @@ class LaracaGeneratorCommand extends Command { - use LaracaCommand; + use Shared; /** * The filesystem instance. @@ -26,37 +26,17 @@ class LaracaGeneratorCommand extends Command */ protected $type; - /** - * Config key. - * - * @var string - */ - protected $key; - /** * Generated files. * - * @var array + * @var array */ protected $generated = []; - /** - * Create a new controller creator command instance. - * - * @return void - */ - public function __construct(Filesystem $files) - { - parent::__construct(); - - $this->key = strtolower($this->type); - $this->files = $files; - } - /** * Execute the console command. * - * @return bool|null + * @return bool|void * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ @@ -91,11 +71,8 @@ protected function makeDirectory($path) /** * Build the directory for the class if necessary. - * - * @param string $path - * @return string */ - protected function makeEmptyDirectory($path) + protected function makeEmptyDirectory(string $path): string { $this->makeDirectory($path); @@ -115,11 +92,11 @@ protected function makeEmptyDirectory($path) * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - protected function build($name, $stub) + protected function buildClass($name, $stub) { $stub = $this->files->get($stub); - return $this->replaceNamespace($stub, $name); + return $this->replaceTags($stub, $name); } /** @@ -152,7 +129,7 @@ protected function makeFile($name, $stub) protected function replaceTags(string &$stub, string $name): string { $search = ['{{ namespace }}', '{{ class }}']; - $replace = [$this->assembleNamespace($this->key), $name]; + $replace = [$this->getConfigNamespaceWithOptions($this->configKey), $name]; $stub = str_replace($search, $replace, $stub); @@ -166,18 +143,7 @@ protected function getPath(string $name): string { $name = Str::of($name)->replaceFirst($this->rootNamespace(), '')->replace('\\', '/'); - return self::assembleFullPath($this->key)."/$name.php"; - } - - /** - * Get the default namespace for the class. - * - * @param string $rootNamespace - * @return string - */ - protected function getDefaultNamespace($rootNamespace) - { - return $this->getFullNamespace($this->key); + return $this->getConfigPathWithOptions($this->configKey)."/$name.php"; } /** @@ -188,7 +154,7 @@ protected function getDefaultNamespace($rootNamespace) */ protected function alreadyExists($rawName) { - return $this->files->exists($this->getPath($this->getClassName($rawName))); + return $this->files->exists($this->getPath($this->formatName($rawName))); } /** @@ -198,13 +164,13 @@ protected function alreadyExists($rawName) */ protected function rootNamespace() { - return $this->laravel->getNamespace(); + return app()->getNamespace(); } /** * Get the console command options. * - * @return array + * @return array> */ protected function getOptions() { diff --git a/src/Commands/MakeCastCommand.php b/src/Commands/MakeCastCommand.php index 46586b9..42dcd10 100644 --- a/src/Commands/MakeCastCommand.php +++ b/src/Commands/MakeCastCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\CastMakeCommand; class MakeCastCommand extends CastMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeCastCommand extends CastMakeCommand protected $name = 'make:cast'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('cast'); + return $this->getConfigNamespaceWithOptions('cast'); } } diff --git a/src/Commands/MakeChannelCommand.php b/src/Commands/MakeChannelCommand.php index 8d40656..aa50fdb 100644 --- a/src/Commands/MakeChannelCommand.php +++ b/src/Commands/MakeChannelCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ChannelMakeCommand; class MakeChannelCommand extends ChannelMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeChannelCommand extends ChannelMakeCommand protected $name = 'make:channel'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('channel'); + return $this->getConfigNamespaceWithOptions('channel'); } } diff --git a/src/Commands/MakeCommandCommand.php b/src/Commands/MakeCommandCommand.php deleted file mode 100644 index 562af47..0000000 --- a/src/Commands/MakeCommandCommand.php +++ /dev/null @@ -1,31 +0,0 @@ -getFullNamespace('command'); - } -} diff --git a/src/Commands/MakeComponentCommand.php b/src/Commands/MakeComponentCommand.php index 7cde77c..785c20f 100644 --- a/src/Commands/MakeComponentCommand.php +++ b/src/Commands/MakeComponentCommand.php @@ -4,16 +4,16 @@ use HandsomeBrown\Laraca\Commands\Traits\CreatesView; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ComponentMakeCommand; class MakeComponentCommand extends ComponentMakeCommand { use CreatesView; - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -21,13 +21,23 @@ class MakeComponentCommand extends ComponentMakeCommand protected $name = 'make:component'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('component'); + return $this->getConfigNamespaceWithOptions('component'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeConsoleCommand.php b/src/Commands/MakeConsoleCommand.php new file mode 100644 index 0000000..ef52231 --- /dev/null +++ b/src/Commands/MakeConsoleCommand.php @@ -0,0 +1,41 @@ +getConfigNamespaceWithOptions('command'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); + } +} diff --git a/src/Commands/MakeControllerCommand.php b/src/Commands/MakeControllerCommand.php index c5beeb9..a6ed1a9 100644 --- a/src/Commands/MakeControllerCommand.php +++ b/src/Commands/MakeControllerCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Routing\Console\ControllerMakeCommand; class MakeControllerCommand extends ControllerMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeControllerCommand extends ControllerMakeCommand protected $name = 'make:controller'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('controller'); + return $this->getConfigNamespaceWithOptions('controller'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeEnumCommand.php b/src/Commands/MakeEnumCommand.php index 1321074..000c30c 100644 --- a/src/Commands/MakeEnumCommand.php +++ b/src/Commands/MakeEnumCommand.php @@ -3,14 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Console\GeneratorCommand; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'make:enum')] class MakeEnumCommand extends GeneratorCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** * The console command name. @@ -51,6 +52,6 @@ protected function getStub() */ protected function getDefaultNamespace($rootNamespace) { - return $this->getFullNamespace('enum'); + return $this->getConfigNamespaceWithOptions('enum'); } } diff --git a/src/Commands/MakeEventCommand.php b/src/Commands/MakeEventCommand.php index 2bacb10..5950c78 100644 --- a/src/Commands/MakeEventCommand.php +++ b/src/Commands/MakeEventCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\EventMakeCommand; class MakeEventCommand extends EventMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeEventCommand extends EventMakeCommand protected $name = 'make:event'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('event'); + return $this->getConfigNamespaceWithOptions('event'); } } diff --git a/src/Commands/MakeExceptionCommand.php b/src/Commands/MakeExceptionCommand.php index 5e67b2a..a12bfa7 100644 --- a/src/Commands/MakeExceptionCommand.php +++ b/src/Commands/MakeExceptionCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ExceptionMakeCommand; class MakeExceptionCommand extends ExceptionMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeExceptionCommand extends ExceptionMakeCommand protected $name = 'make:exception'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('exception'); + return $this->getConfigNamespaceWithOptions('exception'); } } diff --git a/src/Commands/MakeFactoryCommand.php b/src/Commands/MakeFactoryCommand.php index 2d9122e..f6b8a56 100644 --- a/src/Commands/MakeFactoryCommand.php +++ b/src/Commands/MakeFactoryCommand.php @@ -3,16 +3,16 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Database\Console\Factories\FactoryMakeCommand; use Illuminate\Support\Str; class MakeFactoryCommand extends FactoryMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -28,17 +28,16 @@ protected function getPath($name): string { $name = Str::of($name)->replaceFirst($this->rootNamespace(), '')->finish('Factory'); - return self::assembleFullPath('factory')."/$name.php"; + return $this->getConfigPathWithOptions('factory')."/$name.php"; } /** - * getNamespace * Get the full namespace for a given class, without the class name. * * @param string $name */ protected function getNamespace($name) { - return $this->getFullNamespace('factory'); + return $this->getConfigNamespaceWithOptions('factory'); } } diff --git a/src/Commands/MakeJobCommand.php b/src/Commands/MakeJobCommand.php index 8564e74..9425ffb 100644 --- a/src/Commands/MakeJobCommand.php +++ b/src/Commands/MakeJobCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\JobMakeCommand; class MakeJobCommand extends JobMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeJobCommand extends JobMakeCommand protected $name = 'make:job'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('job'); + return $this->getConfigNamespaceWithOptions('job'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeListenerCommand.php b/src/Commands/MakeListenerCommand.php index 837cdc1..cfd8c40 100644 --- a/src/Commands/MakeListenerCommand.php +++ b/src/Commands/MakeListenerCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ListenerMakeCommand; class MakeListenerCommand extends ListenerMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeListenerCommand extends ListenerMakeCommand protected $name = 'make:listener'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('listener'); + return $this->getConfigNamespaceWithOptions('listener'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeMailCommand.php b/src/Commands/MakeMailCommand.php index c80861d..8d3756a 100644 --- a/src/Commands/MakeMailCommand.php +++ b/src/Commands/MakeMailCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\MailMakeCommand; class MakeMailCommand extends MailMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeMailCommand extends MailMakeCommand protected $name = 'make:mail'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('mail'); + return $this->getConfigNamespaceWithOptions('mail'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeMiddlewareCommand.php b/src/Commands/MakeMiddlewareCommand.php index fecffee..a5c7f0e 100644 --- a/src/Commands/MakeMiddlewareCommand.php +++ b/src/Commands/MakeMiddlewareCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Routing\Console\MiddlewareMakeCommand; class MakeMiddlewareCommand extends MiddlewareMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeMiddlewareCommand extends MiddlewareMakeCommand protected $name = 'make:middleware'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('middleware'); + return $this->getConfigNamespaceWithOptions('middleware'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeModelCommand.php b/src/Commands/MakeModelCommand.php index 3e83b7b..fc4fca4 100644 --- a/src/Commands/MakeModelCommand.php +++ b/src/Commands/MakeModelCommand.php @@ -3,16 +3,16 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ModelMakeCommand; use Symfony\Component\Console\Input\InputOption; class MakeModelCommand extends ModelMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -20,7 +20,6 @@ class MakeModelCommand extends ModelMakeCommand protected $name = 'make:model'; /** - * getStub * Get the stub file for the generator. */ protected function getStub(): string @@ -53,18 +52,16 @@ protected function getStub(): string } /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('model'); + return $this->getConfigNamespaceWithOptions('model'); } /** - * getOptions * Get the console command options. * * @return array> @@ -75,4 +72,15 @@ protected function getOptions(): array ['uuid', null, InputOption::VALUE_NONE, 'Create an Eloquent model with a uuid as the primary key.'], ]); } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); + } } diff --git a/src/Commands/MakeNotificationCommand.php b/src/Commands/MakeNotificationCommand.php index a59ff88..2b085db 100644 --- a/src/Commands/MakeNotificationCommand.php +++ b/src/Commands/MakeNotificationCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\NotificationMakeCommand; class MakeNotificationCommand extends NotificationMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,23 @@ class MakeNotificationCommand extends NotificationMakeCommand protected $name = 'make:notification'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('notification'); + return $this->getConfigNamespaceWithOptions('notification'); + } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeObserverCommand.php b/src/Commands/MakeObserverCommand.php index c685151..541e7fd 100644 --- a/src/Commands/MakeObserverCommand.php +++ b/src/Commands/MakeObserverCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ObserverMakeCommand; class MakeObserverCommand extends ObserverMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeObserverCommand extends ObserverMakeCommand protected $name = 'make:observer'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('observer'); + return $this->getConfigNamespaceWithOptions('observer'); } } diff --git a/src/Commands/MakePolicyCommand.php b/src/Commands/MakePolicyCommand.php index 0802189..f7d4ce2 100644 --- a/src/Commands/MakePolicyCommand.php +++ b/src/Commands/MakePolicyCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\PolicyMakeCommand; class MakePolicyCommand extends PolicyMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakePolicyCommand extends PolicyMakeCommand protected $name = 'make:policy'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('policy'); + return $this->getConfigNamespaceWithOptions('policy'); } } diff --git a/src/Commands/MakeProviderCommand.php b/src/Commands/MakeProviderCommand.php index ec731a8..21df835 100644 --- a/src/Commands/MakeProviderCommand.php +++ b/src/Commands/MakeProviderCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ProviderMakeCommand; class MakeProviderCommand extends ProviderMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeProviderCommand extends ProviderMakeCommand protected $name = 'make:provider'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('provider'); + return $this->getConfigNamespaceWithOptions('provider'); } } diff --git a/src/Commands/MakeRequestCommand.php b/src/Commands/MakeRequestCommand.php index f42a875..9ca9b6e 100644 --- a/src/Commands/MakeRequestCommand.php +++ b/src/Commands/MakeRequestCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\RequestMakeCommand; class MakeRequestCommand extends RequestMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeRequestCommand extends RequestMakeCommand protected $name = 'make:request'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('request'); + return $this->getConfigNamespaceWithOptions('request'); } } diff --git a/src/Commands/MakeResourceCommand.php b/src/Commands/MakeResourceCommand.php index 0bbe50c..b75e92c 100644 --- a/src/Commands/MakeResourceCommand.php +++ b/src/Commands/MakeResourceCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ResourceMakeCommand; class MakeResourceCommand extends ResourceMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeResourceCommand extends ResourceMakeCommand protected $name = 'make:resource'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('resource'); + return $this->getConfigNamespaceWithOptions('resource'); } } diff --git a/src/Commands/MakeRuleCommand.php b/src/Commands/MakeRuleCommand.php index 4da84de..e8f82e1 100644 --- a/src/Commands/MakeRuleCommand.php +++ b/src/Commands/MakeRuleCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\RuleMakeCommand; class MakeRuleCommand extends RuleMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeRuleCommand extends RuleMakeCommand protected $name = 'make:rule'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('rule'); + return $this->getConfigNamespaceWithOptions('rule'); } } diff --git a/src/Commands/MakeScopeCommand.php b/src/Commands/MakeScopeCommand.php index 72a2e76..83115d5 100644 --- a/src/Commands/MakeScopeCommand.php +++ b/src/Commands/MakeScopeCommand.php @@ -3,15 +3,15 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\ScopeMakeCommand; class MakeScopeCommand extends ScopeMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -19,13 +19,12 @@ class MakeScopeCommand extends ScopeMakeCommand protected $name = 'make:scope'; /** - * getDefaultNamespace * Get the default namespace for the class. * * @param string $rootNamespace */ protected function getDefaultNamespace($rootNamespace): string { - return $this->getFullNamespace('scope'); + return $this->getConfigNamespaceWithOptions('scope'); } } diff --git a/src/Commands/MakeSeederCommand.php b/src/Commands/MakeSeederCommand.php index 37e9de4..29c7009 100644 --- a/src/Commands/MakeSeederCommand.php +++ b/src/Commands/MakeSeederCommand.php @@ -3,16 +3,16 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Database\Console\Seeds\SeederMakeCommand; use Illuminate\Support\Str; class MakeSeederCommand extends SeederMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -28,15 +28,14 @@ protected function getPath($name): string { $name = Str::of($name)->replaceFirst($this->rootNamespace(), '')->replace('\\', '/'); - return self::assembleFullPath('seeder')."/$name.php"; + return $this->getConfigPathWithOptions('seeder')."/$name.php"; } /** - * rootNamespace * Get the root namespace for the class. */ protected function rootNamespace(): string { - return $this->getFullNamespace('seeder'); + return $this->getConfigNamespaceWithOptions('seeder'); } } diff --git a/src/Commands/MakeStrategyCommand.php b/src/Commands/MakeStrategyCommand.php index c8c2004..07fa14e 100644 --- a/src/Commands/MakeStrategyCommand.php +++ b/src/Commands/MakeStrategyCommand.php @@ -3,7 +3,7 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; @@ -12,7 +12,7 @@ #[AsCommand(name: 'make:strategy')] class MakeStrategyCommand extends LaracaGeneratorCommand { - use Directable, LaracaCommand; + use CreatesMatchingTest, Directable, Shared; /** * The console command name. @@ -38,13 +38,14 @@ class MakeStrategyCommand extends LaracaGeneratorCommand /** * Execute the console command. * - * @return bool|null + * @return bool|void * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function handle() { - $name = $this->getClassName($this->input->getArgument('name')); + $name = $this->formatName($this->input->getArgument('name')); + $name = Str::of($name)->endsWith('Strategy') ? $name : Str::of($name)->finish('Strategy'); if (! parent::handle()) { return false; @@ -71,28 +72,14 @@ public function handle() } /** - * Get the class name + * Replace the tags for the given stub. */ - protected function getClassName($name): string - { - $name = parent::getClassName($name); - - return Str::of($name)->endsWith('Strategy') ? $name : Str::of($name)->finish('Strategy'); - } - - /** - * Replace the namespace for the given stub. - * - * @param string $stub - * @param string $name - * @return $this - */ - protected function replaceNamespace(&$stub, $name) + protected function replaceTags(string &$stub, string $name): string { $concreteStrategy = Str::of($name)->start('Type'); $search = ['{{ namespace }}', '{{ class }}', '{{ interface }}']; - $replace = [$this->assembleNamespace('strategy'), $concreteStrategy, $name]; + $replace = [$this->getConfigNamespaceWithOptions('strategy'), $concreteStrategy, $name]; $stub = str_replace($search, $replace, $stub); @@ -107,7 +94,7 @@ protected function replaceNamespace(&$stub, $name) */ protected function alreadyExists($rawName) { - $name = $this->getClassName($rawName); + $name = $this->formatName($rawName); $strategyName = Str::of($name)->endsWith('Strategy') ? $name : Str::of($name)->finish('Strategy'); return $this->files->exists($this->getPath($strategyName)); @@ -116,7 +103,7 @@ protected function alreadyExists($rawName) /** * Get the console command arguments. * - * @return array + * @return array> */ protected function getArguments() { @@ -124,4 +111,15 @@ protected function getArguments() ['name', InputArgument::REQUIRED, 'The name of the '.strtolower($this->type)], ]; } + + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); + } } diff --git a/src/Commands/MakeTestCommand.php b/src/Commands/MakeTestCommand.php index d3e0a73..85aa583 100644 --- a/src/Commands/MakeTestCommand.php +++ b/src/Commands/MakeTestCommand.php @@ -3,16 +3,16 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; use Illuminate\Foundation\Console\TestMakeCommand; use Illuminate\Support\Str; class MakeTestCommand extends TestMakeCommand { - use Directable, LaracaCommand; + use Directable, Shared, UsesLaravelGenerator; /** - * name * The console command name. * * @var string @@ -28,6 +28,16 @@ protected function getPath($name): string { $name = Str::of($name)->replaceFirst($this->rootNamespace(), '')->replace('\\', '/'); - return self::assembleFullPath('test')."/$name.php"; + return $this->getConfigPathWithOptions('test')."$name.php"; + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return $this->getConfigNamespaceWithOptions('test'); } } diff --git a/src/Commands/MakeValueCommand.php b/src/Commands/MakeValueCommand.php index 78f0519..87c220f 100644 --- a/src/Commands/MakeValueCommand.php +++ b/src/Commands/MakeValueCommand.php @@ -3,7 +3,9 @@ namespace HandsomeBrown\Laraca\Commands; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; +use HandsomeBrown\Laraca\Commands\Traits\UsesLaravelGenerator; +use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; @@ -11,7 +13,7 @@ #[AsCommand(name: 'make:value')] class MakeValueCommand extends GeneratorCommand { - use Directable, LaracaCommand; + use CreatesMatchingTest, Directable, Shared, UsesLaravelGenerator; /** * The console command name. @@ -52,24 +54,32 @@ protected function getStub() */ protected function getDefaultNamespace($rootNamespace) { - return $this->getFullNamespace('value'); + return $this->getConfigNamespaceWithOptions('value'); } /** - * Build the class with the given name. + * Replace the class name for the given stub. * + * @param string $stub * @param string $name * @return string - * - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - protected function buildClass($name) + protected function replaceClass($stub, $name) { - $class = parent::buildClass($name); + $class = str_replace($this->getNamespace($name).'\\', '', $name); $classVar = Str::camel($this->getNameInput()); - $class = Str::replace('{{ class_var }}', $classVar, $class); + return str_replace(['{{ class }}', '{{ class_var }}'], [$class, $classVar], $stub); + } - return $class; + /** + * Create the matching test case if requested. + * + * @param string $path + * @return bool + */ + protected function handleTestCreation($path) + { + return $this->makeTest($path); } } diff --git a/src/Commands/MakeViewCommand.php b/src/Commands/MakeViewCommand.php index fc8220a..6525ee9 100644 --- a/src/Commands/MakeViewCommand.php +++ b/src/Commands/MakeViewCommand.php @@ -4,19 +4,60 @@ use HandsomeBrown\Laraca\Commands\Traits\CreatesView; use HandsomeBrown\Laraca\Commands\Traits\Directable; -use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand; +use HandsomeBrown\Laraca\Commands\Traits\Shared; use Illuminate\Foundation\Console\ViewMakeCommand; +use Illuminate\Support\Str; class MakeViewCommand extends ViewMakeCommand { - use CreatesView; - use Directable, LaracaCommand; + use CreatesView, Directable, Shared; /** - * name * The console command name. * * @var string */ protected $name = 'make:view'; + + /** + * Get the destination test case path. + * + * @return string + */ + protected function getTestPath() + { + $testBasePath = Str::of($this->testClassFullyQualifiedName()) + ->replace('\\', '/') + // ->replaceFirst('Test/Tests/Feature', 'test/tests/Feature') + ->replaceFirst('Tests/Feature', 'tests/Feature') + ->replaceFirst('App/', 'app/') + ->append('Test.php') + ->value(); + + return base_path($testBasePath); + } + + /** + * Get the class fully qualified name for the test. + * + * @return string + */ + protected function testClassFullyQualifiedName() + { + $name = Str::of(Str::lower($this->getNameInput()))->replace('.'.$this->option('extension'), ''); + + $namespacedName = Str::of( + Str::of($name) + ->replace('/', ' ') + ->explode(' ') + ->map(fn ($part) => Str::of($part)->ucfirst()) + ->implode('\\') + ) + ->replace(['-', '_'], ' ') + ->explode(' ') + ->map(fn ($part) => Str::of($part)->ucfirst()) + ->implode(''); + + return $this->getConfigNamespaceWithOptions('test', true).'\\Feature\\View\\'.$namespacedName; + } } diff --git a/src/Commands/TestClass.php b/src/Commands/TestClass.php new file mode 100644 index 0000000..04bf3e3 --- /dev/null +++ b/src/Commands/TestClass.php @@ -0,0 +1,7 @@ +assembleFullPath('view'); + $laracaViewsPath = $this->getConfigPathWithOptions('view'); $views = $laracaViewsPath.'/'.$path; } catch (\Throwable $th) { $this->components->info('Using config.view config path.'); diff --git a/src/Commands/Traits/Directable.php b/src/Commands/Traits/Directable.php index 6e71248..22e84b3 100644 --- a/src/Commands/Traits/Directable.php +++ b/src/Commands/Traits/Directable.php @@ -7,26 +7,24 @@ trait Directable { /** - * Get the console command options. + * Add the domain and service options where applicable * - * @return array + * @return void */ - protected function getOptions() + protected function addDirectableOptions() { - $options = parent::getOptions(); - if (self::domainsEnabled()) { - $options = array_merge($options, [ - ['domain', 'dom', InputOption::VALUE_REQUIRED, 'The name of the domain.'], - ]); + $this->getDefinition()->addOption(new InputOption( + 'domain', 'dom', InputOption::VALUE_REQUIRED, + "The name of the domain {$this->type} will be added to." + )); } if (self::microservicesEnabled() && $this->type !== 'Microservice') { - $options = array_merge($options, [ - ['service', 'serv', InputOption::VALUE_REQUIRED, 'The name of the service.'], - ]); + $this->getDefinition()->addOption(new InputOption( + 'service', 'serv', InputOption::VALUE_REQUIRED, + "The name of the service {$this->type} will be added to." + )); } - - return $options; } } diff --git a/src/Commands/Traits/LaracaCommand.php b/src/Commands/Traits/Shared.php similarity index 50% rename from src/Commands/Traits/LaracaCommand.php rename to src/Commands/Traits/Shared.php index ccdc399..71eb9e3 100644 --- a/src/Commands/Traits/LaracaCommand.php +++ b/src/Commands/Traits/Shared.php @@ -3,34 +3,46 @@ namespace HandsomeBrown\Laraca\Commands\Traits; use HandsomeBrown\Laraca\Traits\GetsConfigValues; +use Illuminate\Console\Concerns\CreatesMatchingTest; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; -trait LaracaCommand +trait Shared { use GetsConfigValues; /** - * Parse the class name and format according to the root namespace. + * Config key. * - * @param string $name - * @return string + * @var string */ - protected function qualifyClass($name) + protected $configKey; + + /** + * Create a new controller creator command instance. + * + * @return void + */ + public function __construct(Filesystem $files) { - $name = ucfirst($name); + parent::__construct($files); - return parent::qualifyClass($name); - } + $this->configKey = strtolower($this->type); + $this->files = $files; - public function hasParents() - { - return (bool) class_parents($this); + if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { + $this->addTestOptions(); + } + + if (in_array(Directable::class, class_uses_recursive($this))) { + $this->addDirectableOptions(); + } } /** * Get the class name */ - protected function getClassName($name): string + protected function formatName(string $name): string { $name = ltrim($name, '\\/'); @@ -41,21 +53,25 @@ protected function getClassName($name): string /** * Get domain and service values + * + * @return array */ - protected function gatherPathAssets(): array + protected function getPathAssets(): array { $domain = null; $service = null; if ($this->input->hasOption('domain')) { - $domainName = $this->getClassName($this->input->getOption('domain')); + $domain = $this->input->getOption('domain'); + $domainName = $domain ? $this->formatName($this->input->getOption('domain')) : null; if (self::domainsEnabled() && $domainName) { $domain = $domainName; } } if ($this->input->hasOption('service')) { - $serviceName = $this->getClassName($this->input->getOption('service')); + $service = $this->input->getOption('service'); + $serviceName = $service ? $this->formatName($this->input->getOption('service')) : null; if (self::microservicesEnabled() && $serviceName) { $service = $serviceName; } @@ -66,42 +82,31 @@ protected function gatherPathAssets(): array /** * Get the namespace with the possibility of domain or service flags - * - * @param string $key */ - protected function getFullNamespace($key): string + protected function getConfigNamespaceWithOptions(string $key, bool $withRoot = true): string { - [$domain, $service] = $this->gatherPathAssets(); + [$domain, $service] = $this->getPathAssets(); - return self::assembleNamespace($key, $domain, $service); - } - - /** - * Get the path with the possibility of domain or service flags - * - * @param string $key - */ - protected function getBasePath($key): string - { - return self::assembleBasePath($key); + return $this->getConfigNamespace($key, $domain, $service, $withRoot); } /** * Get the path with the possibility of domain or service flags */ - public function getFullPath(string $key, $withRoot = true): string + protected function getConfigPathWithOptions(string $key, bool $withRoot = true): string { - [$domain, $service] = $this->gatherPathAssets(); + [$domain, $service] = $this->getPathAssets(); - return self::assembleFullPath($key, $domain, $service, $withRoot); + return self::getConfigPath($key, $domain, $service, $withRoot); } /** * Create the matching test case if requested. * * @param string $path + * @return bool */ - protected function handleTestCreation($path): bool + protected function makeTest($path) { if (! $this->option('test') && ! $this->option('pest')) { return false; @@ -114,7 +119,7 @@ protected function handleTestCreation($path): bool '--pest' => $this->option('pest'), ]; - [$domain, $service] = $this->gatherPathAssets(); + [$domain, $service] = $this->getPathAssets(); if ($domain) { $args['--domain'] = $domain; diff --git a/src/Commands/Traits/UsesLaravelGenerator.php b/src/Commands/Traits/UsesLaravelGenerator.php new file mode 100644 index 0000000..0e10c43 --- /dev/null +++ b/src/Commands/Traits/UsesLaravelGenerator.php @@ -0,0 +1,20 @@ +message = 'Invalid configuration key: '.$key; } diff --git a/src/LaracaServiceProvider.php b/src/LaracaServiceProvider.php index 769f919..73c2397 100644 --- a/src/LaracaServiceProvider.php +++ b/src/LaracaServiceProvider.php @@ -8,8 +8,8 @@ use HandsomeBrown\Laraca\Commands\InitStructureCommand; use HandsomeBrown\Laraca\Commands\MakeCastCommand; use HandsomeBrown\Laraca\Commands\MakeChannelCommand; -use HandsomeBrown\Laraca\Commands\MakeCommandCommand; use HandsomeBrown\Laraca\Commands\MakeComponentCommand; +use HandsomeBrown\Laraca\Commands\MakeConsoleCommand; use HandsomeBrown\Laraca\Commands\MakeControllerCommand; use HandsomeBrown\Laraca\Commands\MakeEnumCommand; use HandsomeBrown\Laraca\Commands\MakeEventCommand; @@ -60,7 +60,7 @@ class LaracaServiceProvider extends ServiceProvider 'InitStructure' => InitStructureCommand::class, 'MakeCast' => MakeCastCommand::class, 'MakeChannel' => MakeChannelCommand::class, - 'MakeCommand' => MakeCommandCommand::class, + 'MakeCommand' => MakeConsoleCommand::class, 'MakeComponent' => MakeComponentCommand::class, 'MakeController' => MakeControllerCommand::class, 'MakeEvent' => MakeEventCommand::class, @@ -88,7 +88,6 @@ class LaracaServiceProvider extends ServiceProvider ]; /** - * boot * Bootstrap the application services. */ public function boot(): void @@ -98,7 +97,7 @@ public function boot(): void __DIR__.'/../config/config.php' => config_path('laraca.php'), ], 'laraca-config'); - $this->app->useDatabasePath($this->assembleFullPath('database')); + $this->app->useDatabasePath($this->getConfigPath('database')); if ($this->domainsEnabled() && $this->domainParentDir()) { $this->commands['DomainList'] = DomainListCommand::class; @@ -108,13 +107,12 @@ public function boot(): void $this->registerCommands(); } - $this->loadViewsFrom($this->assembleFullPath('view'), 'laraca'); + $this->loadViewsFrom($this->getConfigPath('view'), 'laraca'); - $this->loadMigrationsFrom($this->assembleFullPath('migration')); + $this->loadMigrationsFrom($this->getConfigPath('migration')); } /** - * register * Register the application services. */ public function register(): void @@ -124,7 +122,6 @@ public function register(): void } /** - * registerCommands * Register the given commands. */ public function registerCommands(): void diff --git a/src/Traits/GetsConfigValues.php b/src/Traits/GetsConfigValues.php index a00213c..e25f47d 100644 --- a/src/Traits/GetsConfigValues.php +++ b/src/Traits/GetsConfigValues.php @@ -10,9 +10,9 @@ trait GetsConfigValues { /** - * Using domains + * If domains are enabled */ - public static function domainsEnabled(): bool + protected static function domainsEnabled(): bool { $domainsEnabled = Config::get('laraca.struct.domain.enabled'); @@ -22,7 +22,7 @@ public static function domainsEnabled(): bool /** * Domain parent dir */ - public static function domainParentDir(): ?string + protected static function domainParentDir(): ?string { $parentDir = Config::get('laraca.struct.domain.path'); @@ -30,9 +30,9 @@ public static function domainParentDir(): ?string } /** - * Using domains + * If microservices are enabled */ - public static function microservicesEnabled(): bool + protected static function microservicesEnabled(): bool { $microservicesEnabled = Config::get('laraca.struct.microservice.enabled'); @@ -40,9 +40,9 @@ public static function microservicesEnabled(): bool } /** - * Domain parent dir + * Microservice parent dir */ - public static function microserviceParentDir(): ?string + protected static function microserviceParentDir(): ?string { $parentDir = Config::get('laraca.struct.microservice.path'); @@ -50,67 +50,58 @@ public static function microserviceParentDir(): ?string } /** - * assembleFullPath + * Return namespace string */ - public static function assembleFullPath(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string + public static function getConfigNamespace(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string { - [$pathArray, $root] = self::assemblePathArray($key, $domain, $service); + $path = self::assemblePathArray($key, $domain, $service); + $pathArray = $path->getArray(); - $path = implode('/', $pathArray); + $pathArray = array_map(function ($dir) { + return str_replace('/', '\\', ucfirst($dir)); + }, $pathArray); - if ($withRoot) { - if ($root == 'app') { - $path = app_path($path); - } elseif ($root == 'base') { - $path = base_path($path); - } + $namespace = implode('\\', $pathArray); + + if ($path->getRoot() == 'app' && $withRoot) { + $namespace = app()->getNamespace().$namespace; } - return $path; + return $namespace; } /** - * assembleBasePath + * Return full path string */ - public static function assembleBasePath(string $key): string + public static function getConfigPath(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string { - [$pathArray, $root] = self::assembleBasePathArray($key); - - $path = implode('/', $pathArray); - - return $path; - } + $path = self::assemblePathArray($key, $domain, $service); + $pathArray = $path->getArray(); - /** - * assembleNamespace - */ - public static function assembleNamespace(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string - { - [$pathArray, $root] = self::assemblePathArray($key, $domain, $service); + $pathStr = implode('/', $pathArray); - $pathArray = array_map(function ($dir) { - return str_replace('/', '\\', ucfirst($dir)); - }, $pathArray); - - $namespace = implode('\\', $pathArray); - - if ($root == 'app' && $withRoot) { - $namespace = app()->getNamespace().$namespace; + if ($withRoot) { + if ($path->getRoot() == 'app') { + $pathStr = app_path($pathStr); + } elseif ($path->getRoot() == 'base') { + $pathStr = base_path($pathStr); + } } - return $namespace; + return $pathStr; } /** - * assemblePathArray + * Return full path as array */ - protected static function assemblePathArray(string $key, ?string $domain = null, ?string $service = null): array + protected static function assemblePathArray(string $key, ?string $domain = null, ?string $service = null): Path { if (! Config::has('laraca.struct.'.$key)) { throw new InvalidConfigKeyException($key); } - [$pathArray, $root] = self::assembleBasePathArray($key); + $path = self::getBasePathArray($key); + $pathArray = $path->getArray(); if (self::microservicesEnabled() || self::domainsEnabled()) { if ($service || $domain) { @@ -118,7 +109,8 @@ protected static function assemblePathArray(string $key, ?string $domain = null, array_unshift($pathArray, ucfirst($service)); if (self::microserviceParentDir()) { - array_unshift($pathArray, self::microserviceParentDir()); + $parentDir = self::microserviceParentDir(); + array_unshift($pathArray, ...explode('/', $parentDir)); } } @@ -126,24 +118,38 @@ protected static function assemblePathArray(string $key, ?string $domain = null, array_unshift($pathArray, ucfirst($domain)); if (self::domainParentDir()) { - array_unshift($pathArray, self::domainParentDir()); + $parentDir = self::domainParentDir(); + array_unshift($pathArray, ...explode('/', $parentDir)); } } - if ($root == 'base') { - $root = 'app'; + if ($path->getRoot() == 'base') { + $path->setRoot('app'); } } } - return [$pathArray, $root]; + return new Path($pathArray, $path->getRoot()); + } + + /** + * Return base path string + */ + public static function getBasePath(string $key): string + { + $path = self::getBasePathArray($key); + $pathArray = $path->getArray(); + + $pathStr = implode('/', $pathArray); + + return $pathStr; } /** - * assemblePathArray + * Return path as array without root */ - protected static function assembleBasePathArray(string $key): array + protected static function getBasePathArray(string $key): Path { if (! Config::has('laraca.struct.'.$key)) { throw new InvalidConfigKeyException($key); @@ -180,6 +186,6 @@ protected static function assembleBasePathArray(string $key): array } while ($done !== true); - return [$pathArray, $root]; + return new Path($pathArray, $root); } } diff --git a/src/Traits/Path.php b/src/Traits/Path.php new file mode 100644 index 0000000..bc016a5 --- /dev/null +++ b/src/Traits/Path.php @@ -0,0 +1,56 @@ + + */ + protected $pathArray = []; + + /** + * Path root name + * + * @var string + */ + protected $root = ''; + + /** + * @param array $pathArray + * @param string $root + */ + public function __construct($pathArray, $root) + { + $this->pathArray = $pathArray ? $pathArray : []; + $this->root = $root; + } + + /** + * Return path array + * + * @return array + */ + public function getArray(): array + { + return $this->pathArray; + } + + /** + * Return root + */ + public function getRoot(): string + { + return $this->root; + } + + /** + * Update root + */ + public function setRoot(string $root): string + { + return $this->root = $root; + } +} diff --git a/tests/Feature/ArtiMigrationCommandTest.php b/tests/Feature/ArtiMigrationCommandTest.php index 2d696d7..7629d9c 100644 --- a/tests/Feature/ArtiMigrationCommandTest.php +++ b/tests/Feature/ArtiMigrationCommandTest.php @@ -8,11 +8,10 @@ use function Pest\Laravel\artisan; describe('arti:migration', function () { - it('should create the Migration class when used', function (string $class) { + it('should create Migration in config path', function (string $class) { Config::set('laraca.struct.database.path', 'test/database'); artisan('arti:migration', ['name' => $class]); - $output = Artisan::output(); $now = now(); @@ -31,7 +30,7 @@ ->toBe(true, "File not created at expected path:\n$migrationPath1\n$migrationPath2\n$output\n\n"); })->with('classes'); - it('should create the Migration class using path option', function (string $class) { + it('should create Migration in path option', function (string $class) { Config::set('laraca.struct.database.path', 'test/database'); artisan('arti:migration', ['name' => $class, '--path' => 'test/db/migrations']); @@ -53,4 +52,77 @@ ->toBe(true, "File not created at expected path:\n$migrationPath1\n$migrationPath2\n$output\n\n"); })->with('classes'); + + it('should create Migration and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('arti:migration', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $domain = getName($domain); + + $now = now(); + $subSecond = $now->copy()->subSecond()->format('Y_m_d_His'); + $now = $now->format('Y_m_d_His'); + + $snake_class = Str::snake($class); + + $migrationsPath = app_path("Test/Domains/$domain/database/migrations"); + + // account for second change variation that may occur in file name + $migrationPath1 = "$migrationsPath/{$subSecond}_{$snake_class}.php"; + $migrationPath2 = "$migrationsPath/{$now}_{$snake_class}.php"; + + expect(File::exists($migrationPath1) || File::exists($migrationPath2)) + ->toBe(true, "File not created at expected path:\n$migrationPath1\n$migrationPath2\n$output\n\n"); + })->with('classes', 'domains'); + + it('should create Migration and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('arti:migration', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $service = getName($service); + + $now = now(); + $subSecond = $now->copy()->subSecond()->format('Y_m_d_His'); + $now = $now->format('Y_m_d_His'); + + $snake_class = Str::snake($class); + + $migrationsPath = app_path("Test/Services/$service/database/migrations"); + + // account for second change variation that may occur in file name + $migrationPath1 = "$migrationsPath/{$subSecond}_{$snake_class}.php"; + $migrationPath2 = "$migrationsPath/{$now}_{$snake_class}.php"; + + expect(File::exists($migrationPath1) || File::exists($migrationPath2)) + ->toBe(true, "File not created at expected path:\n$migrationPath1\n$migrationPath2\n$output\n\n"); + })->with('classes', 'domains'); + + it('should create Migration and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('arti:migration', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $domain = getName($domain); + $service = getName($service); + + $now = now(); + $subSecond = $now->copy()->subSecond()->format('Y_m_d_His'); + $now = $now->format('Y_m_d_His'); + + $snake_class = Str::snake($class); + + $migrationsPath = app_path("Test/Domains/$domain/Services/$service/database/migrations"); + + // account for second change variation that may occur in file name + $migrationPath1 = "$migrationsPath/{$subSecond}_{$snake_class}.php"; + $migrationPath2 = "$migrationsPath/{$now}_{$snake_class}.php"; + + expect(File::exists($migrationPath1) || File::exists($migrationPath2)) + ->toBe(true, "File not created at expected path:\n$migrationPath1\n$migrationPath2\n$output\n\n"); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/DomainListTest.php b/tests/Feature/DomainListTest.php index 77217db..3b37fb4 100644 --- a/tests/Feature/DomainListTest.php +++ b/tests/Feature/DomainListTest.php @@ -9,25 +9,23 @@ describe('domain:list', function () { it('should list direct children of the configured domain folder', function (string $class, string $domain) { Config::set('laraca.struct.domain.enabled', true); - Config::set('laraca.struct.domain.path', 'TestDomains'); + Config::set('laraca.struct.domain.path', 'Test/Domains'); artisan('make:controller', ['name' => $class, '--domain' => $domain]); - artisan('make:job', ['name' => $class, '--domain' => $domain]); - artisan('domain:list'); $output = Artisan::output(); - $class = ucfirst($class); - $domain = ucfirst($domain); + $class = getName($class); + $domain = getName($domain); expect($output) - ->toContain('TestDomains', $domain); + ->toContain('Test/Domains', $domain); })->with('classes', 'domains'); it('should not be available when domains are disabled', function (string $class, string $domain) { Config::set('laraca.struct.domain.enabled', false); - Config::set('laraca.struct.domain.path', 'TestDomains'); + Config::set('laraca.struct.domain.path', 'Test/Domains'); artisan('make:controller', ['name' => $class, '--domain' => $domain]); $output = Artisan::output(); diff --git a/tests/Feature/DomainsTest.php b/tests/Feature/DomainsTest.php index 9747ec0..82b11f6 100644 --- a/tests/Feature/DomainsTest.php +++ b/tests/Feature/DomainsTest.php @@ -14,8 +14,8 @@ artisan('make:controller', ['name' => $class, '--domain' => $domain]); $output = Artisan::output(); - $class = ucfirst($class); - $domain = ucfirst($domain); + $class = getName($class); + $domain = getName($domain); $contollerPath = app_path("Test/Domains/$domain/Http/Controllers/$class.php"); @@ -35,8 +35,8 @@ artisan('make:enum', ['name' => $class, '--domain' => $domain]); $output = Artisan::output(); - $class = ucfirst($class); - $domain = ucfirst($domain); + $class = getName($class); + $domain = getName($domain); $enumPath = app_path("$domain/Enums/$class.php"); @@ -58,8 +58,7 @@ artisan('make:controller', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $contollerPath = app_path("Test/Http/Controllers/$class.php"); expect($contollerPath) diff --git a/tests/Feature/InitMicroserviceCommandTest.php b/tests/Feature/InitMicroserviceCommandTest.php index a2d48c9..71b996f 100644 --- a/tests/Feature/InitMicroserviceCommandTest.php +++ b/tests/Feature/InitMicroserviceCommandTest.php @@ -9,14 +9,13 @@ use function Pest\Laravel\artisan; describe('init:micro', function () { - it('should implement microservice with selected elements', function (string $class) { + it('should init microservice dirs and files', function (string $class) { Config::set('laraca.struct.microservice.path', 'Test/Services'); artisan('init:micro', ['name' => $class]); - $output = Artisan::output(); - $class = ucfirst($class); + $class = getName($class); $slug = Str::slug($class); $paths = [ @@ -103,24 +102,24 @@ Config::set('laraca.struct.microservice.path', 'Test/Services'); artisan('init:micro', ['name' => $class]); - artisan('init:micro', ['name' => $class]); $output = Artisan::output(); expect($output)->toContain('already exists'); })->with('classes'); - it('should create microservice in domain', function (string $class, string $domain) { + it('should init microservice dirs and files in domain', function (string $class, string $domain) { Config::set('laraca.struct.domain.enabled', true); Config::set('laraca.struct.domain.path', 'Test/Domains'); artisan('init:micro', ['name' => $class, '--domain' => $domain]); $output = Artisan::output(); - $class = ucfirst($class); - $domain = ucfirst($domain); + $class = getName($class); + $domain = getName($domain); $serviceProviderPath = app_path("Test/Domains/$domain/Services/$class/{$class}ServiceProvider.php"); + expect($serviceProviderPath) ->toBeFile("File not created at expected path:\n$serviceProviderPath\n\nOutput results:\n$output\n=====\n"); @@ -130,9 +129,9 @@ ); })->with('classes', 'domains'); - it('should not create a service with service flag', function () { - Config::set('laraca.struct.domain.enabled', true); - Config::set('laraca.struct.domain.path', 'Test/Domains'); + it('should not create a microservice with service flag', function () { + Config::set('laraca.struct.microservice.enabled', true); + Config::set('laraca.struct.microservice.path', 'Test/Services'); artisan('init:micro', ['name' => 'FooCreated', '--service' => 'Bar']); diff --git a/tests/Feature/MakeCastCommandTest.php b/tests/Feature/MakeCastCommandTest.php index 6252708..fdf058f 100644 --- a/tests/Feature/MakeCastCommandTest.php +++ b/tests/Feature/MakeCastCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:cast', function () { - it('should create Cast class with namespace and path created from configured vals', function (string $class) { + it('should create Cast in config path', function (string $class) { Config::set('laraca.struct.cast.path', 'Test/Data/Casts'); artisan('make:cast', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $castPath = app_path("Test/Data/Casts/$class.php"); expect($castPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Cast in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:cast', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $castPath = app_path("Test/Domains/$domain/Data/Casts/$class.php"); + + expect($castPath) + ->toBeFile("File not created at expected path:\n$castPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($castPath))->toContain( + "namespace App\Test\Domains\\$domain\Data\Casts;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Cast in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:cast', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $castPath = app_path("Test/Services/$service/Data/Casts/$class.php"); + + expect($castPath) + ->toBeFile("File not created at expected path:\n$castPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($castPath))->toContain( + "namespace App\Test\Services\\$service\Data\Casts;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Cast in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:cast', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $castPath = app_path("Test/Domains/$domain/Services/$service/Data/Casts/$class.php"); + + expect($castPath) + ->toBeFile("File not created at expected path:\n$castPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($castPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Data\Casts;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeChannelCommandTest.php b/tests/Feature/MakeChannelCommandTest.php index f6af742..050ee74 100644 --- a/tests/Feature/MakeChannelCommandTest.php +++ b/tests/Feature/MakeChannelCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:channel', function () { - it('should create Channel class with namespace and path created from configured vals', function (string $class) { + it('should create Channel in config path', function (string $class) { Config::set('laraca.struct.channel.path', 'Test/Broadcasting'); - $class = ucfirst($class); - artisan('make:channel', ['name' => $class]); $output = Artisan::output(); + $class = getName($class); $channelPath = app_path("Test/Broadcasting/$class.php"); expect($channelPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Channel in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:channel', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $channelPath = app_path("Test/Domains/$domain/Broadcasting/$class.php"); + + expect($channelPath) + ->toBeFile("File not created at expected path:\n$channelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($channelPath))->toContain( + "namespace App\Test\Domains\\$domain\Broadcasting;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Channel in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:channel', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $channelPath = app_path("Test/Services/$service/Broadcasting/$class.php"); + + expect($channelPath) + ->toBeFile("File not created at expected path:\n$channelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($channelPath))->toContain( + "namespace App\Test\Services\\$service\Broadcasting;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Channel in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:channel', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $channelPath = app_path("Test/Domains/$domain/Services/$service/Broadcasting/$class.php"); + + expect($channelPath) + ->toBeFile("File not created at expected path:\n$channelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($channelPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Broadcasting;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeCommandCommandTest.php b/tests/Feature/MakeCommandCommandTest.php deleted file mode 100644 index b2a23f0..0000000 --- a/tests/Feature/MakeCommandCommandTest.php +++ /dev/null @@ -1,28 +0,0 @@ - $class]); - $output = Artisan::output(); - - $commandPath = app_path("Test/Console/Commands/$class.php"); - - expect($commandPath) - ->toBeFile("File not created at expected path:\n$commandPath\n\nOutput results:\n$output\n=====\n"); - - expect(File::get($commandPath))->toContain( - 'namespace App\Test\Console\Commands;', - "class $class", - ); - })->with('classes'); -}); diff --git a/tests/Feature/MakeComponentCommandTest.php b/tests/Feature/MakeComponentCommandTest.php new file mode 100644 index 0000000..be10eec --- /dev/null +++ b/tests/Feature/MakeComponentCommandTest.php @@ -0,0 +1,142 @@ + $class, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $componentPath = app_path("Test/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + 'namespace App\Test\View\Components;', + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $componentTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); + + $viewName = $class->kebab(); + $viewPath = base_path("test/resources/views/components/{$viewName}.blade.php"); + + expect($viewPath) + ->toBeFile("File not created at expected path:\n$viewPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewPath))->toContain('
'); + })->with('classes'); + + it('should create Component and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:component', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $componentPath = app_path("Test/Domains/$domain/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Domains\\$domain\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $componentTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Component and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:component', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $componentPath = app_path("Test/Services/$service/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Services\\$service\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $componentTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Component and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:component', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $componentPath = app_path("Test/Domains/$domain/Services/$service/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $componentTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); +}); diff --git a/tests/Feature/MakeConsoleCommandTest.php b/tests/Feature/MakeConsoleCommandTest.php new file mode 100644 index 0000000..2da0879 --- /dev/null +++ b/tests/Feature/MakeConsoleCommandTest.php @@ -0,0 +1,133 @@ + $class, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $commandPath = app_path("Test/Console/Commands/$class.php"); + + expect($commandPath) + ->toBeFile("File not created at expected path:\n$commandPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandPath))->toContain( + 'namespace App\Test\Console\Commands;', + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $commandTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($commandTestPath) + ->toBeFile("File not created at expected path:\n$commandTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); + })->with('classes'); + + it('should create Command and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:command', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $commandPath = app_path("Test/Domains/$domain/Console/Commands/$class.php"); + + expect($commandPath) + ->toBeFile("File not created at expected path:\n$commandPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandPath))->toContain( + "namespace App\Test\Domains\\$domain\Console\Commands;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $commandTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($commandTestPath) + ->toBeFile("File not created at expected path:\n$commandTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Command and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:command', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $commandPath = app_path("Test/Services/$service/Console/Commands/$class.php"); + + expect($commandPath) + ->toBeFile("File not created at expected path:\n$commandPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandPath))->toContain( + "namespace App\Test\Services\\$service\Console\Commands;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $commandTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($commandTestPath) + ->toBeFile("File not created at expected path:\n$commandTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Command and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:command', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $commandPath = app_path("Test/Domains/$domain/Services/$service/Console/Commands/$class.php"); + + expect($commandPath) + ->toBeFile("File not created at expected path:\n$commandPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Console\Commands;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $commandTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($commandTestPath) + ->toBeFile("File not created at expected path:\n$commandTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($commandTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); +}); diff --git a/tests/Feature/MakeControllerCommandTest.php b/tests/Feature/MakeControllerCommandTest.php index 1035267..b58ace2 100644 --- a/tests/Feature/MakeControllerCommandTest.php +++ b/tests/Feature/MakeControllerCommandTest.php @@ -6,23 +6,128 @@ use function Pest\Laravel\artisan; -describe('make:controller', function () { - it('should create Controller class with namespace and path created from configured vals', function (string $class) { - Config::set('laraca.struct.controller.path', 'Test/Http/Controllers'); +describe('make:component', function () { + it('should create Component and test in config path', function (string $class) { + Config::set('laraca.struct.component.path', 'Test/View/Components'); + Config::set('laraca.struct.test.path', 'Test/tests'); - $class = ucfirst($class); - - artisan('make:controller', ['name' => $class]); + artisan('make:component', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $controllerPath = app_path("Test/Http/Controllers/$class.php"); + $class = getName($class); + $componentPath = app_path("Test/View/Components/$class.php"); - expect($controllerPath) - ->toBeFile("File not created at expected path:\n$controllerPath\n\nOutput results:\n$output\n=====\n"); + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); - expect(File::get($controllerPath))->toContain( - 'namespace App\Test\Http\Controllers;', + expect(File::get($componentPath))->toContain( + 'namespace App\Test\View\Components;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $componentTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Component and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:component', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $componentPath = app_path("Test/Domains/$domain/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Domains\\$domain\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $componentTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Component and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:component', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $componentPath = app_path("Test/Services/$service/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Services\\$service\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $componentTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Component and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:component', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $componentPath = app_path("Test/Domains/$domain/Services/$service/View/Components/$class.php"); + + expect($componentPath) + ->toBeFile("File not created at expected path:\n$componentPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\View\Components;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $componentTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($componentTestPath) + ->toBeFile("File not created at expected path:\n$componentTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($componentTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeEnumCommandTest.php b/tests/Feature/MakeEnumCommandTest.php index 908ea3e..8cd6d34 100644 --- a/tests/Feature/MakeEnumCommandTest.php +++ b/tests/Feature/MakeEnumCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:enum', function () { - it('should create Enum class with namespace and path created from configured vals', function (string $class) { + it('should create Enum in config path', function (string $class) { Config::set('laraca.struct.enum.path', 'Test/Enums'); - $class = ucfirst($class); - artisan('make:enum', ['name' => $class]); $output = Artisan::output(); + $class = getName($class); $enumPath = app_path("Test/Enums/$class.php"); expect($enumPath) @@ -25,4 +24,63 @@ "enum $class", ); })->with('classes'); + + it('should create Enum in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:enum', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $enumPath = app_path("Test/Domains/$domain/Enums/$class.php"); + + expect($enumPath) + ->toBeFile("File not created at expected path:\n$enumPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($enumPath))->toContain( + "namespace App\Test\Domains\\$domain\Enums;", + "enum $class", + ); + })->with('classes', 'domains'); + + it('should create Enum in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:enum', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $enumPath = app_path("Test/Services/$service/Enums/$class.php"); + + expect($enumPath) + ->toBeFile("File not created at expected path:\n$enumPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($enumPath))->toContain( + "namespace App\Test\Services\\$service\Enums;", + "enum $class", + ); + })->with('classes', 'domains'); + + it('should create Enum in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:enum', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $enumPath = app_path("Test/Domains/$domain/Services/$service/Enums/$class.php"); + + expect($enumPath) + ->toBeFile("File not created at expected path:\n$enumPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($enumPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Enums;", + "enum $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeEventCommandTest.php b/tests/Feature/MakeEventCommandTest.php index 8b5c550..367b7e1 100644 --- a/tests/Feature/MakeEventCommandTest.php +++ b/tests/Feature/MakeEventCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:event', function () { - it('should create Event class with namespace and path created from configured vals', function (string $class) { + it('should create Event in config path', function (string $class) { Config::set('laraca.struct.event.path', 'Test/Events'); - $class = ucfirst($class); - artisan('make:event', ['name' => $class]); $output = Artisan::output(); + $class = getName($class); $eventPath = app_path("Test/Events/$class.php"); expect($eventPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Event in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:event', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $eventPath = app_path("Test/Domains/$domain/Events/$class.php"); + + expect($eventPath) + ->toBeFile("File not created at expected path:\n$eventPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($eventPath))->toContain( + "namespace App\Test\Domains\\$domain\Events;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Event in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:event', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $eventPath = app_path("Test/Services/$service/Events/$class.php"); + + expect($eventPath) + ->toBeFile("File not created at expected path:\n$eventPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($eventPath))->toContain( + "namespace App\Test\Services\\$service\Events;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Event in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:event', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $eventPath = app_path("Test/Domains/$domain/Services/$service/Events/$class.php"); + + expect($eventPath) + ->toBeFile("File not created at expected path:\n$eventPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($eventPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Events;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeExceptionCommandTest.php b/tests/Feature/MakeExceptionCommandTest.php index ed1c025..2fde5ec 100644 --- a/tests/Feature/MakeExceptionCommandTest.php +++ b/tests/Feature/MakeExceptionCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:exception', function () { - it('should create Exception class with namespace and path created from configured vals', function (string $class) { + it('should create Exception in config path', function (string $class) { Config::set('laraca.struct.exception.path', 'Test/Exceptions'); - $class = ucfirst($class); - artisan('make:exception', ['name' => $class]); $output = Artisan::output(); + $class = getName($class); $exceptionPath = app_path("Test/Exceptions/$class.php"); expect($exceptionPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Exception in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:exception', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $exceptionPath = app_path("Test/Domains/$domain/Exceptions/$class.php"); + + expect($exceptionPath) + ->toBeFile("File not created at expected path:\n$exceptionPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($exceptionPath))->toContain( + "namespace App\Test\Domains\\$domain\Exceptions;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Exception in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:exception', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $exceptionPath = app_path("Test/Services/$service/Exceptions/$class.php"); + + expect($exceptionPath) + ->toBeFile("File not created at expected path:\n$exceptionPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($exceptionPath))->toContain( + "namespace App\Test\Services\\$service\Exceptions;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Exception in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:exception', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $exceptionPath = app_path("Test/Domains/$domain/Services/$service/Exceptions/$class.php"); + + expect($exceptionPath) + ->toBeFile("File not created at expected path:\n$exceptionPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($exceptionPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Exceptions;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeFactoryCommandTest.php b/tests/Feature/MakeFactoryCommandTest.php index 3a51ead..70b61f9 100644 --- a/tests/Feature/MakeFactoryCommandTest.php +++ b/tests/Feature/MakeFactoryCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:factory', function () { - it('should create Factory class with namespace and path created from configured vals', function (string $class) { + it('should create Factory in config path', function (string $class) { Config::set('laraca.struct.database.path', 'test/database'); - $class = ucfirst($class); - artisan('make:factory', ['name' => $class]); $output = Artisan::output(); + $class = getName($class); $factoryPath = base_path("test/database/factories/{$class}Factory.php"); expect($factoryPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Factory in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:factory', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $factoryPath = app_path("Test/Domains/$domain/database/factories/{$class}Factory.php"); + + expect($factoryPath) + ->toBeFile("File not created at expected path:\n$factoryPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($factoryPath))->toContain( + "namespace App\Test\Domains\\$domain\Database\Factories;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Factory in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:factory', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $factoryPath = app_path("Test/Services/$service/database/factories/{$class}Factory.php"); + + expect($factoryPath) + ->toBeFile("File not created at expected path:\n$factoryPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($factoryPath))->toContain( + "namespace App\Test\Services\\$service\Database\Factories;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Factory in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:factory', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $factoryPath = app_path("Test/Domains/$domain/Services/$service/database/factories/{$class}Factory.php"); + + expect($factoryPath) + ->toBeFile("File not created at expected path:\n$factoryPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($factoryPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Database\Factories;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeJobCommandTest.php b/tests/Feature/MakeJobCommandTest.php index ee6b94c..d6292c0 100644 --- a/tests/Feature/MakeJobCommandTest.php +++ b/tests/Feature/MakeJobCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:job', function () { - it('should create Job class with namespace and path created from configured vals', function (string $class) { + it('should create Job and test in config path', function (string $class) { Config::set('laraca.struct.job.path', 'Test/Jobs'); + Config::set('laraca.struct.test.path', 'Test/tests'); - $class = ucfirst($class); - - artisan('make:job', ['name' => $class]); + artisan('make:job', ['name' => $class, '--test' => true]); $output = Artisan::output(); + $class = getName($class); $jobPath = app_path("Test/Jobs/$class.php"); expect($jobPath) @@ -24,5 +24,110 @@ 'namespace App\Test\Jobs;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $jobTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($jobTestPath) + ->toBeFile("File not created at expected path:\n$jobTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Job and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:job', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $jobPath = app_path("Test/Domains/$domain/Jobs/$class.php"); + + expect($jobPath) + ->toBeFile("File not created at expected path:\n$jobPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobPath))->toContain( + "namespace App\Test\Domains\\$domain\Jobs;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $jobTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($jobTestPath) + ->toBeFile("File not created at expected path:\n$jobTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Job and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:job', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $jobPath = app_path("Test/Services/$service/Jobs/$class.php"); + + expect($jobPath) + ->toBeFile("File not created at expected path:\n$jobPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobPath))->toContain( + "namespace App\Test\Services\\$service\Jobs;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $jobTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($jobTestPath) + ->toBeFile("File not created at expected path:\n$jobTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Job and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:job', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $jobPath = app_path("Test/Domains/$domain/Services/$service/Jobs/$class.php"); + + expect($jobPath) + ->toBeFile("File not created at expected path:\n$jobPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Jobs;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $jobTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($jobTestPath) + ->toBeFile("File not created at expected path:\n$jobTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($jobTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeListenerCommandTest.php b/tests/Feature/MakeListenerCommandTest.php index 81a5c10..7acce9d 100644 --- a/tests/Feature/MakeListenerCommandTest.php +++ b/tests/Feature/MakeListenerCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:listener', function () { - it('should create Listener class with namespace and path created from configured vals', function (string $class) { + it('should create Listener and test in config path', function (string $class) { Config::set('laraca.struct.listener.path', 'Test/Listeners'); + Config::set('laraca.struct.test.path', 'Test/tests'); - $class = ucfirst($class); - - artisan('make:listener', ['name' => $class]); + artisan('make:listener', ['name' => $class, '--test' => true]); $output = Artisan::output(); + $class = getName($class); $listenerPath = app_path("Test/Listeners/$class.php"); expect($listenerPath) @@ -24,5 +24,110 @@ 'namespace App\Test\Listeners;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $listenerTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($listenerTestPath) + ->toBeFile("File not created at expected path:\n$listenerTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Listener and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:listener', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $listenerPath = app_path("Test/Domains/$domain/Listeners/$class.php"); + + expect($listenerPath) + ->toBeFile("File not created at expected path:\n$listenerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerPath))->toContain( + "namespace App\Test\Domains\\$domain\Listeners;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $listenerTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($listenerTestPath) + ->toBeFile("File not created at expected path:\n$listenerTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Listener and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:listener', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $listenerPath = app_path("Test/Services/$service/Listeners/$class.php"); + + expect($listenerPath) + ->toBeFile("File not created at expected path:\n$listenerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerPath))->toContain( + "namespace App\Test\Services\\$service\Listeners;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $listenerTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($listenerTestPath) + ->toBeFile("File not created at expected path:\n$listenerTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Listener and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:listener', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $listenerPath = app_path("Test/Domains/$domain/Services/$service/Listeners/$class.php"); + + expect($listenerPath) + ->toBeFile("File not created at expected path:\n$listenerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Listeners;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $listenerTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($listenerTestPath) + ->toBeFile("File not created at expected path:\n$listenerTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($listenerTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeMailCommandTest.php b/tests/Feature/MakeMailCommandTest.php index 49c5247..f9f37d2 100644 --- a/tests/Feature/MakeMailCommandTest.php +++ b/tests/Feature/MakeMailCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:mail', function () { - it('should create Mail class with namespace and path created from configured vals', function (string $class) { + it('should create Mail and test in config path', function (string $class) { Config::set('laraca.struct.mail.path', 'Test/Mail'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:mail', ['name' => $class]); + artisan('make:mail', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $mailPath = app_path("Test/Mail/$class.php"); expect($mailPath) @@ -24,5 +24,109 @@ 'namespace App\Test\Mail;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $mailTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($mailTestPath) + ->toBeFile("File not created at expected path:\n$mailTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Mail and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:mail', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $mailPath = app_path("Test/Domains/$domain/Mail/$class.php"); + + expect($mailPath) + ->toBeFile("File not created at expected path:\n$mailPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailPath))->toContain( + "namespace App\Test\Domains\\$domain\Mail;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $mailTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($mailTestPath) + ->toBeFile("File not created at expected path:\n$mailTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Mail and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:mail', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $mailPath = app_path("Test/Services/$service/Mail/$class.php"); + + expect($mailPath) + ->toBeFile("File not created at expected path:\n$mailPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailPath))->toContain( + "namespace App\Test\Services\\$service\Mail;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $mailTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($mailTestPath) + ->toBeFile("File not created at expected path:\n$mailTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Mail and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:mail', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $mailPath = app_path("Test/Domains/$domain/Services/$service/Mail/$class.php"); + + expect($mailPath) + ->toBeFile("File not created at expected path:\n$mailPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Mail;", + "class $class", + ); + $classTest = getName($class)->finish('Test'); + $mailTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($mailTestPath) + ->toBeFile("File not created at expected path:\n$mailTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($mailTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeMiddlewareCommandTest.php b/tests/Feature/MakeMiddlewareCommandTest.php index 9eb2049..610dde9 100644 --- a/tests/Feature/MakeMiddlewareCommandTest.php +++ b/tests/Feature/MakeMiddlewareCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:middleware', function () { - it('should create Middleware class with namespace and path created from configured vals', function (string $class) { + it('should create Middleware and test in config path', function (string $class) { Config::set('laraca.struct.middleware.path', 'Test/Http/Middleware'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:middleware', ['name' => $class]); + artisan('make:middleware', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $middlewarePath = app_path("Test/Http/Middleware/$class.php"); expect($middlewarePath) @@ -24,5 +24,110 @@ 'namespace App\Test\Http\Middleware;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $middlewareTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($middlewareTestPath) + ->toBeFile("File not created at expected path:\n$middlewareTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewareTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Middleware and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:middleware', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $middlewarePath = app_path("Test/Domains/$domain/Http/Middleware/$class.php"); + + expect($middlewarePath) + ->toBeFile("File not created at expected path:\n$middlewarePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewarePath))->toContain( + "namespace App\Test\Domains\\$domain\Http\Middleware;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $middlewareTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($middlewareTestPath) + ->toBeFile("File not created at expected path:\n$middlewareTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewareTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Middleware and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:middleware', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $middlewarePath = app_path("Test/Services/$service/Http/Middleware/$class.php"); + + expect($middlewarePath) + ->toBeFile("File not created at expected path:\n$middlewarePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewarePath))->toContain( + "namespace App\Test\Services\\$service\Http\Middleware;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $middlewareTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($middlewareTestPath) + ->toBeFile("File not created at expected path:\n$middlewareTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewareTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Middleware and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:middleware', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $middlewarePath = app_path("Test/Domains/$domain/Services/$service/Http/Middleware/$class.php"); + + expect($middlewarePath) + ->toBeFile("File not created at expected path:\n$middlewarePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewarePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Http\Middleware;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $middlewareTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($middlewareTestPath) + ->toBeFile("File not created at expected path:\n$middlewareTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($middlewareTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeModelCommandTest.php b/tests/Feature/MakeModelCommandTest.php index d9b3384..ee56427 100644 --- a/tests/Feature/MakeModelCommandTest.php +++ b/tests/Feature/MakeModelCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:model', function () { - it('should create Model class with namespace and path created from configured vals', function (string $class) { + it('should create Model and test in config path', function (string $class) { Config::set('laraca.struct.model.path', 'Test/Data/Models'); + Config::set('laraca.struct.test.path', 'Test/tests'); - $class = ucfirst($class); - - artisan('make:model', ['name' => $class]); + artisan('make:model', ['name' => $class, '--test' => true]); $output = Artisan::output(); + $class = getName($class); $modelPath = app_path("Test/Data/Models/$class.php"); expect($modelPath) @@ -24,12 +24,117 @@ 'namespace App\Test\Data\Models;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $modelTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($modelTestPath) + ->toBeFile("File not created at expected path:\n$modelTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); - it('should create a Model class with HasUuids trait', function (string $class) { + it('should create Model and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:model', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $modelPath = app_path("Test/Domains/$domain/Data/Models/$class.php"); + + expect($modelPath) + ->toBeFile("File not created at expected path:\n$modelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelPath))->toContain( + "namespace App\Test\Domains\\$domain\Data\Models;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $modelTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($modelTestPath) + ->toBeFile("File not created at expected path:\n$modelTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Model and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:model', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $modelPath = app_path("Test/Services/$service/Data/Models/$class.php"); + + expect($modelPath) + ->toBeFile("File not created at expected path:\n$modelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelPath))->toContain( + "namespace App\Test\Services\\$service\Data\Models;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $modelTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($modelTestPath) + ->toBeFile("File not created at expected path:\n$modelTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Model and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:model', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $modelPath = app_path("Test/Domains/$domain/Services/$service/Data/Models/$class.php"); + + expect($modelPath) + ->toBeFile("File not created at expected path:\n$modelPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Data\Models;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $modelTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($modelTestPath) + ->toBeFile("File not created at expected path:\n$modelTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($modelTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); + + it('should create Model and test in config path with HasUuids trait', function (string $class) { Config::set('laraca.struct.model.path', 'Test/Data/Models'); - $class = ucfirst($class); + $class = getName($class); artisan('make:model', ['name' => $class, '--uuid' => true]); $output = Artisan::output(); diff --git a/tests/Feature/MakeNotificationCommandTest.php b/tests/Feature/MakeNotificationCommandTest.php index c8eca3a..1d964a9 100644 --- a/tests/Feature/MakeNotificationCommandTest.php +++ b/tests/Feature/MakeNotificationCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:notification', function () { - it('should create Notification class with namespace and path created from configured vals', function (string $class) { + it('should create Notification and test in config path', function (string $class) { Config::set('laraca.struct.notification.path', 'Test/Notifications'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:notification', ['name' => $class]); + artisan('make:notification', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $notificationPath = app_path("Test/Notifications/$class.php"); expect($notificationPath) @@ -24,5 +24,110 @@ 'namespace App\Test\Notifications;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $notificationTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($notificationTestPath) + ->toBeFile("File not created at expected path:\n$notificationTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Notification and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:notification', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $notificationPath = app_path("Test/Domains/$domain/Notifications/$class.php"); + + expect($notificationPath) + ->toBeFile("File not created at expected path:\n$notificationPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationPath))->toContain( + "namespace App\Test\Domains\\$domain\Notifications;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $notificationTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($notificationTestPath) + ->toBeFile("File not created at expected path:\n$notificationTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Notification and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:notification', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $notificationPath = app_path("Test/Services/$service/Notifications/$class.php"); + + expect($notificationPath) + ->toBeFile("File not created at expected path:\n$notificationPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationPath))->toContain( + "namespace App\Test\Services\\$service\Notifications;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $notificationTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($notificationTestPath) + ->toBeFile("File not created at expected path:\n$notificationTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Notification and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:notification', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $notificationPath = app_path("Test/Domains/$domain/Services/$service/Notifications/$class.php"); + + expect($notificationPath) + ->toBeFile("File not created at expected path:\n$notificationPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Notifications;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $notificationTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($notificationTestPath) + ->toBeFile("File not created at expected path:\n$notificationTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($notificationTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeObserverCommandTest.php b/tests/Feature/MakeObserverCommandTest.php index 6a84314..a40282b 100644 --- a/tests/Feature/MakeObserverCommandTest.php +++ b/tests/Feature/MakeObserverCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:observer', function () { - it('should create Observer class with namespace and path created from configured vals', function (string $class) { + it('should create Observer and test in config path', function (string $class) { Config::set('laraca.struct.observer.path', 'Test/Data/Observers'); artisan('make:observer', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $observerPath = app_path("Test/Data/Observers/$class.php"); expect($observerPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Observer and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:observer', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $observerPath = app_path("Test/Domains/$domain/Data/Observers/$class.php"); + + expect($observerPath) + ->toBeFile("File not created at expected path:\n$observerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($observerPath))->toContain( + "namespace App\Test\Domains\\$domain\Data\Observers;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Observer and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:observer', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $observerPath = app_path("Test/Services/$service/Data/Observers/$class.php"); + + expect($observerPath) + ->toBeFile("File not created at expected path:\n$observerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($observerPath))->toContain( + "namespace App\Test\Services\\$service\Data\Observers;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Observer and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:observer', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $observerPath = app_path("Test/Domains/$domain/Services/$service/Data/Observers/$class.php"); + + expect($observerPath) + ->toBeFile("File not created at expected path:\n$observerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($observerPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Data\Observers;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakePolicyCommandTest.php b/tests/Feature/MakePolicyCommandTest.php index b265bb8..874b519 100644 --- a/tests/Feature/MakePolicyCommandTest.php +++ b/tests/Feature/MakePolicyCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:policy', function () { - it('should create Policy class with namespace and path created from configured vals', function (string $class) { + it('should create Policy and test in config path', function (string $class) { Config::set('laraca.struct.policy.path', 'Test/Policies'); artisan('make:policy', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $policyPath = app_path("Test/Policies/$class.php"); expect($policyPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Policy and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:policy', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $policyPath = app_path("Test/Domains/$domain/Policies/$class.php"); + + expect($policyPath) + ->toBeFile("File not created at expected path:\n$policyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($policyPath))->toContain( + "namespace App\Test\Domains\\$domain\Policies;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Policy and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:policy', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $policyPath = app_path("Test/Services/$service/Policies/$class.php"); + + expect($policyPath) + ->toBeFile("File not created at expected path:\n$policyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($policyPath))->toContain( + "namespace App\Test\Services\\$service\Policies;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Policy and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:policy', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $policyPath = app_path("Test/Domains/$domain/Services/$service/Policies/$class.php"); + + expect($policyPath) + ->toBeFile("File not created at expected path:\n$policyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($policyPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Policies;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeProviderCommandTest.php b/tests/Feature/MakeProviderCommandTest.php index f47086c..c74a813 100644 --- a/tests/Feature/MakeProviderCommandTest.php +++ b/tests/Feature/MakeProviderCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:provider', function () { - it('should create Provider class with namespace and path created from configured vals', function (string $class) { + it('should create Provider and test in config path', function (string $class) { Config::set('laraca.struct.provider.path', 'Test/Providers'); artisan('make:provider', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $providerPath = app_path("Test/Providers/$class.php"); expect($providerPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Provider and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:provider', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $providerPath = app_path("Test/Domains/$domain/Providers/$class.php"); + + expect($providerPath) + ->toBeFile("File not created at expected path:\n$providerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($providerPath))->toContain( + "namespace App\Test\Domains\\$domain\Providers;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Provider and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:provider', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $providerPath = app_path("Test/Services/$service/Providers/$class.php"); + + expect($providerPath) + ->toBeFile("File not created at expected path:\n$providerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($providerPath))->toContain( + "namespace App\Test\Services\\$service\Providers;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Provider and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:provider', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $providerPath = app_path("Test/Domains/$domain/Services/$service/Providers/$class.php"); + + expect($providerPath) + ->toBeFile("File not created at expected path:\n$providerPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($providerPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Providers;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeRequestCommandTest.php b/tests/Feature/MakeRequestCommandTest.php index 249a18c..46ba588 100644 --- a/tests/Feature/MakeRequestCommandTest.php +++ b/tests/Feature/MakeRequestCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:request', function () { - it('should create Request class with namespace and path created from configured vals', function (string $class) { + it('should create Request and test in config path', function (string $class) { Config::set('laraca.struct.request.path', 'Test/Http/Requests'); artisan('make:request', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $requestPath = app_path("Test/Http/Requests/$class.php"); expect($requestPath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Request and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:request', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $requestPath = app_path("Test/Domains/$domain/Http/Requests/$class.php"); + + expect($requestPath) + ->toBeFile("File not created at expected path:\n$requestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($requestPath))->toContain( + "namespace App\Test\Domains\\$domain\Http\Requests;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Request and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:request', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $requestPath = app_path("Test/Services/$service/Http/Requests/$class.php"); + + expect($requestPath) + ->toBeFile("File not created at expected path:\n$requestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($requestPath))->toContain( + "namespace App\Test\Services\\$service\Http\Requests;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Request and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:request', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $requestPath = app_path("Test/Domains/$domain/Services/$service/Http/Requests/$class.php"); + + expect($requestPath) + ->toBeFile("File not created at expected path:\n$requestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($requestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Http\Requests;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeResourceCommandTest.php b/tests/Feature/MakeResourceCommandTest.php index 0116cc1..ed78afa 100644 --- a/tests/Feature/MakeResourceCommandTest.php +++ b/tests/Feature/MakeResourceCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:resource', function () { - it('should create Resource class with namespace and path created from configured vals', function (string $class) { + it('should create Resource and test in config path', function (string $class) { Config::set('laraca.struct.resource.path', 'Test/Http/Resources'); artisan('make:resource', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $resourcePath = app_path("Test/Http/Resources/$class.php"); expect($resourcePath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Resource and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:resource', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $resourcePath = app_path("Test/Domains/$domain/Http/Resources/$class.php"); + + expect($resourcePath) + ->toBeFile("File not created at expected path:\n$resourcePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($resourcePath))->toContain( + "namespace App\Test\Domains\\$domain\Http\Resources;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Resource and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:resource', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $resourcePath = app_path("Test/Services/$service/Http/Resources/$class.php"); + + expect($resourcePath) + ->toBeFile("File not created at expected path:\n$resourcePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($resourcePath))->toContain( + "namespace App\Test\Services\\$service\Http\Resources;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Resource and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:resource', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $resourcePath = app_path("Test/Domains/$domain/Services/$service/Http/Resources/$class.php"); + + expect($resourcePath) + ->toBeFile("File not created at expected path:\n$resourcePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($resourcePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Http\Resources;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeRuleCommandTest.php b/tests/Feature/MakeRuleCommandTest.php index bed07d6..b463fe1 100644 --- a/tests/Feature/MakeRuleCommandTest.php +++ b/tests/Feature/MakeRuleCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:rule', function () { - it('should create Rule class with namespace and path created from configured vals', function (string $class) { + it('should create Rule and test in config path', function (string $class) { Config::set('laraca.struct.rule.path', 'Test/Rules'); artisan('make:rule', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $rulePath = app_path("Test/Rules/$class.php"); expect($rulePath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Rule and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:rule', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $rulePath = app_path("Test/Domains/$domain/Rules/$class.php"); + + expect($rulePath) + ->toBeFile("File not created at expected path:\n$rulePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($rulePath))->toContain( + "namespace App\Test\Domains\\$domain\Rules;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Rule and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:rule', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $rulePath = app_path("Test/Services/$service/Rules/$class.php"); + + expect($rulePath) + ->toBeFile("File not created at expected path:\n$rulePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($rulePath))->toContain( + "namespace App\Test\Services\\$service\Rules;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Rule and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:rule', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $rulePath = app_path("Test/Domains/$domain/Services/$service/Rules/$class.php"); + + expect($rulePath) + ->toBeFile("File not created at expected path:\n$rulePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($rulePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Rules;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeScopeCommandTest.php b/tests/Feature/MakeScopeCommandTest.php index d669953..a44cf05 100644 --- a/tests/Feature/MakeScopeCommandTest.php +++ b/tests/Feature/MakeScopeCommandTest.php @@ -7,14 +7,13 @@ use function Pest\Laravel\artisan; describe('make:scope', function () { - it('should create Scope class with namespace and path created from configured vals', function (string $class) { + it('should create Scope and test in config path', function (string $class) { Config::set('laraca.struct.model.path', 'Test/Data/Models'); artisan('make:scope', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $scopePath = app_path("Test/Data/Models/Scopes/$class.php"); expect($scopePath) @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Scope and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:scope', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $scopePath = app_path("Test/Domains/$domain/Data/Models/Scopes/$class.php"); + + expect($scopePath) + ->toBeFile("File not created at expected path:\n$scopePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($scopePath))->toContain( + "namespace App\Test\Domains\\$domain\Data\Models\Scopes;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Scope and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:scope', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $scopePath = app_path("Test/Services/$service/Data/Models/Scopes/$class.php"); + + expect($scopePath) + ->toBeFile("File not created at expected path:\n$scopePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($scopePath))->toContain( + "namespace App\Test\Services\\$service\Data\Models\Scopes;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Scope and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:scope', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $scopePath = app_path("Test/Domains/$domain/Services/$service/Data/Models/Scopes/$class.php"); + + expect($scopePath) + ->toBeFile("File not created at expected path:\n$scopePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($scopePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Data\Models\Scopes;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeSeederCommandTest.php b/tests/Feature/MakeSeederCommandTest.php index 0c99a1b..0963913 100644 --- a/tests/Feature/MakeSeederCommandTest.php +++ b/tests/Feature/MakeSeederCommandTest.php @@ -7,15 +7,14 @@ use function Pest\Laravel\artisan; describe('make:seeder', function () { - it('should create Seeder class with namespace and path created from configured vals', function (string $class) { + it('should create Seeder in config path', function (string $class) { Config::set('laraca.struct.database.path', 'test/database'); artisan('make:seeder', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - - $seederPath = base_path("test/database/seeders/$class.php"); + $class = getName($class); + $seederPath = base_path("test/database/seeders/{$class}.php"); expect($seederPath) ->toBeFile("File not created at expected path:\n$seederPath\n\nOutput results:\n$output\n=====\n"); @@ -25,4 +24,63 @@ "class $class", ); })->with('classes'); + + it('should create Seeder in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:seeder', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $seederPath = app_path("Test/Domains/$domain/database/seeders/{$class}.php"); + + expect($seederPath) + ->toBeFile("File not created at expected path:\n$seederPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($seederPath))->toContain( + "namespace App\Test\Domains\\$domain\Database\Seeders;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Seeder in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:seeder', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $seederPath = app_path("Test/Services/$service/database/seeders/{$class}.php"); + + expect($seederPath) + ->toBeFile("File not created at expected path:\n$seederPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($seederPath))->toContain( + "namespace App\Test\Services\\$service\Database\Seeders;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Seeder in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:seeder', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $seederPath = app_path("Test/Domains/$domain/Services/$service/database/seeders/{$class}.php"); + + expect($seederPath) + ->toBeFile("File not created at expected path:\n$seederPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($seederPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Database\Seeders;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeStrategyCommandTest.php b/tests/Feature/MakeStrategyCommandTest.php index 1844287..9982efb 100644 --- a/tests/Feature/MakeStrategyCommandTest.php +++ b/tests/Feature/MakeStrategyCommandTest.php @@ -7,13 +7,14 @@ use function Pest\Laravel\artisan; describe('make:strategy', function () { - it('should create strategy interface and concrete class with namespace and path created from configured vals', function (string $class) { + it('should create Strategy and test in config path', function (string $class) { Config::set('laraca.struct.strategy.path', 'Test/Strategy'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:strategy', ['name' => $class]); + artisan('make:strategy', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $class = ucfirst($class); + $class = getName($class); $strategyPath = app_path("Test/Strategy/Type{$class}Strategy.php"); $interfacePath = app_path("Test/Strategy/{$class}Strategy.php"); @@ -33,8 +34,140 @@ 'namespace App\Test\Strategy;', "interface {$class}Strategy", ); + + $classTest = getName($class)->start('Type')->finish('StrategyTest'); + $strategyTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($strategyTestPath) + ->toBeFile("File not created at expected path:\n$strategyTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyTestPath))->toContain( + 'namespace Test\Tests\Feature', + "class $classTest", + ); })->with('classes'); + it('should create Strategy and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:strategy', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + + $strategyPath = app_path("Test/Domains/$domain/Strategy/Type{$class}Strategy.php"); + $interfacePath = app_path("Test/Domains/$domain/Strategy/{$class}Strategy.php"); + + expect($strategyPath) + ->toBeFile("File not created at expected path:\n$strategyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyPath))->toContain( + "namespace App\Test\Domains\\$domain\Strategy;", + "class Type{$class}Strategy", + ); + + expect($interfacePath) + ->toBeFile("File not created at expected path:\n$interfacePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($interfacePath))->toContain( + "namespace App\Test\Domains\\$domain\Strategy;", + "interface {$class}Strategy", + ); + + $classTest = getName($class)->start('Type')->finish('StrategyTest'); + $strategyTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($strategyTestPath) + ->toBeFile("File not created at expected path:\n$strategyTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Strategy and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:strategy', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + + $strategyPath = app_path("Test/Services/$service/Strategy/Type{$class}Strategy.php"); + $interfacePath = app_path("Test/Services/$service/Strategy/{$class}Strategy.php"); + + expect($strategyPath) + ->toBeFile("File not created at expected path:\n$strategyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyPath))->toContain( + "namespace App\Test\Services\\$service\Strategy;", + "class Type{$class}Strategy", + ); + + expect($interfacePath) + ->toBeFile("File not created at expected path:\n$interfacePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($interfacePath))->toContain( + "namespace App\Test\Services\\$service\Strategy;", + "interface {$class}Strategy", + ); + + $classTest = getName($class)->start('Type')->finish('StrategyTest'); + $strategyTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($strategyTestPath) + ->toBeFile("File not created at expected path:\n$strategyTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Strategy and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:strategy', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $strategyPath = app_path("Test/Domains/$domain/Services/$service/Strategy/Type{$class}Strategy.php"); + $interfacePath = app_path("Test/Domains/$domain/Services/$service/Strategy/{$class}Strategy.php"); + + expect($strategyPath) + ->toBeFile("File not created at expected path:\n$strategyPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Strategy;", + "class Type{$class}Strategy", + ); + + expect($interfacePath) + ->toBeFile("File not created at expected path:\n$interfacePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($interfacePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Strategy;", + "interface {$class}Strategy", + ); + + $classTest = getName($class)->start('Type')->finish('StrategyTest'); + $strategyTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($strategyTestPath) + ->toBeFile("File not created at expected path:\n$strategyTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($strategyTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); + it('should not allow an existing strategy to be created', function (string $class) { Config::set('laraca.struct.strategy.path', 'Test/Strategy'); diff --git a/tests/Feature/MakeTestCommandTest.php b/tests/Feature/MakeTestCommandTest.php index 12b8f2e..4fa4b5c 100644 --- a/tests/Feature/MakeTestCommandTest.php +++ b/tests/Feature/MakeTestCommandTest.php @@ -7,41 +7,100 @@ use function Pest\Laravel\artisan; describe('make:test', function () { - it('should create Test class with namespace and path created from configured vals', function (string $class) { - Config::set('laraca.struct.test.path', 'test/tests'); + it('should create Test in config path', function (string $class) { + Config::set('laraca.struct.test.path', 'Test/tests'); artisan('make:test', ['name' => $class]); $output = Artisan::output(); - $class = ucfirst($class); - - $testPath = base_path("test/tests/Feature/$class.php"); + $class = getName($class); + $testPath = base_path("Test/tests/Feature/$class.php"); expect($testPath) ->toBeFile("File not created at expected path:\n$testPath\n\nOutput results:\n$output\n=====\n"); expect(File::get($testPath))->toContain( - 'namespace Tests\Feature;', + 'namespace Test\Tests\Feature;', "class $class", ); })->with('classes'); - it('should create Test class with namespace and path created from configured vals with unit option', function (string $class) { - Config::set('laraca.struct.test.path', 'test/tests'); + it('sshould create Test in config path with unit option', function (string $class) { + Config::set('laraca.struct.test.path', 'Test/tests'); artisan('make:test', ['name' => $class, '--unit' => true]); $output = Artisan::output(); - $class = ucfirst($class); + $class = getName($class); - $testPath = base_path("test/tests/Unit/$class.php"); + $testPath = base_path("Test/tests/Unit/$class.php"); expect($testPath) ->toBeFile("File not created at expected path:\n$testPath\n\nOutput results:\n$output\n=====\n"); expect(File::get($testPath))->toContain( - 'namespace Tests\Unit;', + 'namespace Test\Tests\Unit;', "class $class", ); })->with('classes'); + + it('should create Test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:test', ['name' => $class, '--domain' => $domain]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $testPath = app_path("Test/Domains/$domain/tests/Feature/$class.php"); + + expect($testPath) + ->toBeFile("File not created at expected path:\n$testPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($testPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:test', ['name' => $class, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $testPath = app_path("Test/Services/$service/tests/Feature/$class.php"); + + expect($testPath) + ->toBeFile("File not created at expected path:\n$testPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($testPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $class", + ); + })->with('classes', 'domains'); + + it('should create Test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:test', ['name' => $class, '--domain' => $domain, '--service' => $service]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $testPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$class.php"); + + expect($testPath) + ->toBeFile("File not created at expected path:\n$testPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($testPath))->toContain( + + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $class", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeValueCommandTest.php b/tests/Feature/MakeValueCommandTest.php index 2308620..841817e 100644 --- a/tests/Feature/MakeValueCommandTest.php +++ b/tests/Feature/MakeValueCommandTest.php @@ -7,14 +7,14 @@ use function Pest\Laravel\artisan; describe('make:value', function () { - it('should create Value class with namespace and path created from configured vals', function (string $class) { + it('should create Value and test in config path', function (string $class) { Config::set('laraca.struct.value.path', 'Test/Data/Values'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:value', ['name' => $class]); + artisan('make:value', ['name' => $class, '--test' => true]); $output = Artisan::output(); - $class = ucfirst($class); - + $class = getName($class); $valuePath = app_path("Test/Data/Values/$class.php"); expect($valuePath) @@ -24,5 +24,110 @@ 'namespace App\Test\Data\Values;', "class $class", ); + + $classTest = getName($class)->finish('Test'); + $valueTestPath = base_path("Test/tests/Feature/$classTest.php"); + + expect($valueTestPath) + ->toBeFile("File not created at expected path:\n$valueTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valueTestPath))->toContain( + 'namespace Test\Tests\Feature;', + "class $classTest", + ); })->with('classes'); + + it('should create Value and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:value', ['name' => $class, '--domain' => $domain, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $domain = getName($domain); + $valuePath = app_path("Test/Domains/$domain/Data/Values/$class.php"); + + expect($valuePath) + ->toBeFile("File not created at expected path:\n$valuePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valuePath))->toContain( + "namespace App\Test\Domains\\$domain\Data\Values;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $valueTestPath = app_path("Test/Domains/$domain/tests/Feature/$classTest.php"); + + expect($valueTestPath) + ->toBeFile("File not created at expected path:\n$valueTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valueTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Value and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:value', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $valuePath = app_path("Test/Services/$service/Data/Values/$class.php"); + + expect($valuePath) + ->toBeFile("File not created at expected path:\n$valuePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valuePath))->toContain( + "namespace App\Test\Services\\$service\Data\Values;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + + $valueTestPath = app_path("Test/Services/$service/tests/Feature/$classTest.php"); + + expect($valueTestPath) + ->toBeFile("File not created at expected path:\n$valueTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valueTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create Value and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:value', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $class = getName($class); + $service = getName($service); + $domain = getName($domain); + + $valuePath = app_path("Test/Domains/$domain/Services/$service/Data/Values/$class.php"); + + expect($valuePath) + ->toBeFile("File not created at expected path:\n$valuePath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valuePath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Data\Values;", + "class $class", + ); + + $classTest = getName($class)->finish('Test'); + $valueTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/$classTest.php"); + + expect($valueTestPath) + ->toBeFile("File not created at expected path:\n$valueTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($valueTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/Feature/MakeViewCommandTest.php b/tests/Feature/MakeViewCommandTest.php index 6c50876..3ee9397 100644 --- a/tests/Feature/MakeViewCommandTest.php +++ b/tests/Feature/MakeViewCommandTest.php @@ -7,10 +7,11 @@ use function Pest\Laravel\artisan; describe('make:view', function () { - it('should create blade file at package configured path', function (string $class) { + it('should create View and test in config path', function (string $class) { Config::set('laraca.struct.view.path', 'test/resources/views'); + Config::set('laraca.struct.test.path', 'Test/tests'); - artisan('make:view', ['name' => $class]); + artisan('make:view', ['name' => $class, '--test' => true]); $output = Artisan::output(); $viewPath = base_path("test/resources/views/{$class}.blade.php"); @@ -19,19 +20,97 @@ ->toBeFile("File not created at expected path:\n$viewPath\n\nOutput results:\n$output\n=====\n"); expect(File::get($viewPath))->toContain('
'); + + $class = strtolower($class); + $classTest = getName($class)->finish('Test'); + $viewTestPath = base_path("Test/tests/Feature/View/$classTest.php"); + + expect($viewTestPath) + ->toBeFile("File not created at expected path:\n$viewTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewTestPath))->toContain('namespace Test\Tests\Feature\View;'); })->with('classes'); - it('should create blade file at Laravel configured path when view not set in laraca config', function (string $class) { - Config::offsetUnset('view'); + it('should create View and test in config path with domain', function (string $class, string $domain) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); - artisan('make:view', ['name' => $class]); + artisan('make:view', ['name' => $class, '--domain' => $domain, '--test' => true]); $output = Artisan::output(); - $viewPath = base_path("resources/views/{$class}.blade.php"); + $domain = getName($domain); + $viewPath = app_path("Test/Domains/$domain/resources/views/{$class}.blade.php"); expect($viewPath) ->toBeFile("File not created at expected path:\n$viewPath\n\nOutput results:\n$output\n=====\n"); expect(File::get($viewPath))->toContain('
'); - })->with('classes'); + + $class = strtolower($class); + $classTest = getName($class)->finish('Test'); + $viewTestPath = app_path("Test/Domains/$domain/tests/Feature/View/$classTest.php"); + + expect($viewTestPath) + ->toBeFile("File not created at expected path:\n$viewTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Tests\Feature\View;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create View and test in config path with service', function (string $class, string $service) { + Config::set('laraca.struct.microservice.path', 'Test/Services'); + + artisan('make:view', ['name' => $class, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $service = getName($service); + $viewPath = app_path("Test/Services/$service/resources/views/{$class}.blade.php"); + + expect($viewPath) + ->toBeFile("File not created at expected path:\n$viewPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewPath))->toContain('
'); + + $class = strtolower($class); + $classTest = getName($class)->finish('Test'); + $viewTestPath = app_path("Test/Services/$service/tests/Feature/View/$classTest.php"); + + expect($viewTestPath) + ->toBeFile("File not created at expected path:\n$viewTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewTestPath))->toContain( + "namespace App\Test\Services\\$service\Tests\Feature\View;", + "class $classTest", + ); + })->with('classes', 'domains'); + + it('should create View and test in config path with domain service', function (string $class, string $domain, string $service) { + Config::set('laraca.struct.domain.path', 'Test/Domains'); + + artisan('make:view', ['name' => $class, '--domain' => $domain, '--service' => $service, '--test' => true]); + $output = Artisan::output(); + + $service = getName($service); + $domain = getName($domain); + + $viewPath = app_path("Test/Domains/$domain/Services/$service/resources/views/{$class}.blade.php"); + + expect($viewPath) + ->toBeFile("File not created at expected path:\n$viewPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewPath))->toContain('
'); + + $class = strtolower($class); + $classTest = getName($class)->finish('Test'); + $viewTestPath = app_path("Test/Domains/$domain/Services/$service/tests/Feature/View/$classTest.php"); + + expect($viewTestPath) + ->toBeFile("File not created at expected path:\n$viewTestPath\n\nOutput results:\n$output\n=====\n"); + + expect(File::get($viewTestPath))->toContain( + "namespace App\Test\Domains\\$domain\Services\\$service\Tests\Feature\View;", + "class $classTest", + ); + })->with('classes', 'domains', 'domains'); }); diff --git a/tests/LaracaTestCase.php b/tests/LaracaTestCase.php index 81c593f..a8917e6 100644 --- a/tests/LaracaTestCase.php +++ b/tests/LaracaTestCase.php @@ -20,18 +20,6 @@ protected function setUp(): void $this->withoutMockingConsoleOutput(); - $this->afterApplicationCreated(function () { - if (! File::exists(app_path('Test'))) { - File::makeDirectory(app_path('Test')); - } - if (! File::exists(base_path('test'))) { - File::makeDirectory(base_path('test')); - } - if (! File::exists(base_path('resources/views'))) { - File::makeDirectory(base_path('resources/views')); - } - }); - $this->beforeApplicationDestroyed(function () { if (File::exists(app_path('Test'))) { File::deleteDirectories(app_path('Test')); @@ -45,8 +33,11 @@ protected function setUp(): void if (File::exists(base_path('test'))) { File::deleteDirectories(base_path('test')); } - if (File::exists(base_path('resources/views'))) { - File::deleteDirectories(base_path('resources/views')); + if (File::exists(base_path('tests'))) { + File::deleteDirectories(base_path('tests')); + } + if (File::exists(base_path('resources'))) { + File::deleteDirectories(base_path('resources')); } }); } diff --git a/tests/Pest.php b/tests/Pest.php index 88778df..8518b89 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,7 @@ in(__DIR__); /** - * assemblePath - * - * @param string $key + * getConfigPath */ -function assembleFullPath($key, $domain = null, $service = null): string +function getConfigPath(string $key, ?string $domain = null, ?string $service = null): string { - return HandsomeBrown\Laraca\Traits\GetsConfigValues::assembleFullPath($key, $domain, $service); + return HandsomeBrown\Laraca\Traits\GetsConfigValues::getConfigPath($key, $domain, $service); } /** - * assembleNamespace - * - * @param string $key + * getConfigNamespace */ -function assembleNamespace($key): string +function getConfigNamespace(string $key): string { - return HandsomeBrown\Laraca\Traits\GetsConfigValues::assembleNamespace($key); + return HandsomeBrown\Laraca\Traits\GetsConfigValues::getConfigNamespace($key); } /** - * fullNamespaceStr + * getName + * + * @return \Illuminate\Support\Stringable */ -function fullNamespaceStr(string $namespace): string +function getName(string $name) { - return 'namespace '.$namespace.';'; + return Str::of($name)->ucfirst(); } diff --git a/tests/Unit/ConfigPathTest.php b/tests/Unit/ConfigPathTest.php index 5f73a3c..8cd1289 100644 --- a/tests/Unit/ConfigPathTest.php +++ b/tests/Unit/ConfigPathTest.php @@ -10,27 +10,27 @@ Config::set('laraca.struct.empty_key', []); Config::set('laraca.struct.command.parent', 'empty_key'); - assembleFullPath('command'); + getConfigPath('command'); })->with('classes')->throws(MissingPathNamespaceKeyException::class); it('throws an InvalidConfigKeyException when an initial key does not exist in the config', function () { - assembleFullPath('not_a_real_key'); + getConfigPath('not_a_real_key'); })->with('classes')->throws(InvalidConfigKeyException::class); it('throws an InvalidConfigKeyException when a parent key does not exist in the config', function () { Config::set('laraca.struct.model.parent', 'nonexistent_key'); - assembleFullPath('model'); + getConfigPath('model'); })->with('classes')->throws(InvalidConfigKeyException::class); it('throws a MissingRootPathException when a tree does not lead to a base or app parent', function () { Config::set('laraca.struct.model.parent', ''); - assembleFullPath('model'); + getConfigPath('model'); })->with('classes')->throws(MissingRootPathException::class); });