diff --git a/src/Foundation/Console/Commands/Concerns/HasPathSupport.php b/src/Foundation/Console/Commands/Concerns/HasPathSupport.php index 51a17fdb..d1abe2d5 100644 --- a/src/Foundation/Console/Commands/Concerns/HasPathSupport.php +++ b/src/Foundation/Console/Commands/Concerns/HasPathSupport.php @@ -56,7 +56,7 @@ protected function resolvePath(): ?string /** * Resolve custom path location. * - * @return array{type: string, path: string, namespace: string} + * @return array{type: string, path: string, namespace: string, source_path: string, source_namespace: string} * * @throws InvalidArgumentException When custom path is empty */ @@ -77,6 +77,8 @@ protected function resolveCustomPath(): array 'type' => 'custom', 'path' => $path, 'namespace' => 'App', // Default namespace for custom paths + 'source_path' => $path, + 'source_namespace' => app()->getNamespace(), ]; } } diff --git a/tests/Feature/Hook/ActionMakeCommandTest.php b/tests/Feature/Hook/ActionMakeCommandTest.php index e9728d44..40b0305a 100644 --- a/tests/Feature/Hook/ActionMakeCommandTest.php +++ b/tests/Feature/Hook/ActionMakeCommandTest.php @@ -41,3 +41,17 @@ ->toContain(" #[Action('save_post', priority:10)]\n public function handleSavePost(): void") ->toContain(" #[Action('user_register', priority:10)]\n #[Async]\n public function handleUserRegister(): void"); }); + +it('generates the class in the custom path with --path', function (): void { + $customDir = 'pollora-make-action-path-'.uniqid(); + + $this->artisan('pollora:make:action', ['name' => 'SyncToCrm', '--path' => $customDir, '--hook' => 'save_post'])->assertSuccessful(); + + $generated = (string) collect(File::allFiles(base_path($customDir)))->first()?->getContents(); + + expect($generated) + ->toContain('namespace '.app()->getNamespace().'Cms\\Hooks;') + ->and($generated)->not->toContain('namespace AppCms\\'); + + File::deleteDirectory(base_path($customDir)); +});