From 6217735d31caa38209e31402a5fe2880ef0c79ff Mon Sep 17 00:00:00 2001 From: bfs2021 <101915083+bfs2021@users.noreply.github.com> Date: Sat, 7 Nov 2026 08:09:24 +0800 Subject: [PATCH 1/2] fix: resolve the source location for generators with --path --- .../Console/Commands/Concerns/HasPathSupport.php | 4 +++- tests/Feature/Hook/ActionMakeCommandTest.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Foundation/Console/Commands/Concerns/HasPathSupport.php b/src/Foundation/Console/Commands/Concerns/HasPathSupport.php index 51a17fdb..ccc2db5f 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', ]; } } diff --git a/tests/Feature/Hook/ActionMakeCommandTest.php b/tests/Feature/Hook/ActionMakeCommandTest.php index e9728d44..ffcde6b0 100644 --- a/tests/Feature/Hook/ActionMakeCommandTest.php +++ b/tests/Feature/Hook/ActionMakeCommandTest.php @@ -41,3 +41,13 @@ ->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(); + + expect(collect(File::allFiles(base_path($customDir))))->not->toBeEmpty(); + + File::deleteDirectory(base_path($customDir)); +}); From 4c1a63ffe4b2a82730fd7bf7ab31a9d7a62895f5 Mon Sep 17 00:00:00 2001 From: bfs2021 <101915083+bfs2021@users.noreply.github.com> Date: Thu, 12 Nov 2026 21:31:45 +0800 Subject: [PATCH 2/2] fix: derive the --path source namespace from the app namespace --- src/Foundation/Console/Commands/Concerns/HasPathSupport.php | 2 +- tests/Feature/Hook/ActionMakeCommandTest.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Foundation/Console/Commands/Concerns/HasPathSupport.php b/src/Foundation/Console/Commands/Concerns/HasPathSupport.php index ccc2db5f..d1abe2d5 100644 --- a/src/Foundation/Console/Commands/Concerns/HasPathSupport.php +++ b/src/Foundation/Console/Commands/Concerns/HasPathSupport.php @@ -78,7 +78,7 @@ protected function resolveCustomPath(): array 'path' => $path, 'namespace' => 'App', // Default namespace for custom paths 'source_path' => $path, - 'source_namespace' => 'App', + 'source_namespace' => app()->getNamespace(), ]; } } diff --git a/tests/Feature/Hook/ActionMakeCommandTest.php b/tests/Feature/Hook/ActionMakeCommandTest.php index ffcde6b0..40b0305a 100644 --- a/tests/Feature/Hook/ActionMakeCommandTest.php +++ b/tests/Feature/Hook/ActionMakeCommandTest.php @@ -47,7 +47,11 @@ $this->artisan('pollora:make:action', ['name' => 'SyncToCrm', '--path' => $customDir, '--hook' => 'save_post'])->assertSuccessful(); - expect(collect(File::allFiles(base_path($customDir))))->not->toBeEmpty(); + $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)); });