From d263500136dae086929c456f3e7539bdbc0a89c6 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 29 Apr 2025 06:45:57 +0100 Subject: [PATCH 01/21] feat: enhance PathNamespace trait with clean and namespace formatting methods - [test] Enhance PathNamespaceTest with additional path and namespace conversion tests - [feat] add module_path and module_app_path methods for improved module path handling - [refactor] fix trimming logic in clean() method for improved path handling - [fix] trim leading and trailing slashes in app path for consistency - [refactor] enhance path handling methods for improved clarity and consistency --- src/Traits/PathNamespace.php | 153 +++++++++++++++++++++++++++++------ 1 file changed, 129 insertions(+), 24 deletions(-) diff --git a/src/Traits/PathNamespace.php b/src/Traits/PathNamespace.php index 537aafe28..2e636cfee 100644 --- a/src/Traits/PathNamespace.php +++ b/src/Traits/PathNamespace.php @@ -7,7 +7,35 @@ trait PathNamespace { /** - * Get a well-formatted StudlyCase representation of path components. + * Clean up the given path/namespace, replacing directory separators. + */ + public function clean(string $path, string $ds = '/', string $replace = '\\'): string + { + if ($ds === $replace) { + $replace = $ds === '/' ? '\\' : '/'; + } + + return Str::of($path)->rtrim($ds)->replace($replace, $ds)->explode($ds)->filter(fn ($segment, $key) => $key == 0 or ! empty($segment))->implode($ds); + } + + /** + * Clean up the given path. + */ + public function clean_path(string $path, string $ds = '/', string $replace = '\\'): string + { + return $this->clean($path, $ds, $replace); + } + + /** + * Clean up the namespace, replacing directory separators. + */ + public function clean_namespace(string $namespace, string $ds = '\\', string $replace = '/'): string + { + return $this->clean($namespace, $ds, $replace); + } + + /** + * Get a well-formatted StudlyCase representation from the given path. */ public function studly_path(string $path, $ds = '/'): string { @@ -19,57 +47,134 @@ public function studly_path(string $path, $ds = '/'): string */ public function studly_namespace(string $namespace, $ds = '\\'): string { - return $this->studly_path($namespace, $ds); + return $this->studly_path($this->clean_namespace($namespace, $ds), $ds); } /** - * Get a well-formatted namespace from a given path. + * Generate a well-formatted StudlyCase namespace from the given path. */ public function path_namespace(string $path): string { - return Str::of($this->studly_path($path))->replace('/', '\\')->trim('\\'); + return $this->studly_namespace($this->is_app_path($path) ? $this->app_path($path) : $path); + } + + /** + * Get the path to the modules directory. + */ + public function modules_path(?string $path = null): string + { + $base = config('modules.paths.modules'); + + return $path ? $base.DIRECTORY_SEPARATOR.$this->path($path) : $base; + } + + public function module_path(string $module = 'Blog', ?string $path = null): string + { + $module = module($module, true); + + return $module->path($this->path($path)); + } + + public function module_app_path(string $module = 'Blog', ?string $path = null): string + { + $module = module($module, true); + + return $module->path($this->app_path($path)); } /** - * Get a well-formatted StudlyCase namespace for a module, with an optional additional path. + * Get a well-formatted StudlyCase namespace for the module, optionally appending the given path. */ public function module_namespace(string $module, ?string $path = null): string { - $module_namespace = config('modules.namespace', $this->path_namespace(config('modules.paths.modules'))).'\\'.($module); - $module_namespace .= strlen($path) ? '\\'.$this->path_namespace($path) : ''; + $module_namespace = rtrim(config('modules.namespace') ?? config('modules.paths.modules'), '\\').'\\'.($module); + if (! empty($path)) { + $module_namespace .= '\\'.trim($path, '\\'); + } + + return $this->path_namespace($module_namespace); + } - return $this->studly_namespace($module_namespace); + /** + * Format the given namespace and determine if it's within the app path. + */ + public function namespace(string $namespace): string + { + return $this->is_app_path($namespace) ? $this->app_path_namespace($namespace) : $this->path_namespace($namespace); } /** - * Clean path + * Format the given path and determine if it's within the app path. */ - public function clean_path(string $path, $ds = '/'): string + public function path(string $path): string { - return Str::of($path)->explode($ds)->reject(empty($path))->implode($ds); + return $this->is_app_path($path) ? $this->app_path($path) : $this->clean_path($path); } /** - * Get the app path basename. + * Get the base name of the app path. */ public function app_path(?string $path = null): string { - $config_path = config('modules.paths.app_folder'); + $default = 'app/'; + $app_path = config('modules.paths.app') ?? config('modules.paths.app_folder'); + + if (empty($app_path)) { + $app_path = $default; + } - // Get modules config app path or use Laravel default app path. - $app_path = strlen($config_path) ? $config_path : 'app/'; + $app_path = trim($this->clean_path($app_path), '/').'/'; + // Remove duplicated app_path if ($path) { - // Replace duplicate custom|default app paths - $replaces = array_unique([$this->clean_path($app_path).'/', 'app/']); - do { - $path = Str::of($path)->replaceStart($app_path, '')->replaceStart('app/', ''); - } while (Str::of($path)->startsWith($replaces)); - - // Append additional path - $app_path .= strlen($path) ? '/'.$path : ''; + $path = trim($this->clean_path($path), '/').'/'; + + while ($this->is_app_path($path)) { + $path = Str::of($path)->after('/'); + } + + // Append the extra path + $app_path .= ltrim($path, '/'); + } + + return $this->clean_path(trim($app_path, '/')); + } + + /** + * Determine whether the given path is within the app path. + */ + public function is_app_path(string $path): bool + { + $default = 'app/'; + $app_path = config('modules.paths.app') ?? config('modules.paths.app_folder'); + if (empty($app_path)) { + $app_path = $default; + } + $app_path = trim($this->clean_path($app_path), '/').'/'; + + $path = trim($this->clean_path($path), '/').'/'; + $replaces = array_filter(array_unique([$app_path, $default]), fn ($x) => Str::lower($x)); + + if (Str::of(Str::lower($path))->startsWith($replaces)) { + return true; } - return $this->clean_path($app_path); + return false; + } + + /** + * Get the namespace for the app path. + */ + public function app_path_namespace(?string $path = null): string + { + return $this->path_namespace($this->app_path($path)); + } + + /** + * Get the namespace for the module app path. + */ + public function modules_app_path_namespace(string $name, ?string $path = null): string + { + return $this->module_namespace($name, $this->app_path($path)); } } From 62d8e476afa9075d106c16305279c2e0c247ba00 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Mon, 28 Apr 2025 10:06:15 +0100 Subject: [PATCH 02/21] fix: update composer stub to use APP_PATH_NAMESPACE and APP_PATH instead of APP_FOLDER_NAME --- config/config.php | 3 ++- src/Commands/stubs/composer.stub | 2 +- src/Generators/ModuleGenerator.php | 12 +++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config/config.php b/config/config.php index 32f69c3c3..553851edf 100644 --- a/config/config.php +++ b/config/config.php @@ -70,7 +70,8 @@ 'AUTHOR_EMAIL', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE', - 'APP_FOLDER_NAME', + 'APP_PATH_NAMESPACE', + 'APP_PATH', ], ], 'gitkeep' => true, diff --git a/src/Commands/stubs/composer.stub b/src/Commands/stubs/composer.stub index d2ae16177..68e5b21ed 100644 --- a/src/Commands/stubs/composer.stub +++ b/src/Commands/stubs/composer.stub @@ -17,7 +17,7 @@ }, "autoload": { "psr-4": { - "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": "$APP_FOLDER_NAME$", + "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$APP_PATH_NAMESPACE$": "$APP_PATH$", "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Database\\Factories\\": "database/factories/", "$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Database\\Seeders\\": "database/seeders/" } diff --git a/src/Generators/ModuleGenerator.php b/src/Generators/ModuleGenerator.php index 59ef73ca9..15065b4e9 100644 --- a/src/Generators/ModuleGenerator.php +++ b/src/Generators/ModuleGenerator.php @@ -469,12 +469,18 @@ protected function getReplacement($stub): array $replacements = $this->module->config('stubs.replacements'); // Temporarily check if the replacements are defined; remove in the next major version. - if (! isset($replacements['composer']['APP_FOLDER_NAME'])) { - $replacements['composer'][] = 'APP_FOLDER_NAME'; + if (! isset($replacements['composer']['APP_PATH'])) { + $replacements['composer'][] = 'APP_PATH'; } + + if (! isset($replacements['composer']['APP_PATH_NAMESPACE'])) { + $replacements['composer'][] = 'APP_PATH_NAMESPACE'; + } + if (! isset($replacements['routes/web']['PLURAL_LOWER_NAME'])) { $replacements['routes/web'][] = 'PLURAL_LOWER_NAME'; } + if (! isset($replacements['routes/api']['PLURAL_LOWER_NAME'])) { $replacements['routes/api'][] = 'PLURAL_LOWER_NAME'; } @@ -629,7 +635,7 @@ protected function getAuthorEmailReplacement(): string } /** - * Get replacement for $APP_FOLDER_NAME$. + * Get replacement for $APP_PATH$. */ protected function getAppFolderNameReplacement(): string { From 8563991f7d83451e5c9aec5f13c8af1cf731c792 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Fri, 9 May 2025 06:39:46 +0100 Subject: [PATCH 03/21] refactor: enhance path and namespace handling in GeneratorPath class --- src/Support/Config/GeneratorPath.php | 41 ++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Support/Config/GeneratorPath.php b/src/Support/Config/GeneratorPath.php index 70df7998f..99c0e8796 100644 --- a/src/Support/Config/GeneratorPath.php +++ b/src/Support/Config/GeneratorPath.php @@ -6,7 +6,10 @@ class GeneratorPath { - use PathNamespace; + use PathNamespace { + path as __path; + namespace as __namespace; + } private $path; @@ -17,30 +20,52 @@ class GeneratorPath public function __construct($config) { if (is_array($config)) { - $this->path = $config['path']; + $this->path = $this->__path($config['path']); + $this->namespace = $config['namespace'] ?? $this->__namespace($config['path']); $this->generate = $config['generate']; - $this->namespace = $config['namespace'] ?? $this->path_namespace(ltrim($config['path'], config('modules.paths.app_folder', ''))); return; } - $this->path = $config; + $this->path = $this->__path($config ?? ''); + $this->namespace = $this->__namespace($config ?? ''); $this->generate = (bool) $config; - $this->namespace = $this->path_namespace(ltrim($config, config('modules.paths.app_folder', ''))); } + /** + * @deprecated use path() instead + */ public function getPath() { return $this->path; } - public function generate(): bool + /** + * Get the generator path. + */ + public function path(string $path = ''): string { - return $this->generate; + return $this->__path("{$this->path}/{$path}"); } + /** + * @deprecated use namespace() instead + */ public function getNamespace() { - return $this->studly_namespace($this->namespace); + return $this->__namespace($this->namespace); + } + + /** + * Get the generator namespace. + */ + public function namespace(string $namespace = ''): string + { + return $this->__namespace("{$this->namespace}\\{$namespace}"); + } + + public function generate(): bool + { + return $this->generate; } } From 8e0eeab5905724e579a8d5c73be9563c643e6eba Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 29 Apr 2025 07:19:14 +0100 Subject: [PATCH 04/21] fix: Create `getAppPathNamespaceReplacement()`, and refactor ModuleGenerator for improved namespace handling and code clarity --- src/Generators/ModuleGenerator.php | 56 ++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Generators/ModuleGenerator.php b/src/Generators/ModuleGenerator.php index 15065b4e9..31fceb9ac 100644 --- a/src/Generators/ModuleGenerator.php +++ b/src/Generators/ModuleGenerator.php @@ -74,7 +74,8 @@ class ModuleGenerator extends Generator * Module author */ protected array $author = [ - 'name', 'email', + 'name', + 'email', ]; /** @@ -322,7 +323,7 @@ public function generate(): int */ public function generateFolders() { - foreach ($this->getFolders() as $key => $folder) { + foreach (array_keys($this->getFolders()) as $key) { $folder = GenerateConfigReader::read($key); if ($folder->generate() === false) { @@ -540,17 +541,16 @@ private function generateModuleJsonFile() */ private function cleanModuleJsonFile() { - $path = $this->module->getModulePath($this->getName()).'module.json'; - - $content = $this->filesystem->get($path); - $namespace = $this->getModuleNamespaceReplacement(); - $studlyName = $this->getStudlyNameReplacement(); + $json = $this->module->getModulePath($this->getName()).'module.json'; - $provider = '"'.$namespace.'\\\\'.$studlyName.'\\\\Providers\\\\'.$studlyName.'ServiceProvider"'; + $content = $this->filesystem->get($json); + $name = $this->getStudlyNameReplacement(); + $namespace = $this->app_path(config('modules.paths.generator.provider.path').'/'."{$name}ServiceProvider"); - $content = str_replace($provider, '', $content); + $provider = Str::of($this->module_namespace($this->getName(), $namespace))->replace('\\', '\\\\'); + $content = str_replace('"'.$provider.'"', '', $content); - $this->filesystem->put($path, $content); + $this->filesystem->put($json, $content); } /** @@ -603,7 +603,8 @@ protected function getVendorReplacement(): string */ protected function getModuleNamespaceReplacement(): string { - return str_replace('\\', '\\\\', $this->module->config('namespace') ?? $this->path_namespace($this->module->config('paths.modules'))); + return str_replace('\\', '\\\\', $this->module->config('namespace') + ?? $this->namespace($this->module->config('paths.modules'))); } /** @@ -611,11 +612,8 @@ protected function getModuleNamespaceReplacement(): string */ private function getControllerNamespaceReplacement(): string { - if ($this->module->config('paths.generator.controller.namespace')) { - return $this->module->config('paths.generator.controller.namespace'); - } else { - return $this->path_namespace(ltrim($this->module->config('paths.generator.controller.path', 'app/Http/Controllers'), config('modules.paths.app_folder'))); - } + return $this->module->config('paths.generator.controller.namespace') + ?? $this->namespace($this->module->config('paths.generator.controller.path', 'app/Http/Controllers')); } /** @@ -635,16 +633,36 @@ protected function getAuthorEmailReplacement(): string } /** - * Get replacement for $APP_PATH$. + * Get replacement for $APP_FOLDER_NAME$. + * + * @deprecated use $APP_PATH$ instead of $APP_FOLDER_NAME$ */ protected function getAppFolderNameReplacement(): string { - return $this->module->config('paths.app_folder'); + return $this->app_path().'/'; + } + + /** + * Get replacement for $APP_PATH$. + */ + protected function getAppPathReplacement(): string + { + return $this->app_path().'/'; + } + + /** + * Get replacement for $APP_PATH_NAMESPACE$. + */ + protected function getAppPathNamespaceReplacement(): string + { + $namespace = $this->app_path_namespace(); + + return Str::of(strlen($namespace) ? $namespace.'\\' : $namespace)->replace('\\', '\\\\'); } protected function getProviderNamespaceReplacement(): string { - return str_replace('\\', '\\\\', GenerateConfigReader::read('provider')->getNamespace()); + return str_replace('\\', '\\\\', GenerateConfigReader::read('provider')->namespace()); } /** From 15c90ae18f5aa98d50180813e490206b1fcedd36 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 29 Apr 2025 09:08:23 +0100 Subject: [PATCH 05/21] Create `GeneratorCommand::default_namespace()` refactor: update `default_namespace()` method to accept a default path for improved flexibility refactor: update `default_namespace()` method to use an empty string as default value for improved clarity --- src/Commands/Make/ClassMakeCommand.php | 4 +--- src/Commands/Make/GeneratorCommand.php | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Commands/Make/ClassMakeCommand.php b/src/Commands/Make/ClassMakeCommand.php index a69ada417..fc09c03ff 100644 --- a/src/Commands/Make/ClassMakeCommand.php +++ b/src/Commands/Make/ClassMakeCommand.php @@ -84,8 +84,6 @@ public function typeClass(): string public function getDefaultNamespace(): string { - $type = $this->type(); - - return config("modules.paths.generator.{$type}.namespace", 'Classes'); + return $this->default_namespace($this->type(), "app/{$this->type()}"); } } diff --git a/src/Commands/Make/GeneratorCommand.php b/src/Commands/Make/GeneratorCommand.php index 94e8e0d8b..33310da9e 100644 --- a/src/Commands/Make/GeneratorCommand.php +++ b/src/Commands/Make/GeneratorCommand.php @@ -78,6 +78,14 @@ public function getDefaultNamespace(): string return ''; } + /** + * Get a default namespace from config. + */ + public function default_namespace(string $key, string $default = ''): string + { + return config("modules.paths.generator.{$key}.namespace") ?? $this->namespace(config("modules.paths.generator.{$key}.path") ?? $default); + } + /** * Get class namespace. * From 12a7b69e036ff9135959bcb2de16ecb0bccfb8b6 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 29 Apr 2025 10:03:55 +0100 Subject: [PATCH 06/21] fix: update app path configuration references to use 'paths.app' instead of 'paths.app_folder' --- config/config.php | 12 ++++++++---- src/Commands/Actions/ModelShowCommand.php | 2 +- src/Commands/Make/ActionMakeCommand.php | 2 +- src/Commands/Make/CastMakeCommand.php | 2 +- src/Commands/Make/ClassMakeCommand.php | 2 +- src/Commands/Make/EnumMakeCommand.php | 2 +- src/Commands/Make/ExceptionMakeCommand.php | 2 +- src/Commands/Make/HelperMakeCommand.php | 2 +- src/Commands/Make/InterfaceMakeCommand.php | 2 +- src/Commands/Make/RepositoryMakeCommand.php | 2 +- src/Commands/Make/ServiceMakeCommand.php | 2 +- src/Commands/Make/TraitMakeCommand.php | 2 +- src/Commands/Publish/PublishConfigurationCommand.php | 2 +- src/Commands/UpdatePhpunitCoverage.php | 2 +- src/Module.php | 4 +--- tests/BaseTestCase.php | 4 ++-- 16 files changed, 24 insertions(+), 22 deletions(-) diff --git a/config/config.php b/config/config.php index 553851edf..42d99a853 100644 --- a/config/config.php +++ b/config/config.php @@ -111,13 +111,17 @@ /* |-------------------------------------------------------------------------- - | The app path + | /app path |-------------------------------------------------------------------------- | - | app folder name - | for example can change it to 'src' or 'App' + | Specifies a custom path for the /app directory. + | + | Examples: + | '' => '/app' (default Laravel structure), + | 'src' => '/src' (custom location), + | '/' => '/' (root directory). */ - 'app_folder' => 'app/', + 'app' => '', /* |-------------------------------------------------------------------------- diff --git a/src/Commands/Actions/ModelShowCommand.php b/src/Commands/Actions/ModelShowCommand.php index fe6743437..d76822447 100644 --- a/src/Commands/Actions/ModelShowCommand.php +++ b/src/Commands/Actions/ModelShowCommand.php @@ -43,7 +43,7 @@ private function formatModuleNamespace(string $path): string Str::of($path) ->after(base_path().DIRECTORY_SEPARATOR) ->replace( - [config('modules.paths.app_folder'), '/', '.php'], + [config('modules.paths.app'), '/', '.php'], ['', '\\', ''], )->toString(); } diff --git a/src/Commands/Make/ActionMakeCommand.php b/src/Commands/Make/ActionMakeCommand.php index 58182868f..198a28b47 100644 --- a/src/Commands/Make/ActionMakeCommand.php +++ b/src/Commands/Make/ActionMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('actions')->getPath() ?? config('modules.paths.app_folder').'Actions'; + $filePath = GenerateConfigReader::read('actions')->getPath() ?? config('modules.paths.app').'Actions'; return $path.$filePath.'/'.$this->getActionName().'.php'; } diff --git a/src/Commands/Make/CastMakeCommand.php b/src/Commands/Make/CastMakeCommand.php index 13ba40b11..e248453a0 100644 --- a/src/Commands/Make/CastMakeCommand.php +++ b/src/Commands/Make/CastMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('casts')->getPath() ?? config('modules.paths.app_folder').'Casts'; + $filePath = GenerateConfigReader::read('casts')->getPath() ?? config('modules.paths.app').'Casts'; return $path.$filePath.'/'.$this->getCastName().'.php'; } diff --git a/src/Commands/Make/ClassMakeCommand.php b/src/Commands/Make/ClassMakeCommand.php index fc09c03ff..8517008dd 100644 --- a/src/Commands/Make/ClassMakeCommand.php +++ b/src/Commands/Make/ClassMakeCommand.php @@ -46,7 +46,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app_folder').'Classes'; + $filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app').'Classes'; return $this->typePath($path.$filePath.'/'.$this->getFileName().'.php'); } diff --git a/src/Commands/Make/EnumMakeCommand.php b/src/Commands/Make/EnumMakeCommand.php index 48d34ccdc..1adb87b2b 100644 --- a/src/Commands/Make/EnumMakeCommand.php +++ b/src/Commands/Make/EnumMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app_folder').'Enums'; + $filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app').'Enums'; return $path.$filePath.'/'.$this->getEnumName().'.php'; } diff --git a/src/Commands/Make/ExceptionMakeCommand.php b/src/Commands/Make/ExceptionMakeCommand.php index 343ebae6f..6bf83af43 100644 --- a/src/Commands/Make/ExceptionMakeCommand.php +++ b/src/Commands/Make/ExceptionMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('exceptions')->getPath() ?? config('modules.paths.app_folder').'Exceptions'; + $filePath = GenerateConfigReader::read('exceptions')->getPath() ?? config('modules.paths.app').'Exceptions'; return $path.$filePath.'/'.$this->getExceptionName().'.php'; } diff --git a/src/Commands/Make/HelperMakeCommand.php b/src/Commands/Make/HelperMakeCommand.php index b4f1bf072..399cfeba6 100644 --- a/src/Commands/Make/HelperMakeCommand.php +++ b/src/Commands/Make/HelperMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('helpers')->getPath() ?? config('modules.paths.app_folder').'Helpers'; + $filePath = GenerateConfigReader::read('helpers')->getPath() ?? config('modules.paths.app').'Helpers'; return $path.$filePath.'/'.$this->getHelperName().'.php'; } diff --git a/src/Commands/Make/InterfaceMakeCommand.php b/src/Commands/Make/InterfaceMakeCommand.php index 050843fc0..98a6c0955 100644 --- a/src/Commands/Make/InterfaceMakeCommand.php +++ b/src/Commands/Make/InterfaceMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('interfaces')->getPath() ?? config('modules.paths.app_folder').'Interfaces'; + $filePath = GenerateConfigReader::read('interfaces')->getPath() ?? config('modules.paths.app').'Interfaces'; return $path.$filePath.'/'.$this->getInterfaceName().'.php'; } diff --git a/src/Commands/Make/RepositoryMakeCommand.php b/src/Commands/Make/RepositoryMakeCommand.php index 7f8d14591..6b067a731 100644 --- a/src/Commands/Make/RepositoryMakeCommand.php +++ b/src/Commands/Make/RepositoryMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('repository')->getPath() ?? config('modules.paths.app_folder').'Repositories'; + $filePath = GenerateConfigReader::read('repository')->getPath() ?? config('modules.paths.app').'Repositories'; return $path.$filePath.'/'.$this->getRepositoryName().'.php'; } diff --git a/src/Commands/Make/ServiceMakeCommand.php b/src/Commands/Make/ServiceMakeCommand.php index 0f4a1cdb5..7f05a9147 100644 --- a/src/Commands/Make/ServiceMakeCommand.php +++ b/src/Commands/Make/ServiceMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('services')->getPath() ?? config('modules.paths.app_folder').'Services'; + $filePath = GenerateConfigReader::read('services')->getPath() ?? config('modules.paths.app').'Services'; return $path.$filePath.'/'.$this->getServiceName().'.php'; } diff --git a/src/Commands/Make/TraitMakeCommand.php b/src/Commands/Make/TraitMakeCommand.php index 7b0567d1a..885cc2658 100644 --- a/src/Commands/Make/TraitMakeCommand.php +++ b/src/Commands/Make/TraitMakeCommand.php @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); - $filePath = GenerateConfigReader::read('traits')->getPath() ?? config('modules.paths.app_folder').'Traits'; + $filePath = GenerateConfigReader::read('traits')->getPath() ?? config('modules.paths.app').'Traits'; return $path.$filePath.'/'.$this->getTraitName().'.php'; } diff --git a/src/Commands/Publish/PublishConfigurationCommand.php b/src/Commands/Publish/PublishConfigurationCommand.php index 156dd3022..6e4add7ba 100644 --- a/src/Commands/Publish/PublishConfigurationCommand.php +++ b/src/Commands/Publish/PublishConfigurationCommand.php @@ -41,7 +41,7 @@ private function getServiceProviderForModule(string $module): string $namespace = $this->laravel['config']->get('modules.namespace'); $studlyName = Str::studly($module); $provider = $this->laravel['config']->get('modules.paths.generator.provider.path'); - $provider = str_replace($this->laravel['config']->get('modules.paths.app_folder'), '', $provider); + $provider = str_replace($this->laravel['config']->get('modules.paths.app'), '', $provider); $provider = str_replace('/', '\\', $provider); return "$namespace\\$studlyName\\$provider\\{$studlyName}ServiceProvider"; diff --git a/src/Commands/UpdatePhpunitCoverage.php b/src/Commands/UpdatePhpunitCoverage.php index 8a17d8864..853931190 100644 --- a/src/Commands/UpdatePhpunitCoverage.php +++ b/src/Commands/UpdatePhpunitCoverage.php @@ -26,7 +26,7 @@ class UpdatePhpunitCoverage extends Command */ public function handle(): int { - $appFolder = config('modules.paths.app_folder', 'app/'); + $appFolder = config('modules.paths.app', 'app/'); $appFolder = rtrim($appFolder, '/').'/'; $phpunitXmlPath = base_path('phpunit.xml'); $modulesStatusPath = base_path('modules_statuses.json'); diff --git a/src/Module.php b/src/Module.php index 3f4bc79d0..0124463e6 100644 --- a/src/Module.php +++ b/src/Module.php @@ -168,9 +168,7 @@ public function getPath(): string */ public function getAppPath(): string { - $app_path = rtrim($this->getExtraPath(config('modules.paths.app_folder', '')), '/'); - - return is_dir($app_path) ? $app_path : $this->getPath(); + return $this->app_path(); } /** diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 6e8843905..a26c3fc15 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -58,7 +58,7 @@ protected function getEnvironmentSetUp($app) 'modules' => base_path('modules'), 'assets' => public_path('modules'), 'migration' => base_path('database/migrations'), - 'app_folder' => $module_config['paths']['app_folder'], + 'app' => $module_config['paths']['app'], 'generator' => $module_config['paths']['generator'], ]); @@ -79,7 +79,7 @@ protected function createModule(string $moduleName = 'Blog'): int protected function getModuleAppPath(string $moduleName = 'Blog'): string { - return base_path("modules/$moduleName/").rtrim(config('modules.paths.app_folder'), '/'); + return base_path("modules/$moduleName/").rtrim(config('modules.paths.app'), '/'); } protected function getModuleBasePath(string $moduleName = 'Blog'): string From 9439d2722fb3f2f9fe2507ec3cfa453e583103e5 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Thu, 1 May 2025 04:23:55 +0100 Subject: [PATCH 07/21] refactor: update `module_path` function to use `module` helper and the new `path` method for improved module retrieval --- src/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.php b/src/helpers.php index 9a3e6aaf6..6240a8bb2 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -32,7 +32,7 @@ function module(string $name, bool $instance = false): bool|Module if (! function_exists('module_path')) { function module_path(string $name, string $path = ''): string { - $module = app('modules')->find($name); + $module = module($name, true); return $module->getPath().($path ? DIRECTORY_SEPARATOR.$path : $path); } From cdfc9a97921fae53c846a5f2f5781430331d7262 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Mon, 5 May 2025 14:01:57 +0100 Subject: [PATCH 08/21] refactor: update paths in config for consistency and clarity --- config/config.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/config.php b/config/config.php index 42d99a853..4a3bb79d4 100644 --- a/config/config.php +++ b/config/config.php @@ -111,17 +111,17 @@ /* |-------------------------------------------------------------------------- - | /app path + | app/ path |-------------------------------------------------------------------------- | - | Specifies a custom path for the /app directory. + | Specifies a the path for the app/ directory. | | Examples: - | '' => '/app' (default Laravel structure), - | 'src' => '/src' (custom location), - | '/' => '/' (root directory). + | 'app/' = (default Laravel structure), + | 'src/' = (custom location), + | '/' = (root directory). */ - 'app' => '', + 'app' => 'app/', /* |-------------------------------------------------------------------------- @@ -152,7 +152,7 @@ 'policies' => ['path' => 'app/Policies', 'generate' => false], 'provider' => ['path' => 'app/Providers', 'generate' => true], 'repository' => ['path' => 'app/Repositories', 'generate' => false], - 'resource' => ['path' => 'app/Transformers', 'generate' => false], + 'resource' => ['path' => 'app/Resources', 'generate' => false], 'route-provider' => ['path' => 'app/Providers', 'generate' => true], 'rules' => ['path' => 'app/Rules', 'generate' => false], 'services' => ['path' => 'app/Services', 'generate' => false], From 09354a9f8c31e58cf21b19281cf62e0257aecad3 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 29 Apr 2025 09:57:35 +0100 Subject: [PATCH 09/21] refactor: standardize default namespace retrieval in command classes --- src/Commands/Make/ActionMakeCommand.php | 2 +- src/Commands/Make/CastMakeCommand.php | 2 +- src/Commands/Make/ChannelMakeCommand.php | 3 +-- src/Commands/Make/ClassMakeCommand.php | 2 +- src/Commands/Make/CommandMakeCommand.php | 3 +-- src/Commands/Make/ComponentClassMakeCommand.php | 3 +-- src/Commands/Make/ControllerMakeCommand.php | 3 +-- src/Commands/Make/EnumMakeCommand.php | 2 +- src/Commands/Make/EventMakeCommand.php | 3 +-- src/Commands/Make/EventProviderMakeCommand.php | 3 +-- src/Commands/Make/ExceptionMakeCommand.php | 2 +- src/Commands/Make/FactoryMakeCommand.php | 9 ++------- src/Commands/Make/HelperMakeCommand.php | 2 +- src/Commands/Make/InterfaceMakeCommand.php | 2 +- src/Commands/Make/JobMakeCommand.php | 3 +-- src/Commands/Make/ListenerMakeCommand.php | 3 +-- src/Commands/Make/MailMakeCommand.php | 3 +-- src/Commands/Make/MiddlewareMakeCommand.php | 3 +-- src/Commands/Make/ModelMakeCommand.php | 3 +-- src/Commands/Make/NotificationMakeCommand.php | 3 +-- src/Commands/Make/ObserverMakeCommand.php | 3 +-- src/Commands/Make/PolicyMakeCommand.php | 3 +-- src/Commands/Make/ProviderMakeCommand.php | 3 +-- src/Commands/Make/RepositoryMakeCommand.php | 2 +- src/Commands/Make/RequestMakeCommand.php | 3 +-- src/Commands/Make/ResourceMakeCommand.php | 3 +-- src/Commands/Make/RouteProviderMakeCommand.php | 7 ++----- src/Commands/Make/RuleMakeCommand.php | 3 +-- src/Commands/Make/ScopeMakeCommand.php | 7 +------ src/Commands/Make/SeedMakeCommand.php | 3 +-- src/Commands/Make/ServiceMakeCommand.php | 2 +- src/Commands/Make/TestMakeCommand.php | 6 ++---- src/Commands/Make/TraitMakeCommand.php | 2 +- 33 files changed, 36 insertions(+), 70 deletions(-) diff --git a/src/Commands/Make/ActionMakeCommand.php b/src/Commands/Make/ActionMakeCommand.php index 198a28b47..c30835def 100644 --- a/src/Commands/Make/ActionMakeCommand.php +++ b/src/Commands/Make/ActionMakeCommand.php @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.actions.namespace', 'Actions'); + return $this->default_namespace('actions'); } protected function getStubName(): string diff --git a/src/Commands/Make/CastMakeCommand.php b/src/Commands/Make/CastMakeCommand.php index e248453a0..80a9fa38b 100644 --- a/src/Commands/Make/CastMakeCommand.php +++ b/src/Commands/Make/CastMakeCommand.php @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.casts.namespace', 'Casts'); + return $this->default_namespace('casts'); } protected function getStubName(): string diff --git a/src/Commands/Make/ChannelMakeCommand.php b/src/Commands/Make/ChannelMakeCommand.php index 405d8400b..993c6f132 100644 --- a/src/Commands/Make/ChannelMakeCommand.php +++ b/src/Commands/Make/ChannelMakeCommand.php @@ -30,8 +30,7 @@ final class ChannelMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.channels.namespace') - ?? ltrim(config('modules.paths.generator.channels.path', 'Broadcasting'), config('modules.paths.app_folder', '')); + return $this->default_namespace('channels'); } /** diff --git a/src/Commands/Make/ClassMakeCommand.php b/src/Commands/Make/ClassMakeCommand.php index 8517008dd..50ecf94dc 100644 --- a/src/Commands/Make/ClassMakeCommand.php +++ b/src/Commands/Make/ClassMakeCommand.php @@ -84,6 +84,6 @@ public function typeClass(): string public function getDefaultNamespace(): string { - return $this->default_namespace($this->type(), "app/{$this->type()}"); + return $this->default_namespace($this->type(), $this->app_path("app/{$this->type()}")); } } diff --git a/src/Commands/Make/CommandMakeCommand.php b/src/Commands/Make/CommandMakeCommand.php index 66def43bc..03ed67a28 100644 --- a/src/Commands/Make/CommandMakeCommand.php +++ b/src/Commands/Make/CommandMakeCommand.php @@ -36,8 +36,7 @@ class CommandMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.command.namespace') - ?? ltrim(config('modules.paths.generator.command.path', 'Console'), config('modules.paths.app_folder', '')); + return $this->default_namespace('command'); } /** diff --git a/src/Commands/Make/ComponentClassMakeCommand.php b/src/Commands/Make/ComponentClassMakeCommand.php index d18d9caac..704d19e28 100644 --- a/src/Commands/Make/ComponentClassMakeCommand.php +++ b/src/Commands/Make/ComponentClassMakeCommand.php @@ -55,8 +55,7 @@ protected function writeComponentViewTemplate() public function getDefaultNamespace(): string { - return config('modules.paths.generator.component-class.namespace') - ?? ltrim(config('modules.paths.generator.component-class.path', 'View/Component'), config('modules.paths.app_folder', '')); + return $this->default_namespace('component-class'); } /** diff --git a/src/Commands/Make/ControllerMakeCommand.php b/src/Commands/Make/ControllerMakeCommand.php index 474c72919..777a0bfc1 100644 --- a/src/Commands/Make/ControllerMakeCommand.php +++ b/src/Commands/Make/ControllerMakeCommand.php @@ -118,8 +118,7 @@ private function getControllerNameWithoutNamespace() public function getDefaultNamespace(): string { - return config('modules.paths.generator.controller.namespace') - ?? ltrim(config('modules.paths.generator.controller.path', 'Http/Controllers'), config('modules.paths.app_folder')); + return $this->default_namespace('controller'); } /** diff --git a/src/Commands/Make/EnumMakeCommand.php b/src/Commands/Make/EnumMakeCommand.php index 1adb87b2b..652f68003 100644 --- a/src/Commands/Make/EnumMakeCommand.php +++ b/src/Commands/Make/EnumMakeCommand.php @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.enums.namespace', 'Enums'); + return $this->default_namespace('enums'); } protected function getStubName(): string diff --git a/src/Commands/Make/EventMakeCommand.php b/src/Commands/Make/EventMakeCommand.php index d411beb2f..a2c8c2bb6 100644 --- a/src/Commands/Make/EventMakeCommand.php +++ b/src/Commands/Make/EventMakeCommand.php @@ -57,8 +57,7 @@ protected function getFileName() public function getDefaultNamespace(): string { - return config('modules.paths.generator.event.namespace') - ?? ltrim(config('modules.paths.generator.event.path', 'Events'), config('modules.paths.app_folder', '')); + return $this->default_namespace('event'); } /** diff --git a/src/Commands/Make/EventProviderMakeCommand.php b/src/Commands/Make/EventProviderMakeCommand.php index d5722dc8b..1b17655ae 100644 --- a/src/Commands/Make/EventProviderMakeCommand.php +++ b/src/Commands/Make/EventProviderMakeCommand.php @@ -64,8 +64,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.provider.namespace') - ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); + return $this->default_namespace('provider'); } protected function getStubName(): string diff --git a/src/Commands/Make/ExceptionMakeCommand.php b/src/Commands/Make/ExceptionMakeCommand.php index 6bf83af43..ceb227994 100644 --- a/src/Commands/Make/ExceptionMakeCommand.php +++ b/src/Commands/Make/ExceptionMakeCommand.php @@ -67,7 +67,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.exceptions.namespace', 'Exceptions'); + return $this->default_namespace('exceptions'); } protected function getStubName(): string diff --git a/src/Commands/Make/FactoryMakeCommand.php b/src/Commands/Make/FactoryMakeCommand.php index 1542f7235..ef91d0cfc 100644 --- a/src/Commands/Make/FactoryMakeCommand.php +++ b/src/Commands/Make/FactoryMakeCommand.php @@ -93,8 +93,7 @@ private function getModelName() */ public function getDefaultNamespace(): string { - return config('modules.paths.generator.factory.namespace') - ?? ltrim(config('modules.paths.generator.factory.path', 'Database/Factories'), config('modules.paths.app_folder', '')); + return $this->default_namespace('factory'); } /** @@ -102,10 +101,6 @@ public function getDefaultNamespace(): string */ public function getModelNamespace(): string { - $path = ltrim(config('modules.paths.generator.model.path', 'Entities'), config('modules.paths.app_folder', '')); - - $path = str_replace('/', '\\', $path); - - return $this->laravel['modules']->config('namespace').'\\'.$this->laravel['modules']->findOrFail($this->getModuleName()).'\\'.$path; + return $this->module_namespace($this->argument('module'), $this->default_namespace('model')); } } diff --git a/src/Commands/Make/HelperMakeCommand.php b/src/Commands/Make/HelperMakeCommand.php index 399cfeba6..b52b3ff31 100644 --- a/src/Commands/Make/HelperMakeCommand.php +++ b/src/Commands/Make/HelperMakeCommand.php @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.helpers.namespace', 'Helpers'); + return $this->default_namespace('helpers'); } protected function getStubName(): string diff --git a/src/Commands/Make/InterfaceMakeCommand.php b/src/Commands/Make/InterfaceMakeCommand.php index 98a6c0955..ff96595a0 100644 --- a/src/Commands/Make/InterfaceMakeCommand.php +++ b/src/Commands/Make/InterfaceMakeCommand.php @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.interfaces.namespace', 'Interfaces'); + return $this->default_namespace('interfaces'); } protected function getStubName(): string diff --git a/src/Commands/Make/JobMakeCommand.php b/src/Commands/Make/JobMakeCommand.php index a6aa66e08..e1376b34c 100644 --- a/src/Commands/Make/JobMakeCommand.php +++ b/src/Commands/Make/JobMakeCommand.php @@ -31,8 +31,7 @@ class JobMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.jobs.namespace') - ?? ltrim(config('modules.paths.generator.jobs.path', 'Jobs'), config('modules.paths.app_folder', '')); + return $this->default_namespace('jobs'); } /** diff --git a/src/Commands/Make/ListenerMakeCommand.php b/src/Commands/Make/ListenerMakeCommand.php index 72052892f..e1844ec4a 100644 --- a/src/Commands/Make/ListenerMakeCommand.php +++ b/src/Commands/Make/ListenerMakeCommand.php @@ -70,8 +70,7 @@ protected function getTemplateContents() public function getDefaultNamespace(): string { - return config('modules.paths.generator.listener.namespace') - ?? ltrim(config('modules.paths.generator.listener.path', 'Listeners'), config('modules.paths.app_folder', '')); + return $this->default_namespace('listener'); } protected function getEventName(Module $module) diff --git a/src/Commands/Make/MailMakeCommand.php b/src/Commands/Make/MailMakeCommand.php index e07f76d9b..1963bd192 100644 --- a/src/Commands/Make/MailMakeCommand.php +++ b/src/Commands/Make/MailMakeCommand.php @@ -30,8 +30,7 @@ class MailMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.emails.namespace') - ?? ltrim(config('modules.paths.generator.emails.path', 'Emails'), config('modules.paths.app_folder', '')); + return $this->default_namespace('emails'); } /** diff --git a/src/Commands/Make/MiddlewareMakeCommand.php b/src/Commands/Make/MiddlewareMakeCommand.php index a31ece951..454790736 100644 --- a/src/Commands/Make/MiddlewareMakeCommand.php +++ b/src/Commands/Make/MiddlewareMakeCommand.php @@ -35,8 +35,7 @@ class MiddlewareMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.filter.namespace') - ?? ltrim(config('modules.paths.generator.filter.path', 'Http/Middleware'), config('modules.paths.app_folder', '')); + return $this->default_namespace('filter'); } /** diff --git a/src/Commands/Make/ModelMakeCommand.php b/src/Commands/Make/ModelMakeCommand.php index 22b545a19..38ddcf756 100644 --- a/src/Commands/Make/ModelMakeCommand.php +++ b/src/Commands/Make/ModelMakeCommand.php @@ -242,7 +242,6 @@ private function getFillable(): string */ public function getDefaultNamespace(): string { - return config('modules.paths.generator.model.namespace') - ?? ltrim(config('modules.paths.generator.model.path', 'Models'), config('modules.paths.app_folder', '')); + return $this->default_namespace('model'); } } diff --git a/src/Commands/Make/NotificationMakeCommand.php b/src/Commands/Make/NotificationMakeCommand.php index 28ccdeefa..5e7dfd599 100644 --- a/src/Commands/Make/NotificationMakeCommand.php +++ b/src/Commands/Make/NotificationMakeCommand.php @@ -30,8 +30,7 @@ final class NotificationMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.notifications.namespace') - ?? ltrim(config('modules.paths.generator.notifications.path', 'Notifications'), config('modules.paths.app_folder', '')); + return $this->default_namespace('notifications'); } /** diff --git a/src/Commands/Make/ObserverMakeCommand.php b/src/Commands/Make/ObserverMakeCommand.php index e1ae7a0af..a2c74776d 100644 --- a/src/Commands/Make/ObserverMakeCommand.php +++ b/src/Commands/Make/ObserverMakeCommand.php @@ -123,7 +123,6 @@ public function handle(): int */ public function getDefaultNamespace(): string { - return config('modules.paths.generator.observer.namespace') - ?? ltrim(config('modules.paths.generator.observer.path', 'Observers'), config('modules.paths.app_folder', '')); + return $this->default_namespace('observer'); } } diff --git a/src/Commands/Make/PolicyMakeCommand.php b/src/Commands/Make/PolicyMakeCommand.php index c4dfd6d78..519ab9164 100644 --- a/src/Commands/Make/PolicyMakeCommand.php +++ b/src/Commands/Make/PolicyMakeCommand.php @@ -35,8 +35,7 @@ class PolicyMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.policies.namespace') - ?? ltrim(config('modules.paths.generator.policies.path', 'Policies'), config('modules.paths.app_folder', '')); + return $this->default_namespace('policies'); } /** diff --git a/src/Commands/Make/ProviderMakeCommand.php b/src/Commands/Make/ProviderMakeCommand.php index 98315e3d4..e625171c1 100644 --- a/src/Commands/Make/ProviderMakeCommand.php +++ b/src/Commands/Make/ProviderMakeCommand.php @@ -37,8 +37,7 @@ class ProviderMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.provider.namespace') - ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); + return $this->default_namespace('provider'); } /** diff --git a/src/Commands/Make/RepositoryMakeCommand.php b/src/Commands/Make/RepositoryMakeCommand.php index 6b067a731..5044cb64c 100644 --- a/src/Commands/Make/RepositoryMakeCommand.php +++ b/src/Commands/Make/RepositoryMakeCommand.php @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.repository.namespace', 'Repositories'); + return $this->default_namespace('repository'); } protected function getStubName(): string diff --git a/src/Commands/Make/RequestMakeCommand.php b/src/Commands/Make/RequestMakeCommand.php index 3847e22f6..841917b7b 100644 --- a/src/Commands/Make/RequestMakeCommand.php +++ b/src/Commands/Make/RequestMakeCommand.php @@ -35,8 +35,7 @@ class RequestMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.request.namespace') - ?? ltrim(config('modules.paths.generator.request.path', 'Http/Requests'), config('modules.paths.app_folder', '')); + return $this->default_namespace('request'); } /** diff --git a/src/Commands/Make/ResourceMakeCommand.php b/src/Commands/Make/ResourceMakeCommand.php index 2b98f26bd..d108c2080 100644 --- a/src/Commands/Make/ResourceMakeCommand.php +++ b/src/Commands/Make/ResourceMakeCommand.php @@ -21,8 +21,7 @@ class ResourceMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.resource.namespace') - ?? ltrim(config('modules.paths.generator.resource.path', 'Transformers'), config('modules.paths.app_folder', '')); + return $this->default_namespace('resource'); } /** diff --git a/src/Commands/Make/RouteProviderMakeCommand.php b/src/Commands/Make/RouteProviderMakeCommand.php index 1ed3b901f..80a1b03be 100644 --- a/src/Commands/Make/RouteProviderMakeCommand.php +++ b/src/Commands/Make/RouteProviderMakeCommand.php @@ -109,14 +109,11 @@ protected function getApiRoutesPath() public function getDefaultNamespace(): string { - return config('modules.paths.generator.provider.namespace') - ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); + return $this->default_namespace('provider'); } private function getControllerNameSpace(): string { - $module = $this->laravel['modules']; - - return str_replace('/', '\\', $module->config('paths.generator.controller.namespace') ?: $module->config('paths.generator.controller.path', 'Controller')); + return $this->default_namespace('controller'); } } diff --git a/src/Commands/Make/RuleMakeCommand.php b/src/Commands/Make/RuleMakeCommand.php index 9242e5f4e..6bf8ddf3c 100644 --- a/src/Commands/Make/RuleMakeCommand.php +++ b/src/Commands/Make/RuleMakeCommand.php @@ -36,8 +36,7 @@ class RuleMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { - return config('modules.paths.generator.rules.namespace') - ?? ltrim(config('modules.paths.generator.rules.path', 'Rules'), config('modules.paths.app_folder', '')); + return $this->default_namespace('rules'); } /** diff --git a/src/Commands/Make/ScopeMakeCommand.php b/src/Commands/Make/ScopeMakeCommand.php index eef79316c..a4a3c5ab1 100644 --- a/src/Commands/Make/ScopeMakeCommand.php +++ b/src/Commands/Make/ScopeMakeCommand.php @@ -65,12 +65,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - $namespace = config('modules.paths.generator.model.path'); - - $parts = explode('/', $namespace); - $models = end($parts); - - return $models.'\Scopes'; + return $this->default_namespace('scopes'); } protected function getStubName(): string diff --git a/src/Commands/Make/SeedMakeCommand.php b/src/Commands/Make/SeedMakeCommand.php index e598eae85..a57e6e174 100644 --- a/src/Commands/Make/SeedMakeCommand.php +++ b/src/Commands/Make/SeedMakeCommand.php @@ -97,7 +97,6 @@ private function getSeederName(): string */ public function getDefaultNamespace(): string { - return config('modules.paths.generator.seeder.namespace') - ?? ltrim(config('modules.paths.generator.seeder.path', 'Database/Seeders'), config('modules.paths.app_folder', '')); + return $this->default_namespace('seeder'); } } diff --git a/src/Commands/Make/ServiceMakeCommand.php b/src/Commands/Make/ServiceMakeCommand.php index 7f05a9147..54a23c92f 100644 --- a/src/Commands/Make/ServiceMakeCommand.php +++ b/src/Commands/Make/ServiceMakeCommand.php @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.services.namespace', 'Services'); + return $this->default_namespace('services'); } protected function getStubName(): string diff --git a/src/Commands/Make/TestMakeCommand.php b/src/Commands/Make/TestMakeCommand.php index e2bacea1a..97ac9fd92 100644 --- a/src/Commands/Make/TestMakeCommand.php +++ b/src/Commands/Make/TestMakeCommand.php @@ -22,12 +22,10 @@ class TestMakeCommand extends GeneratorCommand public function getDefaultNamespace(): string { if ($this->option('feature')) { - return config('modules.paths.generator.test-feature.namespace') - ?? config('modules.paths.generator.test-feature.path', 'tests/Feature'); + return $this->default_namespace('test-feature'); } - return config('modules.paths.generator.test-unit.namespace') - ?? config('modules.paths.generator.test-unit.path', 'tests/Unit'); + return $this->default_namespace('test-unit'); } /** diff --git a/src/Commands/Make/TraitMakeCommand.php b/src/Commands/Make/TraitMakeCommand.php index 885cc2658..a51cc69dc 100644 --- a/src/Commands/Make/TraitMakeCommand.php +++ b/src/Commands/Make/TraitMakeCommand.php @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string public function getDefaultNamespace(): string { - return config('modules.paths.generator.traits.namespace', 'Traits'); + return $this->default_namespace('traits'); } protected function getStubName(): string From f51c99c09c79419b686c439852b0823ed8ed991c Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Mon, 5 May 2025 13:34:19 +0100 Subject: [PATCH 10/21] fix: update module path to use lowercase 'modules' for consistency --- config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.php b/config/config.php index 4a3bb79d4..33cffa6c4 100644 --- a/config/config.php +++ b/config/config.php @@ -86,7 +86,7 @@ | This path will also be added automatically to the list of scanned folders. | */ - 'modules' => base_path('Modules'), + 'modules' => base_path('modules'), /* |-------------------------------------------------------------------------- From 560730426b730b2232155ecefcd8578fda183968 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Mon, 5 May 2025 15:19:49 +0100 Subject: [PATCH 11/21] refactor: update `getDefaultNamespace()` method to specify default path for seeders --- src/Commands/Make/SeedMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Make/SeedMakeCommand.php b/src/Commands/Make/SeedMakeCommand.php index a57e6e174..c2697d433 100644 --- a/src/Commands/Make/SeedMakeCommand.php +++ b/src/Commands/Make/SeedMakeCommand.php @@ -97,6 +97,6 @@ private function getSeederName(): string */ public function getDefaultNamespace(): string { - return $this->default_namespace('seeder'); + return $this->default_namespace('seeder', 'database/seeds'); } } From 84cb1ba0b99d7f6b7ace2766a7d60cb2f20ac311 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Mon, 5 May 2025 15:20:14 +0100 Subject: [PATCH 12/21] feat: add language files for Recipe module with initial translations --- tests/stubs/valid/Recipe/lang/.gitkeep | 0 tests/stubs/valid/Recipe/lang/en/recipes.php | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/stubs/valid/Recipe/lang/.gitkeep create mode 100644 tests/stubs/valid/Recipe/lang/en/recipes.php diff --git a/tests/stubs/valid/Recipe/lang/.gitkeep b/tests/stubs/valid/Recipe/lang/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/stubs/valid/Recipe/lang/en/recipes.php b/tests/stubs/valid/Recipe/lang/en/recipes.php new file mode 100644 index 000000000..fbe468264 --- /dev/null +++ b/tests/stubs/valid/Recipe/lang/en/recipes.php @@ -0,0 +1,20 @@ + [ + 'recipes' => 'Recipe', + 'create recipe' => 'Create a recipe', + 'edit recipe' => 'Edit a recipe', + ], + 'button' => [ + 'create recipe' => 'Create a recipe', + ], + 'table' => [ + ], + 'form' => [ + ], + 'messages' => [ + ], + 'validation' => [ + ], +]; From f223fb521158e1c86ed05a595d4a01b6020dd70e Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Wed, 7 May 2025 03:38:37 +0100 Subject: [PATCH 13/21] refactor: streamline app path handling and enhance module namespace resolution --- src/Commands/Actions/ModelShowCommand.php | 6 ++---- src/Commands/BaseCommand.php | 2 ++ src/Commands/Publish/PublishConfigurationCommand.php | 5 +---- src/Commands/UpdatePhpunitCoverage.php | 8 +++++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Commands/Actions/ModelShowCommand.php b/src/Commands/Actions/ModelShowCommand.php index d76822447..c171cb834 100644 --- a/src/Commands/Actions/ModelShowCommand.php +++ b/src/Commands/Actions/ModelShowCommand.php @@ -42,10 +42,8 @@ private function formatModuleNamespace(string $path): string return Str::of($path) ->after(base_path().DIRECTORY_SEPARATOR) - ->replace( - [config('modules.paths.app'), '/', '.php'], - ['', '\\', ''], - )->toString(); + ->replace(['/', '.php'], ['\\', '']) + ->toString(); } public function findModels(string $model): Collection diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index ea1c229df..f549aa395 100644 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -8,6 +8,7 @@ use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Support\Collection; use Nwidart\Modules\Contracts\ConfirmableCommand; +use Nwidart\Modules\Traits\PathNamespace; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -18,6 +19,7 @@ abstract class BaseCommand extends Command implements PromptsForMissingInput { use ConfirmableTrait; + use PathNamespace; use Prohibitable; public const ALL = 'All'; diff --git a/src/Commands/Publish/PublishConfigurationCommand.php b/src/Commands/Publish/PublishConfigurationCommand.php index 6e4add7ba..d4b43ae41 100644 --- a/src/Commands/Publish/PublishConfigurationCommand.php +++ b/src/Commands/Publish/PublishConfigurationCommand.php @@ -38,13 +38,10 @@ public function getInfo(): ?string private function getServiceProviderForModule(string $module): string { - $namespace = $this->laravel['config']->get('modules.namespace'); $studlyName = Str::studly($module); $provider = $this->laravel['config']->get('modules.paths.generator.provider.path'); - $provider = str_replace($this->laravel['config']->get('modules.paths.app'), '', $provider); - $provider = str_replace('/', '\\', $provider); - return "$namespace\\$studlyName\\$provider\\{$studlyName}ServiceProvider"; + return $this->module_namespace($module, "$provider/{$studlyName}ServiceProvider"); } protected function getOptions(): array diff --git a/src/Commands/UpdatePhpunitCoverage.php b/src/Commands/UpdatePhpunitCoverage.php index 853931190..be1aeca9c 100644 --- a/src/Commands/UpdatePhpunitCoverage.php +++ b/src/Commands/UpdatePhpunitCoverage.php @@ -4,9 +4,12 @@ use DOMDocument; use Illuminate\Console\Command; +use Nwidart\Modules\Traits\PathNamespace; class UpdatePhpunitCoverage extends Command { + use PathNamespace; + /** * The name and signature of the console command. * @@ -26,8 +29,7 @@ class UpdatePhpunitCoverage extends Command */ public function handle(): int { - $appFolder = config('modules.paths.app', 'app/'); - $appFolder = rtrim($appFolder, '/').'/'; + $app_path = rtrim($this->app_path(), '/').'/'; $phpunitXmlPath = base_path('phpunit.xml'); $modulesStatusPath = base_path('modules_statuses.json'); @@ -56,7 +58,7 @@ public function handle(): int foreach ($enabledModules as $module => $status) { if ($status) { // Only add enabled modules - $moduleDir = $modulesPath.$module.'/'.$appFolder; + $moduleDir = $modulesPath.$module.'/'.$app_path; if (is_dir($moduleDir)) { $moduleDirs[] = $moduleDir; } From e609dee85f613a7b8fcd84dcd17c8fefa445c3db Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Tue, 6 May 2025 02:52:16 +0100 Subject: [PATCH 14/21] tests: Refactor module structure to use 'App' namespace by default for generated files - Updated namespaces in generated module files from 'Modules\Blog\Http\Controllers' to 'Modules\Blog\App\Http\Controllers'. - Changed service provider namespaces from 'Modules\Blog\Providers' to 'Modules\Blog\App\Providers'. - Adjusted repository, request, resource, and rule namespaces to follow the new structure. - Modified test snapshots to reflect the updated namespaces. - Cleaned up unnecessary module path variables in tests for better readability and maintainability. --- tests/BaseTestCase.php | 18 +- tests/Commands/Actions/ListCommandTest.php | 6 - .../Actions/ModuleDeleteCommandTest.php | 16 +- tests/Commands/Make/ActionMakeCommandTest.php | 37 ++-- tests/Commands/Make/CastMakeCommandTest.php | 21 +-- .../Commands/Make/ChannelMakeCommandTest.php | 18 +- tests/Commands/Make/ClassMakeCommandTest.php | 22 +-- .../Commands/Make/CommandMakeCommandTest.php | 20 +-- .../Make/ComponentClassMakeCommandTest.php | 16 +- .../Make/ComponentViewMakeCommandTest.php | 16 +- .../Make/ControllerMakeCommandTest.php | 33 ++-- tests/Commands/Make/EnumMakeCommandTest.php | 17 +- tests/Commands/Make/EventMakeCommandTest.php | 18 +- .../Make/EventProviderMakeCommandTest.php | 15 +- .../Make/ExceptionMakeCommandTest.php | 27 ++- .../Commands/Make/FactoryMakeCommandTest.php | 8 +- tests/Commands/Make/HelperMakeCommandTest.php | 23 +-- .../Make/InterfaceMakeCommandTest.php | 21 +-- tests/Commands/Make/JobMakeCommandTest.php | 20 +-- .../Commands/Make/ListenerMakeCommandTest.php | 28 ++- tests/Commands/Make/MailMakeCommandTest.php | 18 +- .../Make/MiddlewareMakeCommandTest.php | 18 +- .../Make/MigrationMakeCommandTest.php | 32 ++-- tests/Commands/Make/ModelMakeCommandTest.php | 60 +++---- tests/Commands/Make/ModuleMakeCommandTest.php | 165 ++++++++++-------- .../Make/NotificationMakeCommandTest.php | 18 +- .../Commands/Make/ObserverMakeCommandTest.php | 8 +- tests/Commands/Make/PolicyMakeCommandTest.php | 16 +- .../Commands/Make/ProviderMakeCommandTest.php | 22 +-- .../Make/RepositoryMakeCommandTest.php | 19 +- .../Commands/Make/RequestMakeCommandTest.php | 18 +- .../Commands/Make/ResourceMakeCommandTest.php | 30 ++-- .../Make/RouteProviderMakeCommandTest.php | 24 +-- tests/Commands/Make/RuleMakeCommandTest.php | 18 +- tests/Commands/Make/ScopeMakeCommandTest.php | 21 +-- .../Commands/Make/ServiceMakeCommandTest.php | 19 +- tests/Commands/Make/TestMakeCommandTest.php | 22 +-- tests/Commands/Make/TraitMakeCommandTest.php | 17 +- tests/Commands/Make/ViewMakeCommandTest.php | 11 +- ...test_generates_action_in_sub_folder__1.txt | 8 + ...generates_correct_file_with_content__1.txt | 8 + ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...est__test_changes_default_namespace__1.txt | 16 ++ ...mandTest__test_changes_default_path__1.txt | 16 ++ ...generated_correct_file_with_content__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...Test__test_changes_the_default_path__1.txt | 53 ++++++ ...it_can_change_the_default_namespace__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...t_it_uses_set_command_name_in_class__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 22 +++ ...generated_correct_file_with_content__1.txt | 2 +- ...roller_to_class_name_if_not_present__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 56 ++++++ ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...est_it_generates_a_plain_controller__1.txt | 2 +- ...test_it_generates_an_api_controller__1.txt | 2 +- ...t_generates_an_invokable_controller__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 31 ++++ ...generated_correct_file_with_content__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...eCommandTest__test_it_makes_factory__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 24 +++ ...generated_correct_file_with_content__1.txt | 2 +- ..._correct_sync_job_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 19 ++ ...rect_queued_duck_event_with_content__1.txt | 2 +- ...vent_in_a_subdirectory_with_content__1.txt | 2 +- ...d_correct_queued_event_with_content__1.txt | 2 +- ...orrect_sync_duck_event_with_content__1.txt | 2 +- ...vent_in_a_subdirectory_with_content__1.txt | 2 +- ...ted_correct_sync_event_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 26 +++ ...generated_correct_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 17 ++ ...generated_correct_file_with_content__1.txt | 2 +- ...est__test_changes_default_namespace__1.txt | 22 +++ ...mandTest__test_changes_default_path__1.txt | 22 +++ ...mandTest__test_generates_controller__1.txt | 56 ++++++ ...nd_migration_when_flags_are_present__1.txt | 56 ++++++ ...nd_migration_when_flags_are_present__2.txt | 28 +++ ...tes_controller_when_flag_is_present__1.txt | 56 ++++++ ...generates_correct_file_with_content__1.txt | 22 +++ ...t_generates_correct_fillable_fields__1.txt | 22 +++ ...nable_and_route_provider_is_disable__1.txt | 4 +- ...enable_and_route_provider_is_enable__1.txt | 4 +- ...enable_and_route_provider_is_enable__2.txt | 2 +- ...generates_api_module_with_resources__1.txt | 4 +- ...generates_api_module_with_resources__2.txt | 2 +- ...generates_api_module_with_resources__4.txt | 2 +- ...t__test_it_generates_api_route_file__1.txt | 2 +- ...ith_multi_segment_default_namespace__1.txt | 2 +- ...generates_correct_composerjson_file__1.txt | 2 +- ...est__test_it_generates_module_files__1.txt | 2 +- ..._module_namespace_using_studly_case__1.txt | 4 +- ..._test_it_generates_module_resources__1.txt | 4 +- ..._test_it_generates_module_resources__2.txt | 2 +- ..._test_it_generates_module_resources__3.txt | 2 +- ..._test_it_generates_module_resources__4.txt | 2 +- ...generates_web_module_with_resources__1.txt | 4 +- ...generates_web_module_with_resources__2.txt | 2 +- ...generates_web_module_with_resources__4.txt | 2 +- ...es_when_adding_more_than_one_option__1.txt | 4 +- ...es_when_adding_more_than_one_option__2.txt | 2 +- ...es_when_adding_more_than_one_option__4.txt | 2 +- ...t__test_it_generates_web_route_file__1.txt | 2 +- ...ith_multi_segment_default_namespace__1.txt | 2 +- ...odule_with_custom_provider_location__1.txt | 11 ++ ...odule_with_custom_provider_location__2.txt | 30 ++++ ...s_module_with_new_provider_location__2.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 45 +++++ ...generated_correct_file_with_content__1.txt | 2 +- ...CommandTest__test_it_makes_observer__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 15 ++ ...keCommandTest__test_it_makes_policy__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 154 ++++++++++++++++ ..._migration_resources_location_paths__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...vice_provider_with_resource_loading__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 24 +++ ...generated_correct_file_with_content__1.txt | 2 +- ...it_can_change_the_default_namespace__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 17 ++ ...enerate_a_collection_resource_class__1.txt | 4 +- ...generated_correct_file_with_content__1.txt | 4 +- ...test_it_can_change_the_default_path__1.txt | 50 ++++++ ...andTest__test_it_can_overwrite_file__1.txt | 2 +- ...t_it_can_overwrite_route_file_names__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...test_it_can_change_the_default_path__1.txt | 14 ++ ...ndTest__test_it_makes_implicit_rule__1.txt | 2 +- ...MakeCommandTest__test_it_makes_rule__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- ...mespace_with_correct_generated_file__1.txt | 2 +- ...generated_correct_file_with_content__1.txt | 2 +- tests/Commands/Publish/PublishCommandTest.php | 8 +- .../Publish/PublishMigrationCommandTest.php | 6 - .../Publish/PublishTranslationCommandTest.php | 6 - tests/HelpersTest.php | 6 - tests/LaravelFileRepositoryTest.php | 2 +- tests/ModuleHelperTest.php | 6 - .../Config/GenerateConfigReaderTest.php | 16 +- tests/Traits/PathNamespaceTest.php | 114 ++++++++++-- 159 files changed, 1509 insertions(+), 735 deletions(-) create mode 100644 tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_generates_action_in_sub_folder__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_generates_correct_file_with_content__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_changes_default_namespace__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_changes_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/CommandMakeCommandTest__test_changes_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ComponentClassMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/EventMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/JobMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ListenerMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_namespace__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__2.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_file_with_content__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_fillable_fields__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt create mode 100644 tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/PolicyMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/RequestMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/ResourceMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt create mode 100644 tests/Commands/Make/__snapshots__/RuleMakeCommandTest__test_it_can_change_the_default_path__1.txt diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index a26c3fc15..943d95938 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -4,10 +4,16 @@ use Nwidart\Modules\LaravelModulesServiceProvider; use Nwidart\Modules\Providers\ConsoleServiceProvider; +use Nwidart\Modules\Traits\PathNamespace; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class BaseTestCase extends OrchestraTestCase { + use PathNamespace { + module_path as __module_path; + module_app_path as __module_app_path; + } + protected function setUp(): void { parent::setUp(); @@ -72,18 +78,18 @@ protected function setUpDatabase() $this->resetDatabase(); } - protected function createModule(string $moduleName = 'Blog'): int + protected function createModule(string $module = 'Blog'): int { - return $this->artisan('module:make', ['name' => [$moduleName]]); + return $this->artisan('module:make', ['name' => [$module]]); } - protected function getModuleAppPath(string $moduleName = 'Blog'): string + protected function module_path(?string $path = null, string $module = 'Blog'): string { - return base_path("modules/$moduleName/").rtrim(config('modules.paths.app'), '/'); + return $this->modules_path("{$module}/{$path}"); } - protected function getModuleBasePath(string $moduleName = 'Blog'): string + protected function module_app_path(?string $path = null, string $module = 'Blog'): string { - return base_path("modules/$moduleName"); + return $this->module_path($this->app_path($path), $module); } } diff --git a/tests/Commands/Actions/ListCommandTest.php b/tests/Commands/Actions/ListCommandTest.php index 250be7635..dbb1c9060 100644 --- a/tests/Commands/Actions/ListCommandTest.php +++ b/tests/Commands/Actions/ListCommandTest.php @@ -7,16 +7,10 @@ class ListCommandTest extends BaseTestCase { - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void diff --git a/tests/Commands/Actions/ModuleDeleteCommandTest.php b/tests/Commands/Actions/ModuleDeleteCommandTest.php index 2f42a7e7f..4d7631823 100644 --- a/tests/Commands/Actions/ModuleDeleteCommandTest.php +++ b/tests/Commands/Actions/ModuleDeleteCommandTest.php @@ -58,14 +58,14 @@ public function test_it_can_delete_array_module_from_disk(): void foreach ($modules as $module) { $this->createModule($module); - $this->assertDirectoryExists($this->getModuleBasePath($module)); + $this->assertDirectoryExists($this->module_path(null, $module)); } $code = $this->artisan('module:delete', ['module' => ['Foo', 'Bar'], '--force' => true]); $this->assertSame(0, $code); - $this->assertFileDoesNotExist($this->getModuleBasePath('Foo')); - $this->assertFileDoesNotExist($this->getModuleBasePath('Bar')); - $this->assertDirectoryExists($this->getModuleBasePath('Zoo')); + $this->assertFileDoesNotExist($this->module_path(null, 'Foo')); + $this->assertFileDoesNotExist($this->module_path(null, 'Bar')); + $this->assertDirectoryExists($this->module_path(null, 'Zoo')); $this->app[RepositoryInterface::class]->delete('Zoo'); } @@ -80,14 +80,14 @@ public function test_it_can_delete_all_module_from_disk(): void foreach ($modules as $module) { $this->createModule($module); - $this->assertDirectoryExists($this->getModuleBasePath($module)); + $this->assertDirectoryExists($this->module_path(null, $module)); } $code = $this->artisan('module:delete', ['--all' => true, '--force' => true]); $this->assertSame(0, $code); - $this->assertFileDoesNotExist($this->getModuleBasePath('Foo')); - $this->assertFileDoesNotExist($this->getModuleBasePath('Bar')); - $this->assertFileDoesNotExist($this->getModuleBasePath('Zoo')); + $this->assertFileDoesNotExist($this->module_path(null, 'Foo')); + $this->assertFileDoesNotExist($this->module_path(null, 'Bar')); + $this->assertFileDoesNotExist($this->module_path(null, 'Zoo')); } public function test_it_deletes_modules_from_status_file(): void diff --git a/tests/Commands/Make/ActionMakeCommandTest.php b/tests/Commands/Make/ActionMakeCommandTest.php index 953ad0507..d814a8cda 100644 --- a/tests/Commands/Make/ActionMakeCommandTest.php +++ b/tests/Commands/Make/ActionMakeCommandTest.php @@ -15,18 +15,11 @@ class ActionMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -35,55 +28,47 @@ protected function tearDown(): void parent::tearDown(); } - public function test_it_generates_a_new_action_class() + public function test_generates_new_action_class() { $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertTrue(is_file($this->module_app_path('app/Actions/MyAction.php'))); $this->assertSame(0, $code); } - public function test_it_generates_a_new_action_class_can_override_with_force_option() + public function test_generates_new_action_class_with_force_option() { $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertTrue(is_file($this->module_app_path('app/Actions/MyAction.php'))); $this->assertSame(0, $code); } - public function test_it_generates_a_new_action_class_can_use_invoke_option() + public function test_generates_new_action_class_with_invoke_option() { $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog', '--invokable' => true]); - $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertTrue(is_file($this->module_app_path('app/Actions/MyAction.php'))); $this->assertSame(0, $code); } - public function test_it_generated_correct_file_with_content() + public function test_generates_correct_file_with_content() { $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Actions/MyAction.php'); + $file = $this->finder->get($this->module_app_path('app/Actions/MyAction.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_generate_a_action_in_sub_namespace_in_correct_folder() + public function test_generates_action_in_sub_folder() { $code = $this->artisan('module:make-action', ['name' => 'Api\\MyAction', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Actions/Api/MyAction.php')); - $this->assertSame(0, $code); - } - - public function test_it_can_generate_a_action_in_sub_namespace_with_correct_generated_file() - { - $code = $this->artisan('module:make-action', ['name' => 'Api\\MyAction', 'module' => 'Blog']); - - $file = $this->finder->get($this->modulePath.'/Actions/Api/MyAction.php'); - + $this->assertTrue(is_file($this->module_app_path('app/Actions/Api/MyAction.php'))); + $file = $this->finder->get($this->module_app_path('app/Actions/Api/MyAction.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } diff --git a/tests/Commands/Make/CastMakeCommandTest.php b/tests/Commands/Make/CastMakeCommandTest.php index cef20ce58..c06d8466e 100644 --- a/tests/Commands/Make/CastMakeCommandTest.php +++ b/tests/Commands/Make/CastMakeCommandTest.php @@ -15,18 +15,11 @@ class CastMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_cast_class() { $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Casts/MyCast.php')); + $this->assertTrue(is_file($this->module_app_path('app/Casts/MyCast.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_cast_class_can_override_with_force_optio $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Casts/MyCast.php')); + $this->assertTrue(is_file($this->module_app_path('app/Casts/MyCast.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Casts/MyCast.php'); + $file = $this->finder->get($this->module_app_path('app/Casts/MyCast.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -64,17 +57,17 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_cast_in_sub_namespace_in_correct_folder() { - $code = $this->artisan('module:make-cast', ['name' => 'Api\\MyCast', 'module' => 'Blog']); + $code = $this->artisan('module:make-cast', ['name' => 'Api/MyCast', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Casts/Api/MyCast.php')); + $this->assertTrue(is_file($this->module_app_path('app/Casts/Api/MyCast.php'))); $this->assertSame(0, $code); } public function test_it_can_generate_a_cast_in_sub_namespace_with_correct_generated_file() { - $code = $this->artisan('module:make-cast', ['name' => 'Api\\MyCast', 'module' => 'Blog']); + $code = $this->artisan('module:make-cast', ['name' => 'Api/MyCast', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Casts/Api/MyCast.php'); + $file = $this->finder->get($this->module_app_path('app/Casts/Api/MyCast.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ChannelMakeCommandTest.php b/tests/Commands/Make/ChannelMakeCommandTest.php index 7c1fd3b95..00d855c1d 100644 --- a/tests/Commands/Make/ChannelMakeCommandTest.php +++ b/tests/Commands/Make/ChannelMakeCommandTest.php @@ -15,17 +15,11 @@ class ChannelMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_the_channel_class() { $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Broadcasting/WelcomeChannel.php')); + $this->assertTrue(is_file($this->module_app_path('app/Broadcasting/WelcomeChannel.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Broadcasting/WelcomeChannel.php'); + $file = $this->finder->get($this->module_app_path('app/Broadcasting/WelcomeChannel.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_changes_default_path() { $this->app['config']->set('modules.paths.generator.channels.path', 'SuperChannel'); $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperChannel/WelcomeChannel.php'); + $file = $this->finder->get($this->module_path('SuperChannel/WelcomeChannel.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_changes_default_namespace() { $this->app['config']->set('modules.paths.generator.channels.namespace', 'SuperChannel'); $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Broadcasting/WelcomeChannel.php'); + $file = $this->finder->get($this->module_app_path('app/Broadcasting/WelcomeChannel.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ClassMakeCommandTest.php b/tests/Commands/Make/ClassMakeCommandTest.php index 2adce7ded..3ed434520 100644 --- a/tests/Commands/Make/ClassMakeCommandTest.php +++ b/tests/Commands/Make/ClassMakeCommandTest.php @@ -15,17 +15,11 @@ class ClassMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } @@ -39,7 +33,7 @@ public function test_it_generates_a_new_class() { $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertTrue(is_file($this->module_app_path('app/Classes/Demo.php'))); $this->assertSame(0, $code); } @@ -48,7 +42,7 @@ public function test_it_generates_a_new_class_can_override_with_force_option() $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertTrue(is_file($this->module_app_path('app/Classes/Demo.php'))); $this->assertSame(0, $code); } @@ -56,7 +50,7 @@ public function test_it_generates_a_new_class_can_use_invoke_option() { $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--invokable' => true]); - $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertTrue(is_file($this->module_app_path('app/Classes/Demo.php'))); $this->assertSame(0, $code); } @@ -64,7 +58,7 @@ public function test_it_generates_a_new_class_can_use_suffix_option() { $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--suffix' => true]); - $this->assertTrue(is_file($this->modulePath.'/Classes/DemoClass.php')); + $this->assertTrue(is_file($this->module_app_path('app/Classes/DemoClass.php'))); $this->assertSame(0, $code); } @@ -72,7 +66,7 @@ public function test_it_generates_a_new_class_use_type_option() { $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--type' => 'contract']); - $this->assertTrue(is_file($this->modulePath.'/Contracts/Demo.php')); + $this->assertTrue(is_file($this->module_app_path('app/Contracts/Demo.php'))); $this->assertSame(0, $code); } @@ -80,7 +74,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Classes/Demo.php'); + $file = $this->finder->get($this->module_app_path('app/Classes/Demo.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -90,7 +84,7 @@ public function test_it_can_generate_a_class_in_sub_namespace_in_correct_folder( { $code = $this->artisan('module:make-class', ['name' => 'Api\\Demo', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Classes/Api/Demo.php')); + $this->assertTrue(is_file($this->module_app_path('app/Classes/Api/Demo.php'))); $this->assertSame(0, $code); } @@ -98,7 +92,7 @@ public function test_it_can_generate_a_class_in_sub_namespace_with_correct_gener { $code = $this->artisan('module:make-class', ['name' => 'Api\\Demo', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Classes/Api/Demo.php'); + $file = $this->finder->get($this->module_app_path('app/Classes/Api/Demo.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/CommandMakeCommandTest.php b/tests/Commands/Make/CommandMakeCommandTest.php index dd2f2a082..f3d558d50 100644 --- a/tests/Commands/Make/CommandMakeCommandTest.php +++ b/tests/Commands/Make/CommandMakeCommandTest.php @@ -15,17 +15,11 @@ class CommandMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_a_new_console_command_class() { $code = $this->artisan('module:make-command', ['name' => 'MyAwesomeCommand', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Console/MyAwesomeCommand.php')); + $this->assertTrue(is_file($this->module_app_path('app/Console/MyAwesomeCommand.php'))); $this->assertSame(0, $code); } @@ -46,7 +40,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-command', ['name' => 'MyAwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Console/MyAwesomeCommand.php'); + $file = $this->finder->get($this->module_app_path('app/Console/MyAwesomeCommand.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -59,31 +53,31 @@ public function test_it_uses_set_command_name_in_class() ['name' => 'MyAwesomeCommand', 'module' => 'Blog', '--command' => 'my:awesome'] ); - $file = $this->finder->get($this->modulePath.'/Console/MyAwesomeCommand.php'); + $file = $this->finder->get($this->module_app_path('app/Console/MyAwesomeCommand.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_changes_the_default_path() { $this->app['config']->set('modules.paths.generator.command.path', 'app/CustomCommands'); $code = $this->artisan('module:make-command', ['name' => 'AwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/CustomCommands/AwesomeCommand.php'); + $file = $this->finder->get($this->module_app_path('app/CustomCommands/AwesomeCommand.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.command.namespace', 'Commands'); $code = $this->artisan('module:make-command', ['name' => 'AwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Console/AwesomeCommand.php'); + $file = $this->finder->get($this->module_app_path('app/Console/AwesomeCommand.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ComponentClassMakeCommandTest.php b/tests/Commands/Make/ComponentClassMakeCommandTest.php index ae32e6773..57de983ed 100644 --- a/tests/Commands/Make/ComponentClassMakeCommandTest.php +++ b/tests/Commands/Make/ComponentClassMakeCommandTest.php @@ -15,17 +15,11 @@ class ComponentClassMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -37,14 +31,14 @@ protected function tearDown(): void public function test_it_generates_the_component_class() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/View/Components/Blog.php')); + $this->assertTrue(is_file($this->module_app_path('app/View/Components/Blog.php'))); $this->assertSame(0, $code); } public function test_it_generates_the_component_view_from_component_class_command() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/resources/views/components/blog.blade.php'); + $file = $this->finder->get($this->module_path('resources/views/components/blog.blade.php')); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); } @@ -52,18 +46,18 @@ public function test_it_generates_the_component_view_from_component_class_comman public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/View/Components/Blog.php'); + $file = $this->finder->get($this->module_app_path('app/View/Components/Blog.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.component-class.path', 'View/Components/newDirectory'); $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/View/Components/newDirectory/Blog.php'); + $file = $this->finder->get($this->module_path('View/Components/newDirectory/Blog.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ComponentViewMakeCommandTest.php b/tests/Commands/Make/ComponentViewMakeCommandTest.php index 3be5bd352..eab557a23 100644 --- a/tests/Commands/Make/ComponentViewMakeCommandTest.php +++ b/tests/Commands/Make/ComponentViewMakeCommandTest.php @@ -15,17 +15,11 @@ class ComponentViewMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -37,25 +31,25 @@ protected function tearDown(): void public function test_it_generates_the_component_view() { $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $this->assertTrue(is_file($this->getModuleBasePath().'/resources/views/components/blog.blade.php')); + $this->assertTrue(is_file($this->module_path('resources/views/components/blog.blade.php'))); $this->assertSame(0, $code); } public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/resources/views/components/blog.blade.php'); + $file = $this->finder->get($this->module_path('resources/views/components/blog.blade.php')); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { - $this->app['config']->set('modules.paths.generator.component-view.path', 'Resources/views/components/newDirectory'); + $this->app['config']->set('modules.paths.generator.component-view.path', 'resources/views/components/newDirectory'); $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/Resources/views/components/newDirectory/blog.blade.php'); + $file = $this->finder->get($this->module_path('resources/views/components/newDirectory/blog.blade.php')); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ControllerMakeCommandTest.php b/tests/Commands/Make/ControllerMakeCommandTest.php index a6e876f88..7f9412d9c 100644 --- a/tests/Commands/Make/ControllerMakeCommandTest.php +++ b/tests/Commands/Make/ControllerMakeCommandTest.php @@ -15,18 +15,11 @@ class ControllerMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_controller_class() { $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/MyController.php')); + $this->assertTrue(is_file($this->module_app_path('app/Http/Controllers/MyController.php'))); $this->assertSame(0, $code); } @@ -47,7 +40,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -57,7 +50,7 @@ public function test_it_appends_controller_to_name_if_not_present() { $code = $this->artisan('module:make-controller', ['controller' => 'My', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/MyController.php')); + $this->assertTrue(is_file($this->module_app_path('app/Http/Controllers/MyController.php'))); $this->assertSame(0, $code); } @@ -65,7 +58,7 @@ public function test_it_appends_controller_to_class_name_if_not_present() { $code = $this->artisan('module:make-controller', ['controller' => 'My', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -79,7 +72,7 @@ public function test_it_generates_a_plain_controller() '--plain' => true, ]); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -93,7 +86,7 @@ public function test_it_generates_an_api_controller() '--api' => true, ]); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -107,31 +100,31 @@ public function test_it_generates_an_invokable_controller() '--invokable' => true, ]); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.controller.path', 'Controllers'); $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/Controllers/MyController.php'); + $file = $this->finder->get($this->module_path('Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.controller.namespace', 'Controllers'); $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -141,7 +134,7 @@ public function test_it_can_generate_a_controller_in_sub_namespace_in_correct_fo { $code = $this->artisan('module:make-controller', ['controller' => 'Api\\MyController', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/Api/MyController.php')); + $this->assertTrue(is_file($this->module_app_path('app/Http/Controllers/Api/MyController.php'))); $this->assertSame(0, $code); } @@ -149,7 +142,7 @@ public function test_it_can_generate_a_controller_in_sub_namespace_with_correct_ { $code = $this->artisan('module:make-controller', ['controller' => 'Api\\MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Controllers/Api/MyController.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Controllers/Api/MyController.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/EnumMakeCommandTest.php b/tests/Commands/Make/EnumMakeCommandTest.php index 5198cbb11..f0b7d6f99 100644 --- a/tests/Commands/Make/EnumMakeCommandTest.php +++ b/tests/Commands/Make/EnumMakeCommandTest.php @@ -15,18 +15,11 @@ class EnumMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_enum_class() { $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Enums/MyEnum.php')); + $this->assertTrue(is_file($this->module_app_path('app/Enums/MyEnum.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_enum_class_can_override_with_force_optio $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Enums/MyEnum.php')); + $this->assertTrue(is_file($this->module_app_path('app/Enums/MyEnum.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Enums/MyEnum.php'); + $file = $this->finder->get($this->module_app_path('app/Enums/MyEnum.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -66,7 +59,7 @@ public function test_it_can_generate_a_enum_in_sub_namespace_in_correct_folder() { $code = $this->artisan('module:make-enum', ['name' => 'Api\\MyEnum', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Enums/Api/MyEnum.php')); + $this->assertTrue(is_file($this->module_app_path('app/Enums/Api/MyEnum.php'))); $this->assertSame(0, $code); } @@ -74,7 +67,7 @@ public function test_it_can_generate_a_enum_in_sub_namespace_with_correct_genera { $code = $this->artisan('module:make-enum', ['name' => 'Api\\MyEnum', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Enums/Api/MyEnum.php'); + $file = $this->finder->get($this->module_app_path('app/Enums/Api/MyEnum.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/EventMakeCommandTest.php b/tests/Commands/Make/EventMakeCommandTest.php index 99d6c7efd..fd637be09 100644 --- a/tests/Commands/Make/EventMakeCommandTest.php +++ b/tests/Commands/Make/EventMakeCommandTest.php @@ -15,17 +15,11 @@ class EventMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_a_new_event_class() { $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Events/PostWasCreated.php')); + $this->assertTrue(is_file($this->module_app_path('app/Events/PostWasCreated.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Events/PostWasCreated.php'); + $file = $this->finder->get($this->module_app_path('app/Events/PostWasCreated.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.event.path', 'SuperEvents'); $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperEvents/PostWasCreated.php'); + $file = $this->finder->get($this->module_path('SuperEvents/PostWasCreated.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.event.namespace', 'SuperEvents'); $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Events/PostWasCreated.php'); + $file = $this->finder->get($this->module_app_path('app/Events/PostWasCreated.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/EventProviderMakeCommandTest.php b/tests/Commands/Make/EventProviderMakeCommandTest.php index e028eda0e..6bd9ac9ca 100644 --- a/tests/Commands/Make/EventProviderMakeCommandTest.php +++ b/tests/Commands/Make/EventProviderMakeCommandTest.php @@ -15,18 +15,11 @@ class EventProviderMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,8 +32,8 @@ public function test_it_generates_a_new_event_provider_class() { $code = $this->artisan('module:make-event-provider', ['module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Providers/EventServiceProvider.php')); - $this->assertSame(1, $code); + $this->assertTrue(is_file($this->module_app_path('app/Providers/EventServiceProvider.php'))); + $this->assertSame(0, $code); } public function test_it_generates_a_new_event_provider_class_can_override_with_force_option() @@ -48,7 +41,7 @@ public function test_it_generates_a_new_event_provider_class_can_override_with_f $this->artisan('module:make-event-provider', ['module' => 'Blog']); $code = $this->artisan('module:make-event-provider', ['module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Providers/EventServiceProvider.php')); + $this->assertTrue(is_file($this->module_app_path('app/Providers/EventServiceProvider.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-event-provider', ['module' => 'Blog', '--force' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/EventServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/EventServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ExceptionMakeCommandTest.php b/tests/Commands/Make/ExceptionMakeCommandTest.php index ecb203eb0..d37ce743a 100644 --- a/tests/Commands/Make/ExceptionMakeCommandTest.php +++ b/tests/Commands/Make/ExceptionMakeCommandTest.php @@ -15,18 +15,11 @@ class ExceptionMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_exception_class() { $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/MyException.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_exception_class_can_override_with_force_ $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/MyException.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generates_a_new_exception_class_can_use_render_option() { $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--render' => true]); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/MyException.php'))); $this->assertSame(0, $code); } @@ -64,7 +57,7 @@ public function test_it_generates_a_new_exception_class_can_use_report_option() { $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--report' => true]); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/MyException.php'))); $this->assertSame(0, $code); } @@ -72,7 +65,7 @@ public function test_it_generates_a_new_exception_class_can_use_report_and_rende { $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--report' => true, '--render' => true]); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/MyException.php'))); $this->assertSame(0, $code); } @@ -80,7 +73,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Exceptions/MyException.php'); + $file = $this->finder->get($this->module_app_path('app/Exceptions/MyException.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -88,17 +81,17 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_exception_in_sub_namespace_in_correct_folder() { - $code = $this->artisan('module:make-exception', ['name' => 'Api\\MyException', 'module' => 'Blog']); + $code = $this->artisan('module:make-exception', ['name' => 'Api/MyException', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Exceptions/Api/MyException.php')); + $this->assertTrue(is_file($this->module_app_path('app/Exceptions/Api/MyException.php'))); $this->assertSame(0, $code); } public function test_it_can_generate_a_exception_in_sub_namespace_with_correct_generated_file() { - $code = $this->artisan('module:make-exception', ['name' => 'Api\\MyException', 'module' => 'Blog']); + $code = $this->artisan('module:make-exception', ['name' => 'Api/MyException', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Exceptions/Api/MyException.php'); + $file = $this->finder->get($this->module_app_path('app/Exceptions/Api/MyException.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/FactoryMakeCommandTest.php b/tests/Commands/Make/FactoryMakeCommandTest.php index 8f5c04b2f..027fc638c 100644 --- a/tests/Commands/Make/FactoryMakeCommandTest.php +++ b/tests/Commands/Make/FactoryMakeCommandTest.php @@ -15,17 +15,11 @@ class FactoryMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_makes_factory() { $code = $this->artisan('module:make-factory', ['name' => 'Post', 'module' => 'Blog']); - $factoryFile = $this->getModuleBasePath().'/database/factories/PostFactory.php'; + $factoryFile = $this->module_path('database/factories/PostFactory.php'); $this->assertTrue(is_file($factoryFile), 'Factory file was not created.'); $this->assertMatchesSnapshot($this->finder->get($factoryFile)); diff --git a/tests/Commands/Make/HelperMakeCommandTest.php b/tests/Commands/Make/HelperMakeCommandTest.php index 38e3964fa..401d88046 100644 --- a/tests/Commands/Make/HelperMakeCommandTest.php +++ b/tests/Commands/Make/HelperMakeCommandTest.php @@ -15,18 +15,11 @@ class HelperMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_helper_class() { $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertTrue(is_file($this->module_app_path('app/Helpers/MyHelper.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_helper_class_can_override_with_force_opt $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertTrue(is_file($this->module_app_path('app/Helpers/MyHelper.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generates_a_new_helper_class_can_use_invoke_option() { $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog', '--invokable' => true]); - $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertTrue(is_file($this->module_app_path('app/Helpers/MyHelper.php'))); $this->assertSame(0, $code); } @@ -64,7 +57,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Helpers/MyHelper.php'); + $file = $this->finder->get($this->module_app_path('app/Helpers/MyHelper.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -72,17 +65,17 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_helper_in_sub_namespace_in_correct_folder() { - $code = $this->artisan('module:make-helper', ['name' => 'Api\\MyHelper', 'module' => 'Blog']); + $code = $this->artisan('module:make-helper', ['name' => 'Api/MyHelper', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Helpers/Api/MyHelper.php')); + $this->assertTrue(is_file($this->module_app_path('app/Helpers/Api/MyHelper.php'))); $this->assertSame(0, $code); } public function test_it_can_generate_a_helper_in_sub_namespace_with_correct_generated_file() { - $code = $this->artisan('module:make-helper', ['name' => 'Api\\MyHelper', 'module' => 'Blog']); + $code = $this->artisan('module:make-helper', ['name' => 'Api/MyHelper', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Helpers/Api/MyHelper.php'); + $file = $this->finder->get($this->module_app_path('app/Helpers/Api/MyHelper.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/InterfaceMakeCommandTest.php b/tests/Commands/Make/InterfaceMakeCommandTest.php index a269ebfb9..b28012c0d 100644 --- a/tests/Commands/Make/InterfaceMakeCommandTest.php +++ b/tests/Commands/Make/InterfaceMakeCommandTest.php @@ -15,18 +15,11 @@ class InterfaceMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_interface_class() { $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Interfaces/MyInterface.php')); + $this->assertTrue(is_file($this->module_app_path('app/Interfaces/MyInterface.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_interface_class_can_override_with_force_ $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Interfaces/MyInterface.php')); + $this->assertTrue(is_file($this->module_app_path('app/Interfaces/MyInterface.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Interfaces/MyInterface.php'); + $file = $this->finder->get($this->module_app_path('app/Interfaces/MyInterface.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -64,17 +57,17 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_interface_in_sub_namespace_in_correct_folder() { - $code = $this->artisan('module:make-interface', ['name' => 'Api\\MyInterface', 'module' => 'Blog']); + $code = $this->artisan('module:make-interface', ['name' => 'Api/MyInterface', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Interfaces/Api/MyInterface.php')); + $this->assertTrue(is_file($this->module_app_path('app/Interfaces/Api/MyInterface.php'))); $this->assertSame(0, $code); } public function test_it_can_generate_a_interface_in_sub_namespace_with_correct_generated_file() { - $code = $this->artisan('module:make-interface', ['name' => 'Api\\MyInterface', 'module' => 'Blog']); + $code = $this->artisan('module:make-interface', ['name' => 'Api/MyInterface', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Interfaces/Api/MyInterface.php'); + $file = $this->finder->get($this->module_app_path('app/Interfaces/Api/MyInterface.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/JobMakeCommandTest.php b/tests/Commands/Make/JobMakeCommandTest.php index 0c3495f1e..78fa53ccc 100644 --- a/tests/Commands/Make/JobMakeCommandTest.php +++ b/tests/Commands/Make/JobMakeCommandTest.php @@ -15,17 +15,11 @@ class JobMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_the_job_class() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Jobs/SomeJob.php')); + $this->assertTrue(is_file($this->module_app_path('app/Jobs/SomeJob.php'))); $this->assertSame(0, $code); } @@ -46,7 +40,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); + $file = $this->finder->get($this->module_app_path('app/Jobs/SomeJob.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -56,31 +50,31 @@ public function test_it_generated_correct_sync_job_file_with_content() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog', '--sync' => true]); - $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); + $file = $this->finder->get($this->module_app_path('app/Jobs/SomeJob.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.jobs.path', 'SuperJobs'); $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperJobs/SomeJob.php'); + $file = $this->finder->get($this->module_path('/SuperJobs/SomeJob.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.jobs.namespace', 'SuperJobs'); $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); + $file = $this->finder->get($this->module_app_path('app/Jobs/SomeJob.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ListenerMakeCommandTest.php b/tests/Commands/Make/ListenerMakeCommandTest.php index 4282d50c6..cad028ef9 100644 --- a/tests/Commands/Make/ListenerMakeCommandTest.php +++ b/tests/Commands/Make/ListenerMakeCommandTest.php @@ -15,17 +15,11 @@ class ListenerMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -41,7 +35,7 @@ public function test_it_generates_a_new_event_class() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated'] ); - $this->assertTrue(is_file($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php')); + $this->assertTrue(is_file($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php'))); $this->assertSame(0, $code); } @@ -52,7 +46,7 @@ public function test_it_generated_correct_sync_event_with_content() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated'] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -65,7 +59,7 @@ public function test_it_generated_correct_sync_event_in_a_subdirectory_with_cont ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'User/WasCreated'] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -78,7 +72,7 @@ public function test_it_generated_correct_sync_duck_event_with_content() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -91,7 +85,7 @@ public function test_it_generated_correct_queued_event_with_content() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated', '--queued' => true] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -104,7 +98,7 @@ public function test_it_generated_correct_queued_event_in_a_subdirectory_with_co ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'User/WasCreated', '--queued' => true] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -117,13 +111,13 @@ public function test_it_generated_correct_queued_duck_event_with_content() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--queued' => true] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.listener.path', 'Events/Handlers'); @@ -132,13 +126,13 @@ public function test_it_can_change_the_default_namespace() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->getModuleBasePath().'/Events/Handlers/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_path('/Events/Handlers/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.listener.namespace', 'Events\\Handlers'); @@ -147,7 +141,7 @@ public function test_it_can_change_the_default_namespace_specific() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->module_app_path('app/Listeners/NotifyUsersOfANewPost.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/MailMakeCommandTest.php b/tests/Commands/Make/MailMakeCommandTest.php index dee2d69e0..1be6faa2b 100644 --- a/tests/Commands/Make/MailMakeCommandTest.php +++ b/tests/Commands/Make/MailMakeCommandTest.php @@ -15,17 +15,11 @@ class MailMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_the_mail_class() { $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Emails/SomeMail.php')); + $this->assertTrue(is_file($this->module_app_path('app/Emails/SomeMail.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Emails/SomeMail.php'); + $file = $this->finder->get($this->module_app_path('app/Emails/SomeMail.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.emails.path', 'SuperEmails'); $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperEmails/SomeMail.php'); + $file = $this->finder->get($this->module_path('/SuperEmails/SomeMail.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.emails.namespace', 'SuperEmails'); $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Emails/SomeMail.php'); + $file = $this->finder->get($this->module_app_path('app/Emails/SomeMail.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/MiddlewareMakeCommandTest.php b/tests/Commands/Make/MiddlewareMakeCommandTest.php index bf9e744e5..72cb4b944 100644 --- a/tests/Commands/Make/MiddlewareMakeCommandTest.php +++ b/tests/Commands/Make/MiddlewareMakeCommandTest.php @@ -15,17 +15,11 @@ class MiddlewareMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_a_new_middleware_class() { $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Http/Middleware/SomeMiddleware.php')); + $this->assertTrue(is_file($this->module_app_path('app/Http/Middleware/SomeMiddleware.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Middleware/SomeMiddleware.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.filter.path', 'Middleware'); $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->module_path('Middleware/SomeMiddleware.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.filter.namespace', 'Middleware'); $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->module_app_path('app/Http/Middleware/SomeMiddleware.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/MigrationMakeCommandTest.php b/tests/Commands/Make/MigrationMakeCommandTest.php index b643915dd..36e36b173 100644 --- a/tests/Commands/Make/MigrationMakeCommandTest.php +++ b/tests/Commands/Make/MigrationMakeCommandTest.php @@ -15,17 +15,11 @@ class MigrationMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleBasePath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_a_new_migration_class() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); - $files = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $files = $this->finder->allFiles($this->module_path('database/migrations')); $this->assertCount(1, $files); $this->assertSame(0, $code); @@ -48,9 +42,9 @@ public function test_it_generates_correct_create_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -60,9 +54,9 @@ public function test_it_generates_correct_add_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'add_something_to_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -72,9 +66,9 @@ public function test_it_generates_correct_delete_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'delete_something_from_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -84,9 +78,9 @@ public function test_it_generates_correct_drop_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'drop_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -96,9 +90,9 @@ public function test_it_generates_correct_default_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'something_random_name', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -108,9 +102,9 @@ public function test_it_generates_foreign_key_constraints() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog', '--fields' => 'belongsTo:user:id:users']); - $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); + $file = $this->finder->get($this->module_path("database/migrations/{$fileName}")); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ModelMakeCommandTest.php b/tests/Commands/Make/ModelMakeCommandTest.php index 71d991895..b2ec25d18 100644 --- a/tests/Commands/Make/ModelMakeCommandTest.php +++ b/tests/Commands/Make/ModelMakeCommandTest.php @@ -16,17 +16,11 @@ class ModelMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -35,29 +29,29 @@ protected function tearDown(): void parent::tearDown(); } - public function test_it_generates_a_new_model_class() + public function test_generates_new_model_class() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Models/Post.php')); + $this->assertTrue(is_file($this->module_app_path('app/Models/Post.php'))); $this->assertSame(0, $code); } - public function test_it_generated_correct_file_with_content() + public function test_generates_correct_file_with_content() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Models/Post.php'); + $file = $this->finder->get($this->module_app_path('app/Models/Post.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_generates_correct_fillable_fields() + public function test_generates_correct_fillable_fields() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--fillable' => 'title,slug']); - $file = $this->finder->get($this->modulePath.'/Models/Post.php'); + $file = $this->finder->get($this->module_app_path('app/Models/Post.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -67,9 +61,9 @@ public function test_it_generates_migration_file_with_model() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--migration' => true]); - $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->module_path("database/migrations/{$migrationFile->getFilename()}")); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); @@ -79,50 +73,50 @@ public function test_it_generates_migration_file_with_model_using_shortcut_optio { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-m' => true]); - $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->module_path("database/migrations/{$migrationFile->getFilename()}")); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); } - public function test_it_generates_controller_file_with_model() + public function test_generates_controller() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--controller' => true]); - $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); + $controllers = $this->finder->allFiles($this->module_app_path('app/Http/Controllers')); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->module_app_path("Http/Controllers/{$controllerFile->getFilename()}")); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); $this->assertSame(0, $code); } - public function test_it_generates_controller_file_with_model_using_shortcut_option() + public function test_generates_controller_when_flag_is_present() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-c' => true]); - $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); + $controllers = $this->finder->allFiles($this->module_app_path('app/Http/Controllers')); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->module_app_path("Http/Controllers/{$controllerFile->getFilename()}")); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); $this->assertSame(0, $code); } - public function test_it_generates_controller_and_migration_when_both_flags_are_present() + public function test_generates_controller_and_migration_when_flags_are_present() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-c' => true, '-m' => true]); - $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); + $controllers = $this->finder->allFiles($this->module_app_path('app/Http/Controllers')); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->module_app_path("Http/Controllers/{$controllerFile->getFilename()}")); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); - $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->module_path("database/migrations/{$migrationFile->getFilename()}")); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); @@ -133,9 +127,9 @@ public function test_it_generates_correct_migration_file_name_with_multiple_word { $code = $this->artisan('module:make-model', ['model' => 'ProductDetail', 'module' => 'Blog', '-m' => true]); - $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); + $migrations = $this->finder->allFiles($this->module_path('database/migrations')); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->module_path("database/migrations/{$migrationFile->getFilename()}")); $this->assertStringContainsString('create_product_details_table', $migrationFile->getFilename()); $this->assertMatchesSnapshot($migrationContent); @@ -151,25 +145,25 @@ public function test_it_displays_error_if_model_already_exists() $this->assertSame(E_ERROR, $code); } - public function test_it_can_change_the_default_namespace() + public function test_changes_default_path() { $this->app['config']->set('modules.paths.generator.model.path', 'Models'); $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/Models/Post.php'); + $file = $this->finder->get($this->module_path('Models/Post.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_changes_default_namespace() { $this->app['config']->set('modules.paths.generator.model.namespace', 'Models'); $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Models/Post.php'); + $file = $this->finder->get($this->module_app_path('app/Models/Post.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ModuleMakeCommandTest.php b/tests/Commands/Make/ModuleMakeCommandTest.php index bb569e5ad..55462fedd 100644 --- a/tests/Commands/Make/ModuleMakeCommandTest.php +++ b/tests/Commands/Make/ModuleMakeCommandTest.php @@ -20,11 +20,6 @@ class ModuleMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - /** * @var ActivatorInterface */ @@ -38,7 +33,6 @@ class ModuleMakeCommandTest extends BaseTestCase protected function setUp(): void { parent::setUp(); - $this->modulePath = $this->getModuleBasePath(); $this->finder = $this->app['files']; $this->repository = $this->app[RepositoryInterface::class]; $this->activator = $this->app[ActivatorInterface::class]; @@ -56,7 +50,7 @@ public function test_it_generates_module() { $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertDirectoryExists($this->modulePath); + $this->assertDirectoryExists($this->module_path()); $this->assertSame(0, $code); } @@ -65,8 +59,9 @@ public function test_it_generates_module_folders() $code = $this->artisan('module:make', ['name' => ['Blog']]); foreach (config('modules.paths.generator') as $directory) { - $this->assertDirectoryExists($this->modulePath.'/'.$directory['path']); + $this->assertDirectoryExists($this->module_path($directory['path'])); } + $this->assertSame(0, $code); } @@ -75,10 +70,12 @@ public function test_it_generates_module_files() $code = $this->artisan('module:make', ['name' => ['Blog']]); foreach (config('modules.stubs.files') as $file) { - $path = base_path('modules/Blog').'/'.$file; + $path = $this->module_path($file); $this->assertTrue($this->finder->exists($path), "[$file] does not exists"); } - $path = base_path('modules/Blog').'/module.json'; + + $path = $this->module_path('module.json'); + $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -89,7 +86,7 @@ public function test_it_generates_web_route_file() $files = $this->app['modules']->config('stubs.files'); $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->modulePath.'/'.$files['routes/web']; + $path = $this->module_path($files['routes/web']); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -101,7 +98,7 @@ public function test_it_generates_web_route_file_with_multi_segment_default_name $files = $this->app['modules']->config('stubs.files'); $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->modulePath.'/'.$files['routes/web']; + $path = $this->module_path($files['routes/web']); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -112,7 +109,7 @@ public function test_it_generates_api_route_file() $files = $this->app['modules']->config('stubs.files'); $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->modulePath.'/'.$files['routes/api']; + $path = $this->module_path($files['routes/api']); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -125,7 +122,7 @@ public function test_it_generates_api_route_file_with_multi_segment_default_name $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->modulePath.'/'.$files['routes/api']; + $path = $this->module_path($files['routes/api']); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -135,7 +132,7 @@ public function test_it_generates_vite_file() { $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->modulePath.'/'.$this->app['modules']->config('stubs.files.vite'); + $path = $this->module_path($this->app['modules']->config('stubs.files.vite')); $this->assertMatchesSnapshot($this->finder->get($path)); $this->assertSame(0, $code); @@ -145,23 +142,27 @@ public function test_it_generates_module_resources() { $code = $this->artisan('module:make', ['name' => ['Blog']]); - $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $path = $this->module_app_path('app/Providers/BlogServiceProvider.php'); + $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Providers/EventServiceProvider.php'; + // EventProvider is not generated by default + $code = $this->artisan('module:make-event-provider', ['module' => 'Blog']); + $path = $this->module_app_path('app/Providers/EventServiceProvider.php'); + $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $path = $this->module_app_path('app/Http/Controllers/BlogController.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $path = $this->module_path('database/seeders/BlogDatabaseSeeder.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); @@ -172,7 +173,7 @@ public function test_it_generates_correct_composerjson_file() { $code = $this->artisan('module:make', ['name' => ['Blog']]); - $file = $this->finder->get($this->modulePath.'/composer.json'); + $file = $this->finder->get($this->module_path('composer.json')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -182,7 +183,7 @@ public function test_it_generates_module_folder_using_studly_case() { $code = $this->artisan('module:make', ['name' => ['ModuleName']]); - $this->assertTrue($this->finder->exists(base_path('modules/ModuleName'))); + $this->assertTrue($this->finder->exists($this->module_path(null, 'ModuleName'))); $this->assertSame(0, $code); } @@ -190,7 +191,7 @@ public function test_it_generates_module_namespace_using_studly_case() { $code = $this->artisan('module:make', ['name' => ['ModuleName']]); - $file = $this->finder->get($this->getModuleAppPath('ModuleName').'/Providers/ModuleNameServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/ModuleNameServiceProvider.php', 'ModuleName')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -198,15 +199,15 @@ public function test_it_generates_module_namespace_using_studly_case() public function test_it_generates_a_plain_module_with_no_resources() { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + $code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]); - $path = base_path('modules/ModuleName').'/Providers/ModuleNameServiceProvider.php'; + $path = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertFalse($this->finder->exists($path)); - $path = base_path('modules/ModuleName').'/Http/Controllers/ModuleNameController.php'; + $path = $this->module_app_path('app/Http/Controllers/BlogController.php'); $this->assertFalse($this->finder->exists($path)); - $path = base_path('modules/ModuleName').'/Database/Seeders/ModuleNameDatabaseSeeder.php'; + $path = $this->module_path('database/seeders/BlogDatabaseSeeder.php'); $this->assertFalse($this->finder->exists($path)); $this->assertSame(0, $code); @@ -214,22 +215,24 @@ public function test_it_generates_a_plain_module_with_no_resources() public function test_it_generates_a_plain_module_with_no_files() { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + $code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]); foreach (config('modules.stubs.files') as $file) { - $path = base_path('modules/ModuleName').'/'.$file; + $path = $this->module_path($file); $this->assertFalse($this->finder->exists($path), "[$file] exists"); } - $path = base_path('modules/ModuleName').'/module.json'; + + $path = $this->module_path('module.json'); + $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); $this->assertSame(0, $code); } public function test_it_generates_plain_module_with_no_service_provider_in_modulejson_file() { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + $code = $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]); - $path = base_path('modules/ModuleName').'/module.json'; + $path = $this->module_path('module.json'); $content = json_decode($this->finder->get($path)); $this->assertCount(0, $content->providers); @@ -292,10 +295,10 @@ public function test_it_can_generate_module_with_old_config_format() $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertDirectoryExists($this->modulePath.'/Assets'); - $this->assertDirectoryExists($this->modulePath.'/Emails'); - $this->assertFileDoesNotExist($this->modulePath.'/Rules'); - $this->assertFileDoesNotExist($this->modulePath.'/Policies'); + $this->assertDirectoryExists($this->module_path('Assets')); + $this->assertDirectoryExists($this->module_path('Emails')); + $this->assertFileDoesNotExist($this->module_path('Rules')); + $this->assertFileDoesNotExist($this->module_path('Policies')); $this->assertSame(0, $code); } @@ -306,8 +309,8 @@ public function test_it_can_ignore_some_folders_to_generate_with_old_format() $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertFileDoesNotExist($this->modulePath.'/Assets'); - $this->assertFileDoesNotExist($this->modulePath.'/Emails'); + $this->assertFileDoesNotExist($this->module_path('Assets')); + $this->assertFileDoesNotExist($this->module_path('Emails')); $this->assertSame(0, $code); } @@ -318,28 +321,35 @@ public function test_it_can_ignore_some_folders_to_generate_with_new_format() $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertFileDoesNotExist($this->modulePath.'/Assets'); - $this->assertFileDoesNotExist($this->modulePath.'/Emails'); + $this->assertFileDoesNotExist($this->module_path('Assets')); + $this->assertFileDoesNotExist($this->module_path('Emails')); $this->assertSame(0, $code); } public function test_it_can_ignore_resource_folders_to_generate() { - $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'Database/Seeders', 'generate' => false] - ); - $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Providers', 'generate' => false]); - $this->app['config']->set('modules.paths.generator.route-provider', ['path' => 'Providers', 'generate' => false] - ); - $this->app['config']->set( - 'modules.paths.generator.controller', - ['path' => 'Http/Controllers', 'generate' => false] - ); + $this->app['config']->set('modules.paths.generator.seeder', [ + 'path' => 'database/seeders', + 'generate' => false, + ]); + $this->app['config']->set('modules.paths.generator.provider', [ + 'path' => 'app/Providers', + 'generate' => false, + ]); + $this->app['config']->set('modules.paths.generator.route-provider', [ + 'path' => 'app/Providers', + 'generate' => false, + ]); + $this->app['config']->set('modules.paths.generator.controller', [ + 'path' => 'app/Http/Controllers', + 'generate' => false, + ]); $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertFileDoesNotExist($this->modulePath.'/Database/Seeders'); - $this->assertFileDoesNotExist($this->modulePath.'/Providers'); - $this->assertFileDoesNotExist($this->modulePath.'/Http/Controllers'); + $this->assertFileDoesNotExist($this->module_path('database/seeders')); + $this->assertFileDoesNotExist($this->module_app_path('app/Providers')); + $this->assertFileDoesNotExist($this->module_app_path('app/Http/Controllers')); $this->assertSame(0, $code); } @@ -359,17 +369,20 @@ public function test_it_generates_disabled_module_with_disabled_flag() $this->assertSame(0, $code); } - public function test_it_generes_module_with_new_provider_location() + public function test_it_generes_module_with_custom_provider_location() { $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Base/Providers', 'generate' => true]); $code = $this->artisan('module:make', ['name' => ['Blog']]); - $this->assertDirectoryExists($this->modulePath.'/Base/Providers'); - $file = $this->finder->get($this->modulePath.'/module.json'); + $this->assertDirectoryExists($this->module_path('Base/Providers')); + + $file = $this->finder->get($this->module_path('module.json')); $this->assertMatchesSnapshot($file); - $file = $this->finder->get($this->modulePath.'/composer.json'); + + $file = $this->finder->get($this->module_path('composer.json')); $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); } @@ -377,19 +390,19 @@ public function test_it_generates_web_module_with_resources() { $code = $this->artisan('module:make', ['name' => ['Blog'], '--web' => true]); - $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $path = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $path = $this->module_app_path('app/Http/Controllers/BlogController.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $path = $this->module_path('database/seeders/BlogDatabaseSeeder.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); @@ -400,19 +413,19 @@ public function test_it_generates_api_module_with_resources() { $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true]); - $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $path = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $path = $this->module_app_path('app/Http/Controllers/BlogController.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $path = $this->module_path('database/seeders/BlogDatabaseSeeder.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); @@ -423,19 +436,19 @@ public function test_it_generates_web_module_with_resources_when_adding_more_tha { $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true, '--plain' => true]); - $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $path = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $path = $this->module_app_path('app/Http/Controllers/BlogController.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $path = $this->module_path('database/seeders/BlogDatabaseSeeder.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); - $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue($this->finder->exists($path)); $this->assertMatchesSnapshot($this->finder->get($path)); @@ -449,11 +462,11 @@ public function test_it_generate_module_when_provider_is_enable_and_route_provid $this->artisan('module:make', ['name' => ['Blog']]); - $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $providerPath = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue($this->finder->exists($providerPath)); $this->assertMatchesSnapshot($this->finder->get($providerPath)); - $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $RouteProviderPath = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue($this->finder->exists($RouteProviderPath)); $this->assertMatchesSnapshot($this->finder->get($RouteProviderPath)); @@ -470,11 +483,11 @@ public function test_it_generate_module_when_provider_is_enable_and_route_provid $this->artisan('module:make', ['name' => ['Blog']]); - $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $providerPath = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue($this->finder->exists($providerPath)); $this->assertMatchesSnapshot($this->finder->get($providerPath)); - $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $RouteProviderPath = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue(! $this->finder->exists($RouteProviderPath)); $content = $this->finder->get($providerPath); @@ -489,13 +502,13 @@ public function test_it_generate_module_when_provider_is_disable_and_route_provi $this->artisan('module:make', ['name' => ['Blog']]); - $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $providerPath = $this->module_app_path('app/Providers/BlogServiceProvider.php'); $this->assertTrue(! $this->finder->exists($providerPath)); - $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $RouteProviderPath = $this->module_app_path('app/Providers/RouteServiceProvider.php'); $this->assertTrue(! $this->finder->exists($RouteProviderPath)); - $content = $this->finder->get($this->getModuleBasePath().'/module.json'); + $content = $this->finder->get($this->module_path('module.json')); $this->assertStringNotContainsString('Modules\Blog\Providers\BlogServiceProvider', $content); } @@ -512,7 +525,7 @@ public function test_it_can_set_author_details() ] ); - $content = $this->finder->get($this->getModuleBasePath().'/composer.json'); + $content = $this->finder->get($this->module_path('composer.json')); $this->assertStringContainsString('Joe Blogs', $content); $this->assertStringContainsString('user@domain.com', $content); diff --git a/tests/Commands/Make/NotificationMakeCommandTest.php b/tests/Commands/Make/NotificationMakeCommandTest.php index 6c870ebb0..63510fc17 100644 --- a/tests/Commands/Make/NotificationMakeCommandTest.php +++ b/tests/Commands/Make/NotificationMakeCommandTest.php @@ -15,17 +15,11 @@ class NotificationMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_the_notification_class() { $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Notifications/WelcomeNotification.php')); + $this->assertTrue(is_file($this->module_app_path('app/Notifications/WelcomeNotification.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Notifications/WelcomeNotification.php'); + $file = $this->finder->get($this->module_app_path('app/Notifications/WelcomeNotification.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.notifications.path', 'SuperNotifications'); $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperNotifications/WelcomeNotification.php'); + $file = $this->finder->get($this->module_path('SuperNotifications/WelcomeNotification.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.notifications.namespace', 'SuperNotifications'); $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Notifications/WelcomeNotification.php'); + $file = $this->finder->get($this->module_app_path('Notifications/WelcomeNotification.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ObserverMakeCommandTest.php b/tests/Commands/Make/ObserverMakeCommandTest.php index 93e4e1ad0..4c105c083 100644 --- a/tests/Commands/Make/ObserverMakeCommandTest.php +++ b/tests/Commands/Make/ObserverMakeCommandTest.php @@ -15,17 +15,11 @@ class ObserverMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_makes_observer() { $code = $this->artisan('module:make-observer', ['name' => 'Post', 'module' => 'Blog']); - $observerFile = $this->modulePath.'/Observers/PostObserver.php'; + $observerFile = $this->module_app_path('app/Observers/PostObserver.php'); $this->assertTrue(is_file($observerFile), 'Observer file was not created.'); $this->assertMatchesSnapshot($this->finder->get($observerFile)); diff --git a/tests/Commands/Make/PolicyMakeCommandTest.php b/tests/Commands/Make/PolicyMakeCommandTest.php index a68e8b48e..f2587fd73 100644 --- a/tests/Commands/Make/PolicyMakeCommandTest.php +++ b/tests/Commands/Make/PolicyMakeCommandTest.php @@ -15,17 +15,11 @@ class PolicyMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,32 +32,32 @@ public function test_it_makes_policy() { $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $policyFile = $this->modulePath.'/Policies/PostPolicy.php'; + $policyFile = $this->module_app_path('app/Policies/PostPolicy.php'); $this->assertTrue(is_file($policyFile), 'Policy file was not created.'); $this->assertMatchesSnapshot($this->finder->get($policyFile)); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.policies.path', 'SuperPolicies'); $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperPolicies/PostPolicy.php'); + $file = $this->finder->get($this->module_path('SuperPolicies/PostPolicy.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.policies.namespace', 'SuperPolicies'); $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Policies/PostPolicy.php'); + $file = $this->finder->get($this->module_app_path('Policies/PostPolicy.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ProviderMakeCommandTest.php b/tests/Commands/Make/ProviderMakeCommandTest.php index 905e21fb9..9e9309ddf 100644 --- a/tests/Commands/Make/ProviderMakeCommandTest.php +++ b/tests/Commands/Make/ProviderMakeCommandTest.php @@ -15,16 +15,10 @@ class ProviderMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; - $this->modulePath = $this->getModuleAppPath(); $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]); } @@ -38,7 +32,7 @@ public function test_it_generates_a_service_provider() { $code = $this->artisan('module:make-provider', ['name' => 'MyBlogServiceProvider', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Providers/MyBlogServiceProvider.php')); + $this->assertTrue(is_file($this->module_app_path('app/Providers/MyBlogServiceProvider.php'))); $this->assertSame(0, $code); } @@ -46,7 +40,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-provider', ['name' => 'MyBlogServiceProvider', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Providers/MyBlogServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/MyBlogServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -56,7 +50,7 @@ public function test_it_generates_a_master_service_provider_with_resource_loadin { $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/BlogServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -67,31 +61,31 @@ public function test_it_can_have_custom_migration_resources_location_paths() $this->app['config']->set('modules.paths.generator.migration', 'migrations'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/BlogServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.provider.path', 'SuperProviders'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->getModuleBasePath().'/SuperProviders/BlogServiceProvider.php'); + $file = $this->finder->get($this->module_path('SuperProviders/BlogServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.provider.namespace', 'SuperProviders'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('app/Providers/BlogServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/RepositoryMakeCommandTest.php b/tests/Commands/Make/RepositoryMakeCommandTest.php index bd78769e1..7b1fe0ee3 100644 --- a/tests/Commands/Make/RepositoryMakeCommandTest.php +++ b/tests/Commands/Make/RepositoryMakeCommandTest.php @@ -15,18 +15,11 @@ class RepositoryMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_repository_class() { $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertTrue(is_file($this->module_app_path('Repositories/MyRepository.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_repository_class_can_override_with_force $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertTrue(is_file($this->module_app_path('Repositories/MyRepository.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generates_a_new_repository_class_can_use_invoke_option() { $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog', '--invokable' => true]); - $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertTrue(is_file($this->module_app_path('Repositories/MyRepository.php'))); $this->assertSame(0, $code); } @@ -64,7 +57,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Repositories/MyRepository.php'); + $file = $this->finder->get($this->module_app_path('Repositories/MyRepository.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -74,7 +67,7 @@ public function test_it_can_generate_a_repository_in_sub_namespace_in_correct_fo { $code = $this->artisan('module:make-repository', ['name' => 'Api\\MyRepository', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Repositories/Api/MyRepository.php')); + $this->assertTrue(is_file($this->module_app_path('Repositories/Api/MyRepository.php'))); $this->assertSame(0, $code); } @@ -82,7 +75,7 @@ public function test_it_can_generate_a_repository_in_sub_namespace_with_correct_ { $code = $this->artisan('module:make-repository', ['name' => 'Api\\MyRepository', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Repositories/Api/MyRepository.php'); + $file = $this->finder->get($this->module_app_path('Repositories/Api/MyRepository.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/RequestMakeCommandTest.php b/tests/Commands/Make/RequestMakeCommandTest.php index 2ecc4510f..36bfedc50 100644 --- a/tests/Commands/Make/RequestMakeCommandTest.php +++ b/tests/Commands/Make/RequestMakeCommandTest.php @@ -15,17 +15,11 @@ class RequestMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_generates_a_new_form_request_class() { $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php')); + $this->assertTrue(is_file($this->module_app_path('Http/Requests/CreateBlogPostRequest.php'))); $this->assertSame(0, $code); } @@ -46,31 +40,31 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->module_app_path('Http/Requests/CreateBlogPostRequest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.request.path', 'SuperRequests'); $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperRequests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->module_path('SuperRequests/CreateBlogPostRequest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.request.namespace', 'SuperRequests'); $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->module_app_path('Http/Requests/CreateBlogPostRequest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ResourceMakeCommandTest.php b/tests/Commands/Make/ResourceMakeCommandTest.php index 2cd73ed3f..545baa30c 100644 --- a/tests/Commands/Make/ResourceMakeCommandTest.php +++ b/tests/Commands/Make/ResourceMakeCommandTest.php @@ -15,17 +15,11 @@ class ResourceMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -36,17 +30,17 @@ protected function tearDown(): void public function test_it_generates_a_new_resource_class() { - $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog']); + $code = $this->artisan('module:make-resource', ['name' => 'PostsResource', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Transformers/PostsTransformer.php')); + $this->assertTrue(is_file($this->module_app_path('Resources/PostsResource.php'))); $this->assertSame(0, $code); } public function test_it_generated_correct_file_with_content() { - $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog']); + $code = $this->artisan('module:make-resource', ['name' => 'PostsResource', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->module_app_path('Resources/PostsResource.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -54,33 +48,33 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_collection_resource_class() { - $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); + $code = $this->artisan('module:make-resource', ['name' => 'PostsResource', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->module_app_path('Resources/PostsResource.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.resource.path', 'app/Http/Resources'); - $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); + $code = $this->artisan('module:make-resource', ['name' => 'PostsResource', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath.'/Http/Resources/PostsTransformer.php'); + $file = $this->finder->get($this->module_app_path('Http/Resources/PostsResource.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.resource.namespace', 'Http\\Resources'); - $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); + $code = $this->artisan('module:make-resource', ['name' => 'PostsResource', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->module_app_path('Resources/PostsResource.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/RouteProviderMakeCommandTest.php b/tests/Commands/Make/RouteProviderMakeCommandTest.php index 868d2bf34..396b18263 100644 --- a/tests/Commands/Make/RouteProviderMakeCommandTest.php +++ b/tests/Commands/Make/RouteProviderMakeCommandTest.php @@ -15,17 +15,11 @@ class RouteProviderMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -36,7 +30,7 @@ protected function tearDown(): void public function test_it_generates_a_new_service_provider_class() { - $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('Providers/RouteServiceProvider.php'); $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -46,7 +40,7 @@ public function test_it_generates_a_new_service_provider_class() public function test_it_generated_correct_file_with_content() { - $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('Providers/RouteServiceProvider.php'); $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -56,23 +50,23 @@ public function test_it_generated_correct_file_with_content() $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.provider.path', 'SuperProviders'); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperProviders/RouteServiceProvider.php'); + $file = $this->finder->get($this->module_path('SuperProviders/RouteServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.provider.namespace', 'SuperProviders'); - $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; + $path = $this->module_app_path('Providers/RouteServiceProvider.php'); $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -89,7 +83,7 @@ public function test_it_can_overwrite_route_file_names() $code = $this->artisan('module:route-provider', ['module' => 'Blog', '--force' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('Providers/RouteServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -101,7 +95,7 @@ public function test_it_can_overwrite_file(): void $this->app['config']->set('modules.stubs.files.routes/web', 'SuperRoutes/web.php'); $code = $this->artisan('module:route-provider', ['module' => 'Blog', '--force' => true]); - $file = $this->finder->get($this->modulePath.'/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->module_app_path('Providers/RouteServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -113,7 +107,7 @@ public function test_it_can_change_the_custom_controller_namespace(): void $this->app['config']->set('modules.paths.generator.provider.path', 'Base/Providers'); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/Base/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->module_path('Base/Providers/RouteServiceProvider.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/RuleMakeCommandTest.php b/tests/Commands/Make/RuleMakeCommandTest.php index 60de67225..fb2f07499 100644 --- a/tests/Commands/Make/RuleMakeCommandTest.php +++ b/tests/Commands/Make/RuleMakeCommandTest.php @@ -15,17 +15,11 @@ class RuleMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -38,7 +32,7 @@ public function test_it_makes_rule() { $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $ruleFile = $this->modulePath.'/Rules/UniqueRule.php'; + $ruleFile = $this->module_app_path('Rules/UniqueRule.php'); $this->assertTrue(is_file($ruleFile), 'Rule file was not created.'); $this->assertMatchesSnapshot($this->finder->get($ruleFile)); @@ -49,32 +43,32 @@ public function test_it_makes_implicit_rule() { $code = $this->artisan('module:make-rule', ['name' => 'ImplicitUniqueRule', 'module' => 'Blog', '--implicit' => true]); - $ruleFile = $this->modulePath.'/Rules/ImplicitUniqueRule.php'; + $ruleFile = $this->module_app_path('Rules/ImplicitUniqueRule.php'); $this->assertTrue(is_file($ruleFile), 'Rule file was not created.'); $this->assertMatchesSnapshot($this->finder->get($ruleFile)); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.rules.path', 'SuperRules'); $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperRules/UniqueRule.php'); + $file = $this->finder->get($this->module_path('SuperRules/UniqueRule.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.rules.namespace', 'SuperRules'); $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Rules/UniqueRule.php'); + $file = $this->finder->get($this->module_app_path('Rules/UniqueRule.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ScopeMakeCommandTest.php b/tests/Commands/Make/ScopeMakeCommandTest.php index 5a18f0a30..1577d230a 100644 --- a/tests/Commands/Make/ScopeMakeCommandTest.php +++ b/tests/Commands/Make/ScopeMakeCommandTest.php @@ -15,18 +15,11 @@ class ScopeMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_scope_class() { $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/MyScope.php')); + $this->assertTrue(is_file($this->module_app_path('Models/Scopes/MyScope.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_scope_class_can_override_with_force_opti $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/MyScope.php')); + $this->assertTrue(is_file($this->module_app_path('Models/Scopes/MyScope.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Models/Scopes/MyScope.php'); + $file = $this->finder->get($this->module_app_path('Models/Scopes/MyScope.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -64,17 +57,17 @@ public function test_it_generated_correct_file_with_content() public function test_it_can_generate_a_scope_in_sub_namespace_in_correct_folder() { - $code = $this->artisan('module:make-scope', ['name' => 'Api\\MyScope', 'module' => 'Blog']); + $code = $this->artisan('module:make-scope', ['name' => 'Api/MyScope', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/Api/MyScope.php')); + $this->assertTrue(is_file($this->module_app_path('Models/Scopes/Api/MyScope.php'))); $this->assertSame(0, $code); } public function test_it_can_generate_a_scope_in_sub_namespace_with_correct_generated_file() { - $code = $this->artisan('module:make-scope', ['name' => 'Api\\MyScope', 'module' => 'Blog']); + $code = $this->artisan('module:make-scope', ['name' => 'Api/MyScope', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Models/Scopes/Api/MyScope.php'); + $file = $this->finder->get($this->module_app_path('Models/Scopes/Api/MyScope.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ServiceMakeCommandTest.php b/tests/Commands/Make/ServiceMakeCommandTest.php index 18fdd7454..0a9051cf2 100644 --- a/tests/Commands/Make/ServiceMakeCommandTest.php +++ b/tests/Commands/Make/ServiceMakeCommandTest.php @@ -15,18 +15,11 @@ class ServiceMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_service_class() { $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertTrue(is_file($this->module_app_path('Services/MyService.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_service_class_can_override_with_force_op $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertTrue(is_file($this->module_app_path('Services/MyService.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generates_a_new_service_class_can_use_invoke_option() { $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog', '--invokable' => true]); - $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertTrue(is_file($this->module_app_path('Services/MyService.php'))); $this->assertSame(0, $code); } @@ -64,7 +57,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Services/MyService.php'); + $file = $this->finder->get($this->module_app_path('Services/MyService.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -74,7 +67,7 @@ public function test_it_can_generate_a_service_in_sub_namespace_in_correct_folde { $code = $this->artisan('module:make-service', ['name' => 'Api\\MyService', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Services/Api/MyService.php')); + $this->assertTrue(is_file($this->module_app_path('Services/Api/MyService.php'))); $this->assertSame(0, $code); } @@ -82,7 +75,7 @@ public function test_it_can_generate_a_service_in_sub_namespace_with_correct_gen { $code = $this->artisan('module:make-service', ['name' => 'Api\\MyService', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Services/Api/MyService.php'); + $file = $this->finder->get($this->module_app_path('Services/Api/MyService.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/TestMakeCommandTest.php b/tests/Commands/Make/TestMakeCommandTest.php index e17aba453..c0031fb2b 100644 --- a/tests/Commands/Make/TestMakeCommandTest.php +++ b/tests/Commands/Make/TestMakeCommandTest.php @@ -16,11 +16,6 @@ class TestMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - /** * @var ActivatorInterface */ @@ -31,7 +26,6 @@ protected function setUp(): void parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleBasePath(); $this->activator = $this->app[ActivatorInterface::class]; } @@ -46,7 +40,7 @@ public function test_it_generates_a_new_unit_test_class() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php')); + $this->assertTrue(is_file($this->module_path('tests/Unit/EloquentPostRepositoryTest.php'))); $this->assertSame(0, $code); } @@ -54,7 +48,7 @@ public function test_it_generates_a_new_feature_test_class() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $this->assertTrue(is_file($this->modulePath.'/tests/Feature/EloquentPostRepositoryTest.php')); + $this->assertTrue(is_file($this->module_path('tests/Feature/EloquentPostRepositoryTest.php'))); $this->assertSame(0, $code); } @@ -62,7 +56,7 @@ public function test_it_generated_correct_unit_file_with_content() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('tests/Unit/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -72,7 +66,7 @@ public function test_it_generated_correct_feature_file_with_content() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->modulePath.'/tests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('tests/Feature/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -84,7 +78,7 @@ public function test_it_can_change_the_default_unit_namespace() $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/SuperTests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('SuperTests/Unit/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -96,7 +90,7 @@ public function test_it_can_change_the_default_unit_namespace_specific() $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('tests/Unit/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -108,7 +102,7 @@ public function test_it_can_change_the_default_feature_namespace() $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->modulePath.'/SuperTests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('SuperTests/Feature/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -120,7 +114,7 @@ public function test_it_can_change_the_default_feature_namespace_specific() $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->getModuleBasePath().'/tests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->module_path('tests/Feature/EloquentPostRepositoryTest.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/TraitMakeCommandTest.php b/tests/Commands/Make/TraitMakeCommandTest.php index c0f141083..f1eae5e2a 100644 --- a/tests/Commands/Make/TraitMakeCommandTest.php +++ b/tests/Commands/Make/TraitMakeCommandTest.php @@ -15,18 +15,11 @@ class TraitMakeCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); - } protected function tearDown(): void @@ -39,7 +32,7 @@ public function test_it_generates_a_new_trait_class() { $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Traits/MyTrait.php')); + $this->assertTrue(is_file($this->module_app_path('Traits/MyTrait.php'))); $this->assertSame(0, $code); } @@ -48,7 +41,7 @@ public function test_it_generates_a_new_trait_class_can_override_with_force_opti $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog', '--force' => true]); - $this->assertTrue(is_file($this->modulePath.'/Traits/MyTrait.php')); + $this->assertTrue(is_file($this->module_app_path('Traits/MyTrait.php'))); $this->assertSame(0, $code); } @@ -56,7 +49,7 @@ public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Traits/MyTrait.php'); + $file = $this->finder->get($this->module_app_path('Traits/MyTrait.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); @@ -66,7 +59,7 @@ public function test_it_can_generate_a_trait_in_sub_namespace_in_correct_folder( { $code = $this->artisan('module:make-trait', ['name' => 'Api\\MyTrait', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath.'/Traits/Api/MyTrait.php')); + $this->assertTrue(is_file($this->module_app_path('Traits/Api/MyTrait.php'))); $this->assertSame(0, $code); } @@ -74,7 +67,7 @@ public function test_it_can_generate_a_trait_in_sub_namespace_with_correct_gener { $code = $this->artisan('module:make-trait', ['name' => 'Api\\MyTrait', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath.'/Traits/Api/MyTrait.php'); + $file = $this->finder->get($this->module_app_path('Traits/Api/MyTrait.php')); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ViewMakeCommandTest.php b/tests/Commands/Make/ViewMakeCommandTest.php index 4a254bcf6..38281404e 100644 --- a/tests/Commands/Make/ViewMakeCommandTest.php +++ b/tests/Commands/Make/ViewMakeCommandTest.php @@ -16,14 +16,11 @@ class ViewMakeCommandTest extends BaseTestCase */ private mixed $finder; - private string $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void @@ -35,25 +32,25 @@ protected function tearDown(): void public function test_it_generates_the_view() { $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); - $this->assertTrue(is_file($this->getModuleBasePath().'/resources/views/blog.blade.php')); + $this->assertTrue(is_file($this->module_path('resources/views/blog.blade.php'))); $this->assertSame(0, $code); } public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/resources/views/blog.blade.php'); + $file = $this->finder->get($this->module_path('resources/views/blog.blade.php')); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); } - public function test_it_can_change_the_default_namespace() + public function test_it_can_change_the_default_path() { $this->app['config']->set('modules.paths.generator.views.path', 'resources/views'); $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->getModuleBasePath().'/resources/views/blog.blade.php'); + $file = $this->finder->get($this->module_path('resources/views/blog.blade.php')); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_generates_action_in_sub_folder__1.txt b/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_generates_action_in_sub_folder__1.txt new file mode 100644 index 000000000..63efa11f8 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_generates_action_in_sub_folder__1.txt @@ -0,0 +1,8 @@ +view('view.name'); + } +} diff --git a/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 56c9a9606..d21291817 100644 --- a/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -1,6 +1,6 @@ id(); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('posts'); + } +}; diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt new file mode 100644 index 000000000..e3d176d1a --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt @@ -0,0 +1,56 @@ +app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); // $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt index 3ccddc802..9e71a8100 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt index 99e2a52a4..a9aea33d3 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt index bc3afb929..b6df05ff2 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt @@ -1,6 +1,6 @@ prefix('v1')->group(function () { Route::apiResource('blogs', BlogController::class)->names('blog'); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt index b591bbb36..661b647dc 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt @@ -1,7 +1,7 @@ prefix('v1')->group(function () { Route::apiResource('blogs', BlogController::class)->names('blog'); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt index 746cae739..b1d1c7ac4 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt @@ -17,7 +17,7 @@ }, "autoload": { "psr-4": { - "Modules\\Blog\\": "app/", + "Modules\\Blog\\App\\": "app/", "Modules\\Blog\\Database\\Factories\\": "database/factories/", "Modules\\Blog\\Database\\Seeders\\": "database/seeders/" } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt index 92e3b4504..ef5c06f5f 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt @@ -5,7 +5,7 @@ "keywords": [], "priority": 0, "providers": [ - "Modules\\Blog\\Providers\\BlogServiceProvider" + "Modules\\Blog\\App\\Providers\\BlogServiceProvider" ], "files": [] } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt index b0ee36863..1cc6b2efb 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt index 3ccddc802..9e71a8100 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt index c95fe85b9..d86b03738 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt index 7badeb0e4..f2e8d5ab6 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt @@ -1,6 +1,6 @@ app->register(EventServiceProvider::class); + // $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt index 7badeb0e4..f2e8d5ab6 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt @@ -1,6 +1,6 @@ group(function () { Route::resource('blogs', BlogController::class)->names('blog'); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt index 65f996120..a1c995006 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt @@ -1,7 +1,7 @@ group(function () { Route::resource('blogs', BlogController::class)->names('blog'); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__1.txt new file mode 100644 index 000000000..c59f26953 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__1.txt @@ -0,0 +1,11 @@ +{ + "name": "Blog", + "alias": "blog", + "description": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Blog\\Base\\Providers\\BlogServiceProvider" + ], + "files": [] +} diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt new file mode 100644 index 000000000..b1d1c7ac4 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt @@ -0,0 +1,30 @@ +{ + "name": "nwidart/blog", + "description": "", + "authors": [ + { + "name": "Nicolas Widart", + "email": "n.widart@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Blog\\App\\": "app/", + "Modules\\Blog\\Database\\Factories\\": "database/factories/", + "Modules\\Blog\\Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Modules\\Blog\\Tests\\": "tests/" + } + } +} diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt index 746cae739..b1d1c7ac4 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt @@ -17,7 +17,7 @@ }, "autoload": { "psr-4": { - "Modules\\Blog\\": "app/", + "Modules\\Blog\\App\\": "app/", "Modules\\Blog\\Database\\Factories\\": "database/factories/", "Modules\\Blog\\Database\\Seeders\\": "database/seeders/" } diff --git a/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_path__1.txt b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_path__1.txt new file mode 100644 index 000000000..d32033810 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_path__1.txt @@ -0,0 +1,45 @@ +line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + */ + public function toArray($notifiable): array + { + return []; + } +} diff --git a/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 34c69d767..9a19b805e 100644 --- a/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -1,6 +1,6 @@ registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->nameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->nameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $configPath = module_path($this->name, config('modules.paths.generator.config.path')); + + if (is_dir($configPath)) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath)); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + $config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname()); + $config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config); + $segments = explode('.', $this->nameLower.'.'.$config_key); + + // Remove duplicated adjacent segments + $normalized = []; + foreach ($segments as $segment) { + if (end($normalized) !== $segment) { + $normalized[] = $segment; + } + } + + $key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized); + + $this->publishes([$file->getPathname() => config_path($config)], 'config'); + $this->merge_config_from($file->getPathname(), $key); + } + } + } + } + + /** + * Merge config from the given path recursively. + */ + protected function merge_config_from(string $path, string $key): void + { + $existing = config($key, []); + $module_config = require $path; + + config([$key => array_replace_recursive($existing, $module_config)]); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->nameLower); + $sourcePath = module_path($this->name, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); + + Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + } + + /** + * Get the services provided by the provider. + */ + public function provides(): array + { + return []; + } + + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->nameLower)) { + $paths[] = $path.'/modules/'.$this->nameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt index fcc2b83f0..4a5b71ae9 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt @@ -1,6 +1,6 @@ mapApiRoutes(); + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path($this->name, '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php')); + } +} diff --git a/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt index 24e3ae646..02212dca4 100644 --- a/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt @@ -1,6 +1,6 @@ createModule(); - $this->modulePath = $this->getModuleBasePath(); $this->finder = $this->app['files']; - $this->finder->put($this->modulePath.'/resources/assets/script.js', 'assetfile'); + $this->finder->put($this->module_path('resources/assets/script.js'), 'assetfile'); } protected function tearDown(): void diff --git a/tests/Commands/Publish/PublishMigrationCommandTest.php b/tests/Commands/Publish/PublishMigrationCommandTest.php index 66a912c39..74fa909c4 100644 --- a/tests/Commands/Publish/PublishMigrationCommandTest.php +++ b/tests/Commands/Publish/PublishMigrationCommandTest.php @@ -12,17 +12,11 @@ class PublishMigrationCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); } diff --git a/tests/Commands/Publish/PublishTranslationCommandTest.php b/tests/Commands/Publish/PublishTranslationCommandTest.php index fe343ee41..cfe8dcc29 100644 --- a/tests/Commands/Publish/PublishTranslationCommandTest.php +++ b/tests/Commands/Publish/PublishTranslationCommandTest.php @@ -12,17 +12,11 @@ class PublishTranslationCommandTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index 47d497bad..4d82d8650 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -12,17 +12,11 @@ class HelpersTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void diff --git a/tests/LaravelFileRepositoryTest.php b/tests/LaravelFileRepositoryTest.php index f7092c5b7..493ddec22 100644 --- a/tests/LaravelFileRepositoryTest.php +++ b/tests/LaravelFileRepositoryTest.php @@ -200,7 +200,7 @@ public function test_it_can_delete_a_module() $this->repository->delete('Blog'); - $this->assertFalse(is_dir(base_path('modules/Blog'))); + $this->assertFalse(is_dir($this->module_path())); } public function test_it_can_register_macros() diff --git a/tests/ModuleHelperTest.php b/tests/ModuleHelperTest.php index 51cc0841f..33d9448fa 100644 --- a/tests/ModuleHelperTest.php +++ b/tests/ModuleHelperTest.php @@ -14,17 +14,11 @@ class ModuleHelperTest extends BaseTestCase */ private $finder; - /** - * @var string - */ - private $modulePath; - protected function setUp(): void { parent::setUp(); $this->finder = $this->app['files']; $this->createModule(); - $this->modulePath = $this->getModuleAppPath(); } protected function tearDown(): void diff --git a/tests/Support/Config/GenerateConfigReaderTest.php b/tests/Support/Config/GenerateConfigReaderTest.php index 101ccc3e6..d8161efab 100644 --- a/tests/Support/Config/GenerateConfigReaderTest.php +++ b/tests/Support/Config/GenerateConfigReaderTest.php @@ -13,29 +13,29 @@ public function test_it_can_read_a_configuration_value_with_new_format() $seedConfig = GenerateConfigReader::read('seeder'); $this->assertInstanceOf(GeneratorPath::class, $seedConfig); - $this->assertEquals('database/seeders', $seedConfig->getPath()); + $this->assertEquals('database/seeders', $seedConfig->path()); $this->assertTrue($seedConfig->generate()); } public function test_it_can_read_a_configuration_value_with_new_format_set_to_false() { - $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'Database/Seeders', 'generate' => false]); + $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'database/seeders', 'generate' => false]); $seedConfig = GenerateConfigReader::read('seeder'); $this->assertInstanceOf(GeneratorPath::class, $seedConfig); - $this->assertEquals('Database/Seeders', $seedConfig->getPath()); + $this->assertEquals('database/seeders', $seedConfig->path()); $this->assertFalse($seedConfig->generate()); } public function test_it_can_read_a_configuration_value_with_old_format() { - $this->app['config']->set('modules.paths.generator.seeder', 'Database/Seeders'); + $this->app['config']->set('modules.paths.generator.seeder', 'database/seeders'); $seedConfig = GenerateConfigReader::read('seeder'); $this->assertInstanceOf(GeneratorPath::class, $seedConfig); - $this->assertEquals('Database/Seeders', $seedConfig->getPath()); + $this->assertEquals('database/seeders', $seedConfig->path()); $this->assertTrue($seedConfig->generate()); } @@ -46,7 +46,7 @@ public function test_it_can_read_a_configuration_value_with_old_format_set_to_fa $seedConfig = GenerateConfigReader::read('seeder'); $this->assertInstanceOf(GeneratorPath::class, $seedConfig); - $this->assertFalse($seedConfig->getPath()); + $this->assertEmpty($seedConfig->path()); $this->assertFalse($seedConfig->generate()); } @@ -56,7 +56,7 @@ public function test_it_can_guess_namespace_from_path() $config = GenerateConfigReader::read('provider'); - $this->assertEquals('Base/Providers', $config->getPath()); - $this->assertEquals('Base\Providers', $config->getNamespace()); + $this->assertEquals('Base/Providers', $config->path()); + $this->assertEquals('Base\Providers', $config->namespace()); } } diff --git a/tests/Traits/PathNamespaceTest.php b/tests/Traits/PathNamespaceTest.php index a9eb0ea4a..bc7122521 100644 --- a/tests/Traits/PathNamespaceTest.php +++ b/tests/Traits/PathNamespaceTest.php @@ -9,43 +9,121 @@ class PathNamespaceTest extends BaseTestCase protected function setUp(): void { parent::setUp(); + } + + public function test_converts_to_studly_path() + { + $this->assertSame('Modules/User/App/Models/User', $this->studly_path('Modules/User/app/Models/User')); + } + + public function test_converts_namespace_with_studly_path() + { + $this->assertSame('Modules\\User\\App\\Models\\User', $this->studly_path('Modules\\User\\app\\Models\\User', '\\')); + } + + public function test_converts_to_studly_namespace() + { + $this->assertSame('Modules\User\App\Models\User', $this->studly_namespace('Modules/User/app/Models/User')); + } + + public function test_converts_custom_namespace_with_studly_namespace() + { + $this->assertSame('Modules\\\\User\\\\App\\\\Models\\\\User', $this->studly_namespace('Modules\\\\User\\\\app\\\\Models\\\\User', '\\\\')); + } + + public function test_generates_path_namespace() + { + $this->assertSame('User\App\Models\User', $this->path_namespace('User/app/Models/User')); + } + + public function test_generates_module_namespace() + { + $this->assertSame('Modules\User', $this->module_namespace('user')); + $this->assertSame('Modules\User\App\Models\User', $this->module_namespace('user', 'app/Models/User')); + } + + public function test_cleans_path() + { + $this->assertSame('blog/services', $this->clean_path('blog//services')); + $this->assertSame('', $this->clean_path('//')); + $this->assertSame('', $this->clean_path('')); + } + + public function test_cleans_namespace_with_clean_path() + { + $this->assertSame('Modules\User\App\Models\User', $this->clean_path('Modules\\\\User/App\\Models\User\\//', '\\')); + $this->assertSame('', $this->clean_path('\\')); + } + + public function test_identifies_app_path() + { + $this->assertTrue($this->is_app_path('app/Models/User')); + $this->assertFalse($this->is_app_path('src/Models/User')); + } - $this->class = new UsePathNamespaceTrait; + public function test_recognizes_custom_app_path() + { + config(['modules.paths.app' => 'src/']); + $this->assertTrue($this->is_app_path('app/Models/User')); + $this->assertTrue($this->is_app_path('src/Models/User')); } - public function test_studly_path() + public function test_generates_app_path() { - $this->assertSame('Blog/Services', $this->class->studly_path('/blog/services')); + $app_path = $this->app_path(); + + $this->assertSame('app/Models/User', $this->app_path('Models/User')); + $this->assertSame($app_path, $this->app_path(null)); } - public function test_studly_namespace() + public function test_generates_custom_app_path() { - $this->assertSame('/blog/services', $this->class->studly_namespace('/blog/services')); + config(['modules.paths.app' => 'src/']); + + $this->assertSame('src/Models/User', $this->app_path('Models/User')); } - public function test_path_namespace() + public function test_generates_root_app_path() { - $this->assertSame('Blog\Services', $this->class->path_namespace('/blog/services')); + config(['modules.paths.app' => '/']); + + $this->assertSame('', $this->app_path()); } - public function test_module_namespace() + public function test_removes_duplicate_app_path() { - $this->assertSame('Modules\Blog/services', $this->class->module_namespace('blog/services')); + $this->assertSame('app/Models/User', $this->app_path('app/Models/User')); + $this->assertSame('app/Models/User', $this->app_path('app/app/Models/User')); + + config(['modules.paths.app' => 'src/']); + $this->assertSame('src/Models/User', $this->app_path('src/Models/User')); + $this->assertSame('src/Models/User', $this->app_path('src/src/Models/User')); + + config(['modules.paths.app' => '/']); + $this->assertSame('Models/User', $this->app_path('app/Models/User')); + $this->assertSame('Models/User', $this->app_path('app/app/Models/User')); } - public function test_clean_path() + public function test_removes_duplicate_app_path_regardless_of_case() { - $this->assertSame('blog/services', $this->class->clean_path('blog/services')); - $this->assertSame('', $this->class->clean_path('')); + $this->assertSame('app/Models/User', $this->app_path('app/Models/User')); + $this->assertSame('app/Models/User', $this->app_path('App/App/Models/User')); + $this->assertSame('app/Models/User', $this->app_path('APP/APP/Models/User')); } - public function test_app_path() + public function test_generates_app_path_namespace() { - $configPath = config('modules.paths.app_folder'); - $configPath = rtrim($configPath, '/'); + $this->assertSame('App', $this->app_path_namespace()); + $this->assertSame('App', $this->app_path_namespace(null)); + $this->assertSame('App\Models\User', $this->app_path_namespace('app/Models/User')); + $this->assertSame('App\Models\User', $this->app_path_namespace('Models/User')); + } - $this->assertSame($configPath, $this->class->app_path()); - $this->assertSame($configPath, $this->class->app_path(null)); - $this->assertSame('app/blog/services', $this->class->app_path('blog/services')); + public function test_generates_modules_app_path_namespace() + { + $this->assertSame('Modules\User\App', $this->modules_app_path_namespace('user')); + $this->assertSame('Modules\User\App', $this->modules_app_path_namespace('user', null)); + $this->assertSame('Modules\User\App\Models\User', $this->modules_app_path_namespace('user', 'app/Models/User')); + $this->assertSame('Modules\User\App\Models\User', $this->modules_app_path_namespace('user', 'Models/User')); } } From fac9960125c7518a81f288ed17584a3056ca11e9 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Thu, 22 May 2025 02:51:36 +0100 Subject: [PATCH 15/21] refactor: add PathNamespace trait to Module class for improved path handling --- src/Module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Module.php b/src/Module.php index 0124463e6..52044fe38 100644 --- a/src/Module.php +++ b/src/Module.php @@ -11,10 +11,11 @@ use Illuminate\Support\Traits\Macroable; use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\ActivatorInterface; +use Nwidart\Modules\Traits\PathNamespace; abstract class Module { - use Macroable; + use Macroable, PathNamespace; /** * The laravel|lumen application instance. From 73c6e6cd532ea394b04c035cb0be2639b958fde0 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Wed, 25 Jun 2025 04:56:23 +0100 Subject: [PATCH 16/21] fix: correct wording in app path configuration comments for clarity --- config/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.php b/config/config.php index 33cffa6c4..5946486cf 100644 --- a/config/config.php +++ b/config/config.php @@ -114,11 +114,11 @@ | app/ path |-------------------------------------------------------------------------- | - | Specifies a the path for the app/ directory. + | Specifies the path for the app/ directory. | | Examples: - | 'app/' = (default Laravel structure), - | 'src/' = (custom location), + | 'app/' = (default Laravel directory), + | 'src/' = (custom directory), | '/' = (root directory). */ 'app' => 'app/', From b6e231b2fefea5cfc7cdcbe86ea9a4e64a84a065 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Wed, 25 Jun 2025 04:57:30 +0100 Subject: [PATCH 17/21] refactor: update stub files for improved response structure and routing configuration --- src/Commands/stubs/composer.stub | 4 +- src/Commands/stubs/controller-api.stub | 44 +++++++++++++------- src/Commands/stubs/controller.invokable.stub | 5 +-- src/Commands/stubs/controller.stub | 15 ++----- src/Commands/stubs/factory.stub | 3 +- src/Commands/stubs/model.stub | 4 +- src/Commands/stubs/routes/api.stub | 4 +- src/Commands/stubs/routes/web.stub | 2 +- src/Commands/stubs/scaffold/provider.stub | 3 +- 9 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/Commands/stubs/composer.stub b/src/Commands/stubs/composer.stub index 68e5b21ed..e2ba66f93 100644 --- a/src/Commands/stubs/composer.stub +++ b/src/Commands/stubs/composer.stub @@ -10,9 +10,7 @@ "extra": { "laravel": { "providers": [], - "aliases": { - - } + "aliases": {} } }, "autoload": { diff --git a/src/Commands/stubs/controller-api.stub b/src/Commands/stubs/controller-api.stub index 025095da3..fdbbe65bf 100644 --- a/src/Commands/stubs/controller-api.stub +++ b/src/Commands/stubs/controller-api.stub @@ -12,9 +12,12 @@ class $CLASS$ extends Controller */ public function index() { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'users' => [] + ], + ]); } /** @@ -22,9 +25,12 @@ class $CLASS$ extends Controller */ public function store(Request $request) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -32,9 +38,12 @@ class $CLASS$ extends Controller */ public function show($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -42,9 +51,12 @@ class $CLASS$ extends Controller */ public function update(Request $request, $id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -52,8 +64,10 @@ class $CLASS$ extends Controller */ public function destroy($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => null, + 'message' => 'Record deleted successfully.', + ]); } } diff --git a/src/Commands/stubs/controller.invokable.stub b/src/Commands/stubs/controller.invokable.stub index 516117ac0..4267f06e2 100644 --- a/src/Commands/stubs/controller.invokable.stub +++ b/src/Commands/stubs/controller.invokable.stub @@ -10,8 +10,5 @@ class $CLASS$ extends Controller /** * Handle the incoming request. */ - public function __invoke(Request $request) - { - return response()->json([]); - } + public function __invoke(Request $request) {} } diff --git a/src/Commands/stubs/controller.stub b/src/Commands/stubs/controller.stub index 79f1b77dd..01904fa1a 100644 --- a/src/Commands/stubs/controller.stub +++ b/src/Commands/stubs/controller.stub @@ -18,10 +18,7 @@ class $CLASS$ extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('$LOWER_NAME$::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class $CLASS$ extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('$LOWER_NAME$::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('$LOWER_NAME$::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/src/Commands/stubs/factory.stub b/src/Commands/stubs/factory.stub index ece09967d..24e45e55d 100644 --- a/src/Commands/stubs/factory.stub +++ b/src/Commands/stubs/factory.stub @@ -3,13 +3,14 @@ namespace $NAMESPACE$; use Illuminate\Database\Eloquent\Factories\Factory; +use $MODEL_NAMESPACE$\$NAME$; class $NAME$Factory extends Factory { /** * The name of the factory's corresponding model. */ - protected $model = \$MODEL_NAMESPACE$\$NAME$::class; + protected $model = $NAME$::class; /** * Define the model's default state. diff --git a/src/Commands/stubs/model.stub b/src/Commands/stubs/model.stub index 1d45d1dfa..f50b71482 100644 --- a/src/Commands/stubs/model.stub +++ b/src/Commands/stubs/model.stub @@ -15,8 +15,8 @@ class $CLASS$ extends Model */ protected $fillable = $FILLABLE$; - // protected static function newFactory(): $NAME$Factory + // protected static function newFactory() // { - // // return $NAME$Factory::new(); + // return $NAME$Factory::new(); // } } diff --git a/src/Commands/stubs/routes/api.stub b/src/Commands/stubs/routes/api.stub index bd71ff0fe..02a4f5ef5 100644 --- a/src/Commands/stubs/routes/api.stub +++ b/src/Commands/stubs/routes/api.stub @@ -3,6 +3,6 @@ use Illuminate\Support\Facades\Route; use $MODULE_NAMESPACE$\$STUDLY_NAME$\$CONTROLLER_NAMESPACE$\$STUDLY_NAME$Controller; -Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () { - Route::apiResource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$'); +Route::middleware(['auth:api'])->prefix('v1')->group(function () { + Route::apiResource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class); }); diff --git a/src/Commands/stubs/routes/web.stub b/src/Commands/stubs/routes/web.stub index 2da42a169..552f97b08 100644 --- a/src/Commands/stubs/routes/web.stub +++ b/src/Commands/stubs/routes/web.stub @@ -4,5 +4,5 @@ use Illuminate\Support\Facades\Route; use $MODULE_NAMESPACE$\$STUDLY_NAME$\$CONTROLLER_NAMESPACE$\$STUDLY_NAME$Controller; Route::middleware(['auth', 'verified'])->group(function () { - Route::resource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$'); + Route::resource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class); }); diff --git a/src/Commands/stubs/scaffold/provider.stub b/src/Commands/stubs/scaffold/provider.stub index 919773f4f..1cca60bc5 100644 --- a/src/Commands/stubs/scaffold/provider.stub +++ b/src/Commands/stubs/scaffold/provider.stub @@ -129,7 +129,8 @@ class $CLASS$ extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** From ec415f07f09b7a48e2de5f80cc83788830aa6104 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Fri, 4 Jul 2025 09:12:31 +0100 Subject: [PATCH 18/21] feat: add Path helper class for utility methods handling of path and namespace --- src/Helpers/Path.php | 815 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 815 insertions(+) create mode 100644 src/Helpers/Path.php diff --git a/src/Helpers/Path.php b/src/Helpers/Path.php new file mode 100644 index 000000000..522e187c7 --- /dev/null +++ b/src/Helpers/Path.php @@ -0,0 +1,815 @@ + + * @author Thomas Schulz + * @author Théo Fidry + * @author Solomon Ochepa + */ +final class Path +{ + /** + * The number of buffer entries that triggers a cleanup operation. + */ + private const CLEANUP_THRESHOLD = 1250; + + /** + * The buffer size after the cleanup operation. + */ + private const CLEANUP_SIZE = 1000; + + /** + * Buffers input/output of {@link canonicalize()}. + * + * @var array + */ + private static array $buffer = []; + + private static int $bufferSize = 0; + + public function __construct() {} + + /** + * Clean up a given path/namespace, replacing directory separators. + */ + public static function clean(string $path, string $ds = DIRECTORY_SEPARATOR, string $replace = '\\'): string + { + if ($ds === $replace) { + $replace = ($ds === '/') ? '\\' : '/'; + } + + return Str::of($path)->rtrim($ds) + ->replace($replace, $ds) + ->explode($ds) + ->filter(fn ($segment, $key) => $key == 0 or ! empty($segment)) + ->implode($ds); + } + + /** + * Get a StudlyCase representation of the given path/namespace. + */ + public static function studly(string $path, $ds = '/'): string + { + return collect(explode($ds, Path::clean($path, $ds)))->map(fn ($path) => Str::studly($path))->implode($ds); + } + + public static function lower(string $string): string + { + if (false !== $encoding = mb_detect_encoding($string, null, true)) { + return mb_strtolower($string, $encoding); + } + + return strtolower($string); + } + + /** + * Canonicalizes the given path. + * + * During normalization, all slashes are replaced by forward slashes ("/"). + * Furthermore, all "." and ".." segments are removed as far as possible. + * ".." segments at the beginning of relative paths are not removed. + * + * ```php + * echo Path::canonicalize("\symfony\puli\..\css\style.css"); + * // => /symfony/css/style.css + * + * echo Path::canonicalize("../css/./style.css"); + * // => ../css/style.css + * ``` + * + * This method is able to deal with both UNIX and Windows paths. + */ + public static function canonicalize(string $path): string + { + if ($path === '') { + return ''; + } + + // This method is called by many other methods in this class. Buffer + // the canonicalized paths to make up for the severe performance + // decrease. + if (isset(self::$buffer[$path])) { + return self::$buffer[$path]; + } + + // Replace "~" with user's home directory. + if ($path[0] === '~') { + $path = self::home_directory().substr($path, 1); + } + + $path = self::clean($path); + + [$root, $pathWithoutRoot] = self::split($path); + + $canonicalParts = self::canonical_parts($root, $pathWithoutRoot); + + // Add the root directory again + self::$buffer[$path] = $canonicalPath = $root.implode('/', $canonicalParts); + self::$bufferSize++; + + // Clean up regularly to prevent memory leaks + if (self::$bufferSize > self::CLEANUP_THRESHOLD) { + self::$buffer = \array_slice(self::$buffer, -self::CLEANUP_SIZE, null, true); + self::$bufferSize = self::CLEANUP_SIZE; + } + + return $canonicalPath; + } + + /** + * Returns the directory part of the path. + * + * This method is similar to PHP's dirname(), but handles various cases + * where dirname() returns a weird result: + * + * - dirname() does not accept backslashes on UNIX + * - dirname("C:/symfony") returns "C:", not "C:/" + * - dirname("C:/") returns ".", not "C:/" + * - dirname("C:") returns ".", not "C:/" + * - dirname("symfony") returns ".", not "" + * - dirname() does not canonicalize the result + * + * This method fixes these shortcomings and behaves like dirname() + * otherwise. + * + * The result is a canonical path. + * + * @return string The canonical directory part. Returns the root directory + * if the root directory is passed. Returns an empty string + * if a relative path is passed that contains no slashes. + * Returns an empty string if an empty string is passed. + */ + public static function directory(string $path): string + { + if ($path === '') { + return ''; + } + + $path = self::canonicalize($path); + + // Maintain scheme + if (false !== $schemeSeparatorPosition = strpos($path, '://')) { + $scheme = substr($path, 0, $schemeSeparatorPosition + 3); + $path = substr($path, $schemeSeparatorPosition + 3); + } else { + $scheme = ''; + } + + if (false === $dirSeparatorPosition = strrpos($path, '/')) { + return ''; + } + + // Directory equals root directory "/" + if ($dirSeparatorPosition === 0) { + return $scheme.'/'; + } + + // Directory equals Windows root "C:/" + if ($dirSeparatorPosition === 2 && ctype_alpha($path[0]) && $path[1] === ':') { + return $scheme.substr($path, 0, 3); + } + + return $scheme.substr($path, 0, $dirSeparatorPosition); + } + + /** + * Returns canonical path of the user's home directory. + * + * Supported operating systems: + * + * - UNIX + * - Windows8 and upper + * + * If your operating system or environment isn't supported, an exception is thrown. + * + * The result is a canonical path. + * + * @throws RuntimeException If your operating system or environment isn't supported + */ + public static function home_directory(): string + { + // For UNIX support + if (getenv('HOME')) { + return self::canonicalize(getenv('HOME')); + } + + // For >= Windows8 support + if (getenv('HOMEDRIVE') && getenv('HOMEPATH')) { + return self::canonicalize(getenv('HOMEDRIVE').getenv('HOMEPATH')); + } + + throw new RuntimeException("Cannot find the home directory path: Your environment or operating system isn't supported."); + } + + /** + * Returns the root directory of a path. + * + * The result is a canonical path. + * + * @return string The canonical root directory. Returns an empty string if + * the given path is relative or empty. + */ + public static function root(string $path): string + { + if ($path === '') { + return ''; + } + + // Maintain scheme + if (false !== $schemeSeparatorPosition = strpos($path, '://')) { + $scheme = substr($path, 0, $schemeSeparatorPosition + 3); + $path = substr($path, $schemeSeparatorPosition + 3); + } else { + $scheme = ''; + } + + $firstCharacter = $path[0]; + + // UNIX root "/" or "\" (Windows style) + if ($firstCharacter === '/' || $firstCharacter === '\\') { + return $scheme.'/'; + } + + $length = \strlen($path); + + // Windows root + if ($length > 1 && $path[1] === ':' && ctype_alpha($firstCharacter)) { + // Special case: "C:" + if ($length === 2) { + return $scheme.$path.'/'; + } + + // Normal case: "C:/ or "C:\" + if ($path[2] === '/' || $path[2] === '\\') { + return $scheme.$firstCharacter.$path[1].'/'; + } + } + + return ''; + } + + /** + * Returns the file name without the extension from a file path. + * + * @param string|null $extension if specified, only that extension is cut + * off (may contain leading dot) + */ + public static function filename(string $path, ?string $extension = null): string + { + if ($path === '') { + return ''; + } + + if ($extension !== null) { + // remove extension and trailing dot + return rtrim(basename($path, $extension), '.'); + } + + return pathinfo($path, \PATHINFO_FILENAME); + } + + /** + * Returns the extension from a file path (without leading dot). + * + * @param bool $forceLowerCase forces the extension to be lower-case + */ + public static function extension(string $path, bool $forceLowerCase = false): string + { + if ($path === '') { + return ''; + } + + $extension = pathinfo($path, \PATHINFO_EXTENSION); + + if ($forceLowerCase) { + $extension = self::lower($extension); + } + + return $extension; + } + + /** + * Returns whether the path has an (or the specified) extension. + * + * @param string $path the path string + * @param string|string[]|null $extensions if null or not provided, checks if + * an extension exists, otherwise + * checks for the specified extension + * or array of extensions (with or + * without leading dot) + * @param bool $ignoreCase whether to ignore case-sensitivity + */ + public static function has_extension(string $path, $extensions = null, bool $ignoreCase = false): bool + { + if ($path === '') { + return false; + } + + $actualExtension = self::extension($path, $ignoreCase); + + // Only check if path has any extension + if ($extensions === [] || $extensions === null) { + return $actualExtension !== ''; + } + + if (\is_string($extensions)) { + $extensions = [$extensions]; + } + + foreach ($extensions as $key => $extension) { + if ($ignoreCase) { + $extension = self::lower($extension); + } + + // remove leading '.' in extensions array + $extensions[$key] = ltrim($extension, '.'); + } + + return \in_array($actualExtension, $extensions, true); + } + + /** + * Changes the extension of a path string. + * + * @param string $path The path string with filename.ext to change. + * @param string $extension new extension (with or without leading dot) + * @return string the path string with new file extension + */ + public static function change_extension(string $path, string $extension): string + { + if ($path === '') { + return ''; + } + + $actualExtension = self::extension($path); + $extension = ltrim($extension, '.'); + + // No extension for paths + if (str_ends_with($path, '/')) { + return $path; + } + + // No actual extension in path + if (! $actualExtension) { + return $path.(str_ends_with($path, '.') ? '' : '.').$extension; + } + + return substr($path, 0, -\strlen($actualExtension)).$extension; + } + + /** + * Turns a relative path into an absolute path in canonical form. + * + * Usually, the relative path is appended to the given base path. Dot + * segments ("." and "..") are removed/collapsed and all slashes turned + * into forward slashes. + * + * ```php + * echo Path::absolute("../style.css", "/symfony/puli/css"); + * // => /symfony/puli/style.css + * ``` + * + * If an absolute path is passed, that path is returned unless its root + * directory is different than the one of the base path. In that case, an + * exception is thrown. + * + * ```php + * Path::absolute("/style.css", "/symfony/puli/css"); + * // => /style.css + * + * Path::absolute("C:/style.css", "C:/symfony/puli/css"); + * // => C:/style.css + * + * Path::absolute("C:/style.css", "/symfony/puli/css"); + * // InvalidArgumentException + * ``` + * + * If the base path is not an absolute path, an exception is thrown. + * + * The result is a canonical path. + * + * @param string $basePath an absolute base path + * + * @throws InvalidArgumentException if the base path is not absolute or if + * the given path is an absolute path with + * a different root than the base path + */ + public static function absolute(string $path, string $basePath): string + { + if ($basePath === '') { + throw new InvalidArgumentException(\sprintf('The base path must be a non-empty string. Got: "%s".', $basePath)); + } + + if (! self::is_absolute($basePath)) { + throw new InvalidArgumentException(\sprintf('The base path "%s" is not an absolute path.', $basePath)); + } + + if (self::is_absolute($path)) { + return self::canonicalize($path); + } + + if (false !== $schemeSeparatorPosition = strpos($basePath, '://')) { + $scheme = substr($basePath, 0, $schemeSeparatorPosition + 3); + $basePath = substr($basePath, $schemeSeparatorPosition + 3); + } else { + $scheme = ''; + } + + return $scheme.self::canonicalize(rtrim($basePath, '/\\').'/'.$path); + } + + public static function is_absolute(string $path): bool + { + if ($path === '') { + return false; + } + + // Strip scheme + if (false !== ($schemeSeparatorPosition = strpos($path, '://')) && $schemeSeparatorPosition !== 1) { + $path = substr($path, $schemeSeparatorPosition + 3); + } + + $firstCharacter = $path[0]; + + // UNIX root "/" or "\" (Windows style) + if ($firstCharacter === '/' || $firstCharacter === '\\') { + return true; + } + + // Windows root + if (\strlen($path) > 1 && ctype_alpha($firstCharacter) && $path[1] === ':') { + // Special case: "C:" + if (\strlen($path) === 2) { + return true; + } + + // Normal case: "C:/ or "C:\" + if ($path[2] === '/' || $path[2] === '\\') { + return true; + } + } + + return false; + } + + /** + * Turns a path into a relative path. + * + * The relative path is created relative to the given base path: + * + * ```php + * echo Path::relative("/symfony/style.css", "/symfony/puli"); + * // => ../style.css + * ``` + * + * If a relative path is passed and the base path is absolute, the relative + * path is returned unchanged: + * + * ```php + * Path::relative("style.css", "/symfony/puli/css"); + * // => style.css + * ``` + * + * If both paths are relative, the relative path is created with the + * assumption that both paths are relative to the same directory: + * + * ```php + * Path::relative("style.css", "symfony/puli/css"); + * // => ../../../style.css + * ``` + * + * If both paths are absolute, their root directory must be the same, + * otherwise an exception is thrown: + * + * ```php + * Path::relative("C:/symfony/style.css", "/symfony/puli"); + * // InvalidArgumentException + * ``` + * + * If the passed path is absolute, but the base path is not, an exception + * is thrown as well: + * + * ```php + * Path::relative("/symfony/style.css", "symfony/puli"); + * // InvalidArgumentException + * ``` + * + * If the base path is not an absolute path, an exception is thrown. + * + * The result is a canonical path. + * + * @throws InvalidArgumentException if the base path is not absolute or if + * the given path has a different root + * than the base path + */ + public static function relative(string $path, ?string $basePath = null): string + { + $path = self::canonicalize($path); + $basePath = self::canonicalize($basePath ?? base_path()); + + [$root, $relativePath] = self::split($path); + [$baseRoot, $relativeBasePath] = self::split($basePath); + + // If the base path is given as absolute path and the path is already + // relative, consider it to be relative to the given absolute path + // already + if ($root === '' && $baseRoot !== '') { + // If base path is already in its root + if ($relativeBasePath === '') { + $relativePath = ltrim($relativePath, './\\'); + } + + return $relativePath; + } + + // If the passed path is absolute, but the base path is not, we + // cannot generate a relative path + if ($root !== '' && $baseRoot === '') { + throw new InvalidArgumentException(\sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath)); + } + + // Fail if the roots of the two paths are different + if ($baseRoot && $root !== $baseRoot) { + throw new InvalidArgumentException(\sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot)); + } + + if ($relativeBasePath === '') { + return $relativePath; + } + + // Build a "../../" prefix with as many "../" parts as necessary + $parts = explode('/', $relativePath); + $baseParts = explode('/', $relativeBasePath); + $dotDotPrefix = ''; + + // Once we found a non-matching part in the prefix, we need to add + // "../" parts for all remaining parts + $match = true; + + foreach ($baseParts as $index => $basePart) { + if ($match && isset($parts[$index]) && $basePart === $parts[$index]) { + unset($parts[$index]); + + continue; + } + + $match = false; + $dotDotPrefix .= '../'; + } + + return rtrim($dotDotPrefix.implode('/', $parts), '/'); + } + + public static function is_relative(string $path): bool + { + return ! self::is_absolute($path); + } + + /** + * Returns the longest common base path in canonical form of a set of paths or + * `null` if the paths are on different Windows partitions. + * + * Dot segments ("." and "..") are removed/collapsed and all slashes turned + * into forward slashes. + * + * ```php + * $basePath = Path::base_path( + * '/symfony/css/style.css', + * '/symfony/css/..' + * ); + * // => /symfony + * ``` + * + * The root is returned if no common base path can be found: + * + * ```php + * $basePath = Path::base_path( + * '/symfony/css/style.css', + * '/puli/css/..' + * ); + * // => / + * ``` + * + * If the paths are located on different Windows partitions, `null` is + * returned. + * + * ```php + * $basePath = Path::base_path( + * 'C:/symfony/css/style.css', + * 'D:/symfony/css/..' + * ); + * // => null + * ``` + */ + public static function base_path(string ...$paths): ?string + { + [$bpRoot, $basePath] = self::split(self::canonicalize(reset($paths))); + + for (next($paths); key($paths) !== null && $basePath !== ''; next($paths)) { + [$root, $path] = self::split(self::canonicalize(current($paths))); + + // If we deal with different roots (e.g. C:/ vs. D:/), it's time + // to quit + if ($root !== $bpRoot) { + return null; + } + + // Make the base path shorter until it fits into path + while (true) { + if ($basePath === '.') { + // No more base paths + $basePath = ''; + + // next path + continue 2; + } + + // Prevent false positives for common prefixes + // see is_base_path() + if (str_starts_with($path.'/', $basePath.'/')) { + // next path + continue 2; + } + + $basePath = \dirname($basePath); + } + } + + return $bpRoot.$basePath; + } + + /** + * Returns whether a path is a base path of another path. + * + * Dot segments ("." and "..") are removed/collapsed and all slashes turned + * into forward slashes. + * + * ```php + * Path::is_base_path('/symfony', '/symfony/css'); + * // => true + * + * Path::is_base_path('/symfony', '/symfony'); + * // => true + * + * Path::is_base_path('/symfony', '/symfony/..'); + * // => false + * + * Path::is_base_path('/symfony', '/puli'); + * // => false + * ``` + */ + public static function is_base_path(string $basePath, string $ofPath): bool + { + $basePath = self::canonicalize($basePath); + $ofPath = self::canonicalize($ofPath); + + // Append slashes to prevent false positives when two paths have + // a common prefix, for example /base/foo and /base/foobar. + // Don't append a slash for the root "/", because then that root + // won't be discovered as common prefix ("//" is not a prefix of + // "/foobar/"). + return str_starts_with($ofPath.'/', rtrim($basePath, '/').'/'); + } + + /** + * Returns whether the given path is on the local filesystem. + */ + public static function is_local(string $path): bool + { + return $path !== '' && ! str_contains($path, '://'); + } + + /** + * Splits a canonical path into its root directory and the remainder. + * + * If the path has no root directory, an empty root directory will be + * returned. + * + * If the root directory is a Windows style partition, the resulting root + * will always contain a trailing slash. + * + * list ($root, $path) = Path::split("C:/symfony") + * // => ["C:/", "symfony"] + * + * list ($root, $path) = Path::split("C:") + * // => ["C:/", ""] + * + * @return array{string, string} an array with the root directory and the remaining relative path + */ + public static function split(string $path): array + { + if ($path === '') { + return ['', '']; + } + + // Remember scheme as part of the root, if any + if (false !== $schemeSeparatorPosition = strpos($path, '://')) { + $root = substr($path, 0, $schemeSeparatorPosition + 3); + $path = substr($path, $schemeSeparatorPosition + 3); + } else { + $root = ''; + } + + $length = \strlen($path); + + // Remove and remember root directory + if (str_starts_with($path, '/')) { + $root .= '/'; + $path = $length > 1 ? substr($path, 1) : ''; + } elseif ($length > 1 && ctype_alpha($path[0]) && $path[1] === ':') { + if ($length === 2) { + // Windows special case: "C:" + $root .= $path.'/'; + $path = ''; + } elseif ($path[2] === '/') { + // Windows normal case: "C:/".. + $root .= substr($path, 0, 3); + $path = $length > 3 ? substr($path, 3) : ''; + } + } + + return [$root, $path]; + } + + /** + * Joins two or more path strings into a canonical path. + */ + public static function join(string ...$paths): string + { + $finalPath = null; + $wasScheme = false; + + foreach ($paths as $path) { + if ($path === '') { + continue; + } + + if ($finalPath === null) { + // For first part we keep slashes, like '/top', 'C:\' or 'phar://' + $finalPath = $path; + $wasScheme = str_contains($path, '://'); + + continue; + } + + // Only add slash if previous part didn't end with '/' or '\' + if (! \in_array(substr($finalPath, -1), ['/', '\\'], true)) { + $finalPath .= '/'; + } + + // If first part included a scheme like 'phar://' we allow \current part to start with '/', otherwise trim + $finalPath .= $wasScheme ? $path : ltrim($path, '/'); + $wasScheme = false; + } + + if ($finalPath === null) { + return ''; + } + + return self::canonicalize($finalPath); + } + + /** + * @return string[] + */ + public static function canonical_parts(string $root, string $pathWithoutRoot): array + { + $parts = explode('/', $pathWithoutRoot); + + $canonicalParts = []; + + // Collapse "." and "..", if possible + foreach ($parts as $part) { + if ($part === '.' || $part === '') { + continue; + } + + // Collapse ".." with the previous part, if one exists + // Don't collapse ".." if the previous part is also ".." + if ($part === '..' && \count($canonicalParts) > 0 && $canonicalParts[\count($canonicalParts) - 1] !== '..') { + array_pop($canonicalParts); + + continue; + } + + // Only add ".." prefixes for relative paths + if ($part !== '..' || $root === '') { + $canonicalParts[] = $part; + } + } + + return $canonicalParts; + } +} From 2da03c496cec884f9bf2450bf336081673f4fe8c Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Fri, 4 Jul 2025 09:17:28 +0100 Subject: [PATCH 19/21] refactor: replace custom path cleaning and studlying methods with Path helper class for improved consistency --- src/Traits/PathNamespace.php | 61 +++++------------------------- tests/Traits/PathNamespaceTest.php | 19 +++++----- 2 files changed, 19 insertions(+), 61 deletions(-) diff --git a/src/Traits/PathNamespace.php b/src/Traits/PathNamespace.php index 2e636cfee..057d255b6 100644 --- a/src/Traits/PathNamespace.php +++ b/src/Traits/PathNamespace.php @@ -3,59 +3,16 @@ namespace Nwidart\Modules\Traits; use Illuminate\Support\Str; +use Nwidart\Modules\Helpers\Path; trait PathNamespace { - /** - * Clean up the given path/namespace, replacing directory separators. - */ - public function clean(string $path, string $ds = '/', string $replace = '\\'): string - { - if ($ds === $replace) { - $replace = $ds === '/' ? '\\' : '/'; - } - - return Str::of($path)->rtrim($ds)->replace($replace, $ds)->explode($ds)->filter(fn ($segment, $key) => $key == 0 or ! empty($segment))->implode($ds); - } - - /** - * Clean up the given path. - */ - public function clean_path(string $path, string $ds = '/', string $replace = '\\'): string - { - return $this->clean($path, $ds, $replace); - } - - /** - * Clean up the namespace, replacing directory separators. - */ - public function clean_namespace(string $namespace, string $ds = '\\', string $replace = '/'): string - { - return $this->clean($namespace, $ds, $replace); - } - - /** - * Get a well-formatted StudlyCase representation from the given path. - */ - public function studly_path(string $path, $ds = '/'): string - { - return collect(explode($ds, $this->clean_path($path, $ds)))->map(fn ($path) => Str::studly($path))->implode($ds); - } - - /** - * Get a well-formatted StudlyCase namespace. - */ - public function studly_namespace(string $namespace, $ds = '\\'): string - { - return $this->studly_path($this->clean_namespace($namespace, $ds), $ds); - } - /** * Generate a well-formatted StudlyCase namespace from the given path. */ public function path_namespace(string $path): string { - return $this->studly_namespace($this->is_app_path($path) ? $this->app_path($path) : $path); + return Path::studly($this->is_app_path($path) ? $this->app_path($path) : $path, '\\'); } /** @@ -72,7 +29,7 @@ public function module_path(string $module = 'Blog', ?string $path = null): stri { $module = module($module, true); - return $module->path($this->path($path)); + return $path ? $module->path($this->path($path)) : $module->getPath(); } public function module_app_path(string $module = 'Blog', ?string $path = null): string @@ -108,7 +65,7 @@ public function namespace(string $namespace): string */ public function path(string $path): string { - return $this->is_app_path($path) ? $this->app_path($path) : $this->clean_path($path); + return $this->is_app_path($path) ? $this->app_path($path) : Path::clean($path); } /** @@ -123,11 +80,11 @@ public function app_path(?string $path = null): string $app_path = $default; } - $app_path = trim($this->clean_path($app_path), '/').'/'; + $app_path = trim(Path::clean($app_path), '/').'/'; // Remove duplicated app_path if ($path) { - $path = trim($this->clean_path($path), '/').'/'; + $path = trim(Path::clean($path), '/').'/'; while ($this->is_app_path($path)) { $path = Str::of($path)->after('/'); @@ -137,7 +94,7 @@ public function app_path(?string $path = null): string $app_path .= ltrim($path, '/'); } - return $this->clean_path(trim($app_path, '/')); + return Path::clean(trim($app_path, '/')); } /** @@ -150,9 +107,9 @@ public function is_app_path(string $path): bool if (empty($app_path)) { $app_path = $default; } - $app_path = trim($this->clean_path($app_path), '/').'/'; + $app_path = trim(Path::clean($app_path), '/').'/'; - $path = trim($this->clean_path($path), '/').'/'; + $path = trim(Path::clean($path), '/').'/'; $replaces = array_filter(array_unique([$app_path, $default]), fn ($x) => Str::lower($x)); if (Str::of(Str::lower($path))->startsWith($replaces)) { diff --git a/tests/Traits/PathNamespaceTest.php b/tests/Traits/PathNamespaceTest.php index bc7122521..500767c66 100644 --- a/tests/Traits/PathNamespaceTest.php +++ b/tests/Traits/PathNamespaceTest.php @@ -2,6 +2,7 @@ namespace Nwidart\Modules\Tests\Traits; +use Nwidart\Modules\Helpers\Path; use Nwidart\Modules\Tests\BaseTestCase; class PathNamespaceTest extends BaseTestCase @@ -13,22 +14,22 @@ protected function setUp(): void public function test_converts_to_studly_path() { - $this->assertSame('Modules/User/App/Models/User', $this->studly_path('Modules/User/app/Models/User')); + $this->assertSame('Modules/User/App/Models/User', Path::studly('Modules/User/app/Models/User')); } public function test_converts_namespace_with_studly_path() { - $this->assertSame('Modules\\User\\App\\Models\\User', $this->studly_path('Modules\\User\\app\\Models\\User', '\\')); + $this->assertSame('Modules\\User\\App\\Models\\User', Path::studly('Modules\\User\\app\\Models\\User', '\\')); } public function test_converts_to_studly_namespace() { - $this->assertSame('Modules\User\App\Models\User', $this->studly_namespace('Modules/User/app/Models/User')); + $this->assertSame('Modules\User\App\Models\User', Path::studly('Modules/User/app/Models/User', '\\')); } public function test_converts_custom_namespace_with_studly_namespace() { - $this->assertSame('Modules\\\\User\\\\App\\\\Models\\\\User', $this->studly_namespace('Modules\\\\User\\\\app\\\\Models\\\\User', '\\\\')); + $this->assertSame('Modules\\\\User\\\\App\\\\Models\\\\User', Path::studly('Modules\\\\User\\\\app\\\\Models\\\\User', '\\\\')); } public function test_generates_path_namespace() @@ -44,15 +45,15 @@ public function test_generates_module_namespace() public function test_cleans_path() { - $this->assertSame('blog/services', $this->clean_path('blog//services')); - $this->assertSame('', $this->clean_path('//')); - $this->assertSame('', $this->clean_path('')); + $this->assertSame('blog/services', Path::clean('blog//services')); + $this->assertSame('', Path::clean('//')); + $this->assertSame('', Path::clean('')); } public function test_cleans_namespace_with_clean_path() { - $this->assertSame('Modules\User\App\Models\User', $this->clean_path('Modules\\\\User/App\\Models\User\\//', '\\')); - $this->assertSame('', $this->clean_path('\\')); + $this->assertSame('Modules\User\App\Models\User', Path::clean('Modules\\\\User/App\\Models\User\\//', '\\')); + $this->assertSame('', Path::clean('\\')); } public function test_identifies_app_path() From a9eee00e14a0a90dca6035bd9bb82ca5e3cc78de Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Fri, 4 Jul 2025 09:19:51 +0100 Subject: [PATCH 20/21] refactor: add deprecated getModuleAppPath and getModuleBasePath methods for backward compatibility --- src/helpers.php | 2 +- tests/BaseTestCase.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helpers.php b/src/helpers.php index 6240a8bb2..18f4fe964 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -14,7 +14,7 @@ * @param bool $instance Whether to return the module's instance instead of the status. Defaults to false [status]. * @return bool|Module The module instance or its status. */ - function module(string $name, bool $instance = false): bool|Module + function module(string $name, bool $instance = false): Module|bool { /** @var FileRepository $repository */ $repository = app('modules'); diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 943d95938..e3a86456e 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -92,4 +92,20 @@ protected function module_app_path(?string $path = null, string $module = 'Blog' { return $this->module_path($this->app_path($path), $module); } + + /** + * @deprecated Use `module_app_path` instead. + */ + protected function getModuleAppPath(string $moduleName = 'Blog'): string + { + return $this->module_app_path(null, $moduleName); + } + + /** + * @deprecated Use `module_path` instead. + */ + protected function getModuleBasePath(string $moduleName = 'Blog'): string + { + return $this->module_path(null, $moduleName); + } } From 2ed853f38bd2f6c0a24fb36afaab48d18c880fc5 Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Fri, 4 Jul 2025 09:21:27 +0100 Subject: [PATCH 21/21] Update snapshot tests --- ...roller_to_class_name_if_not_present__1.txt | 15 ++----- ...it_can_change_the_default_namespace__1.txt | 15 ++----- ...test_it_can_change_the_default_path__1.txt | 15 ++----- ...mespace_with_correct_generated_file__1.txt | 15 ++----- ...generated_correct_file_with_content__1.txt | 15 ++----- ...test_it_generates_an_api_controller__1.txt | 44 ++++++++++++------- ...t_generates_an_invokable_controller__1.txt | 5 +-- ...eCommandTest__test_it_makes_factory__1.txt | 3 +- ...est__test_changes_default_namespace__1.txt | 4 +- ...mandTest__test_changes_default_path__1.txt | 4 +- ...mandTest__test_generates_controller__1.txt | 15 ++----- ...nd_migration_when_flags_are_present__1.txt | 15 ++----- ...tes_controller_when_flag_is_present__1.txt | 15 ++----- ...generates_correct_file_with_content__1.txt | 4 +- ...t_generates_correct_fillable_fields__1.txt | 4 +- ...nable_and_route_provider_is_disable__1.txt | 3 +- ...enable_and_route_provider_is_enable__1.txt | 3 +- ...generates_api_module_with_resources__1.txt | 3 +- ...generates_api_module_with_resources__2.txt | 44 ++++++++++++------- ...t__test_it_generates_api_route_file__1.txt | 4 +- ...ith_multi_segment_default_namespace__1.txt | 4 +- ...generates_correct_composerjson_file__1.txt | 4 +- ..._module_namespace_using_studly_case__1.txt | 3 +- ..._test_it_generates_module_resources__1.txt | 3 +- ..._test_it_generates_module_resources__4.txt | 15 ++----- ...generates_web_module_with_resources__1.txt | 3 +- ...generates_web_module_with_resources__2.txt | 15 ++----- ...es_when_adding_more_than_one_option__1.txt | 3 +- ...es_when_adding_more_than_one_option__2.txt | 15 ++----- ...t__test_it_generates_web_route_file__1.txt | 2 +- ...ith_multi_segment_default_namespace__1.txt | 2 +- ...odule_with_custom_provider_location__2.txt | 4 +- ...it_can_change_the_default_namespace__1.txt | 3 +- ...test_it_can_change_the_default_path__1.txt | 3 +- ..._migration_resources_location_paths__1.txt | 3 +- ...vice_provider_with_resource_loading__1.txt | 3 +- 36 files changed, 132 insertions(+), 198 deletions(-) diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_appends_controller_to_class_name_if_not_present__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_appends_controller_to_class_name_if_not_present__1.txt index 2052fe7aa..ddba42398 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_appends_controller_to_class_name_if_not_present__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_appends_controller_to_class_name_if_not_present__1.txt @@ -18,10 +18,7 @@ class MyController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class MyController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index 2fa0c40b5..4183e7492 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -18,10 +18,7 @@ class MyController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class MyController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_path__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_path__1.txt index 2fa0c40b5..4183e7492 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_path__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_change_the_default_path__1.txt @@ -18,10 +18,7 @@ class MyController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class MyController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file__1.txt index 76cedd372..80c86815e 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file__1.txt @@ -18,10 +18,7 @@ class MyController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class MyController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 2052fe7aa..ddba42398 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -18,10 +18,7 @@ class MyController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class MyController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_api_controller__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_api_controller__1.txt index 8499b84bc..dca70cc03 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_api_controller__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_api_controller__1.txt @@ -12,9 +12,12 @@ class MyController extends Controller */ public function index() { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'users' => [] + ], + ]); } /** @@ -22,9 +25,12 @@ class MyController extends Controller */ public function store(Request $request) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -32,9 +38,12 @@ class MyController extends Controller */ public function show($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -42,9 +51,12 @@ class MyController extends Controller */ public function update(Request $request, $id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -52,8 +64,10 @@ class MyController extends Controller */ public function destroy($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => null, + 'message' => 'Record deleted successfully.', + ]); } } diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt index 0a195057f..48963122c 100644 --- a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt @@ -10,8 +10,5 @@ class MyController extends Controller /** * Handle the incoming request. */ - public function __invoke(Request $request) - { - return response()->json([]); - } + public function __invoke(Request $request) {} } diff --git a/tests/Commands/Make/__snapshots__/FactoryMakeCommandTest__test_it_makes_factory__1.txt b/tests/Commands/Make/__snapshots__/FactoryMakeCommandTest__test_it_makes_factory__1.txt index df7bc0648..787a30d35 100644 --- a/tests/Commands/Make/__snapshots__/FactoryMakeCommandTest__test_it_makes_factory__1.txt +++ b/tests/Commands/Make/__snapshots__/FactoryMakeCommandTest__test_it_makes_factory__1.txt @@ -3,13 +3,14 @@ namespace Modules\Blog\Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; +use Modules\Blog\App\Models\Post; class PostFactory extends Factory { /** * The name of the factory's corresponding model. */ - protected $model = \Modules\Blog\App\Models\Post::class; + protected $model = Post::class; /** * Define the model's default state. diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_namespace__1.txt index 7355e76a1..9bbc7e190 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_namespace__1.txt @@ -15,8 +15,8 @@ class Post extends Model */ protected $fillable = []; - // protected static function newFactory(): PostFactory + // protected static function newFactory() // { - // // return PostFactory::new(); + // return PostFactory::new(); // } } diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_path__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_path__1.txt index 7355e76a1..9bbc7e190 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_path__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_changes_default_path__1.txt @@ -15,8 +15,8 @@ class Post extends Model */ protected $fillable = []; - // protected static function newFactory(): PostFactory + // protected static function newFactory() // { - // // return PostFactory::new(); + // return PostFactory::new(); // } } diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller__1.txt index e3d176d1a..dda7423ba 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller__1.txt @@ -18,10 +18,7 @@ class PostController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class PostController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__1.txt index e3d176d1a..dda7423ba 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_and_migration_when_flags_are_present__1.txt @@ -18,10 +18,7 @@ class PostController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class PostController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt index e3d176d1a..dda7423ba 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_controller_when_flag_is_present__1.txt @@ -18,10 +18,7 @@ class PostController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class PostController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_file_with_content__1.txt index 96e669fc9..68679f3b8 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_file_with_content__1.txt @@ -15,8 +15,8 @@ class Post extends Model */ protected $fillable = []; - // protected static function newFactory(): PostFactory + // protected static function newFactory() // { - // // return PostFactory::new(); + // return PostFactory::new(); // } } diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_fillable_fields__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_fillable_fields__1.txt index 3440ae590..e38870cee 100644 --- a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_fillable_fields__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_generates_correct_fillable_fields__1.txt @@ -15,8 +15,8 @@ class Post extends Model */ protected $fillable = ["title","slug"]; - // protected static function newFactory(): PostFactory + // protected static function newFactory() // { - // // return PostFactory::new(); + // return PostFactory::new(); // } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt index 5489cf923..9db97c072 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt index 9e71a8100..74748911e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt index 9e71a8100..74748911e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt index b6df05ff2..fd7747ebc 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt @@ -12,9 +12,12 @@ class BlogController extends Controller */ public function index() { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'users' => [] + ], + ]); } /** @@ -22,9 +25,12 @@ class BlogController extends Controller */ public function store(Request $request) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -32,9 +38,12 @@ class BlogController extends Controller */ public function show($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -42,9 +51,12 @@ class BlogController extends Controller */ public function update(Request $request, $id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => [ + // 'user' => [] + ], + ]); } /** @@ -52,8 +64,10 @@ class BlogController extends Controller */ public function destroy($id) { - // - - return response()->json([]); + return response()->json([ + 'status' => 'success', + 'data' => null, + 'message' => 'Record deleted successfully.', + ]); } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt index d333799f6..6fdc1a46e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt @@ -3,6 +3,6 @@ use Illuminate\Support\Facades\Route; use Modules\Blog\App\Http\Controllers\BlogController; -Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () { - Route::apiResource('blogs', BlogController::class)->names('blog'); +Route::middleware(['auth:api'])->prefix('v1')->group(function () { + Route::apiResource('blogs', BlogController::class); }); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt index 661b647dc..fe7efb9ec 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file_with_multi_segment_default_namespace__1.txt @@ -3,6 +3,6 @@ use Illuminate\Support\Facades\Route; use Custom\Modules\Blog\App\Http\Controllers\BlogController; -Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () { - Route::apiResource('blogs', BlogController::class)->names('blog'); +Route::middleware(['auth:api'])->prefix('v1')->group(function () { + Route::apiResource('blogs', BlogController::class); }); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt index b1d1c7ac4..71accf83b 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt @@ -10,9 +10,7 @@ "extra": { "laravel": { "providers": [], - "aliases": { - - } + "aliases": {} } }, "autoload": { diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt index 1cc6b2efb..c2c26762c 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt @@ -129,7 +129,8 @@ class ModuleNameServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt index 9e71a8100..74748911e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt index f2e8d5ab6..4f3208757 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt @@ -18,10 +18,7 @@ class BlogController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class BlogController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt index 9e71a8100..74748911e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt index f2e8d5ab6..4f3208757 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt @@ -18,10 +18,7 @@ class BlogController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class BlogController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt index 9e71a8100..74748911e 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt index f2e8d5ab6..4f3208757 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt @@ -18,10 +18,7 @@ class BlogController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - return view('blog::create'); - } + public function create() {} /** * Store a newly created resource in storage. @@ -31,18 +28,12 @@ class BlogController extends Controller /** * Show the specified resource. */ - public function show($id) - { - return view('blog::show'); - } + public function show($id) {} /** * Show the form for editing the specified resource. */ - public function edit($id) - { - return view('blog::edit'); - } + public function edit($id) {} /** * Update the specified resource in storage. diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt index 00a3e5f65..024e4ba6c 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt @@ -4,5 +4,5 @@ use Illuminate\Support\Facades\Route; use Modules\Blog\App\Http\Controllers\BlogController; Route::middleware(['auth', 'verified'])->group(function () { - Route::resource('blogs', BlogController::class)->names('blog'); + Route::resource('blogs', BlogController::class); }); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt index a1c995006..89b3a80f4 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file_with_multi_segment_default_namespace__1.txt @@ -4,5 +4,5 @@ use Illuminate\Support\Facades\Route; use Custom\Modules\Blog\App\Http\Controllers\BlogController; Route::middleware(['auth', 'verified'])->group(function () { - Route::resource('blogs', BlogController::class)->names('blog'); + Route::resource('blogs', BlogController::class); }); diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt index b1d1c7ac4..71accf83b 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_custom_provider_location__2.txt @@ -10,9 +10,7 @@ "extra": { "laravel": { "providers": [], - "aliases": { - - } + "aliases": {} } }, "autoload": { diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index cfe3fed1a..eb7d28d97 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt index cfe3fed1a..eb7d28d97 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_path__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt index 4a5b71ae9..3562a7f8a 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /** diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt index 7ec787868..e7431ad2d 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt @@ -129,7 +129,8 @@ class BlogServiceProvider extends ServiceProvider $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); - Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + $namespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($namespace, $this->nameLower); } /**