From ba3075bc91215279c3e9fc5aa57f99dc9779d3da Mon Sep 17 00:00:00 2001 From: Jonas Regner Date: Tue, 16 Jan 2024 09:36:09 +0100 Subject: [PATCH] feat: add app module --- src/NameResolver.php | 19 ++++++++++++++----- tests/Commands/MakeAppCommandTest.php | 11 +++++++++++ tests/Commands/MakeControllerCommandTest.php | 12 ++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/NameResolver.php b/src/NameResolver.php index 5447378..b8c9bf6 100644 --- a/src/NameResolver.php +++ b/src/NameResolver.php @@ -25,6 +25,8 @@ final class NameResolver private string $path; + private ?string $module = null; + public function __construct( private readonly BaseCommand $command, private readonly string $name @@ -70,22 +72,29 @@ private function init(): void if ($numParts === 1) { $this->appOrDomain = $this->askForAppOrDomainName($commandType); - } elseif ($numParts === 2) { - $appOrDomain = Str::of($parts[0])->lower()->ucfirst()->value(); + } elseif ($numParts === 2 || ($numParts === 3 && $commandType === 'APP')) { + $appOrDomain = $parts[0]; if ($commandType === 'APP' && ! $this->isExistingApp($appOrDomain)) { throw new AppDoesNotExistsException($parts[0]); } - $this->appOrDomain = $appOrDomain; - $this->setDirectoryAndClassName($parts[1]); + if ($numParts === 3 && $commandType === 'APP') { + $this->appOrDomain = $appOrDomain; + $this->module = $parts[1]; + $this->setDirectoryAndClassName($parts[2]); + } else { + $this->appOrDomain = $appOrDomain; + $this->setDirectoryAndClassName($parts[1]); + } } else { throw new InvalidNameException($this->name); } $this->namespace = sprintf( - $this->command->getNamespaceTemplate().'%s', + $this->command->getNamespaceTemplate().'%s%s', $this->appOrDomain, + $this->module ? '\\'.$this->module.'\\' : '', $this->command->getType()->getNamespace(), $this->directory ? '\\'.$this->directory : '', ); diff --git a/tests/Commands/MakeAppCommandTest.php b/tests/Commands/MakeAppCommandTest.php index ed0b5d3..6867444 100644 --- a/tests/Commands/MakeAppCommandTest.php +++ b/tests/Commands/MakeAppCommandTest.php @@ -18,6 +18,17 @@ public function testCanMakeModule(): void $this->assertStringNotContainsString('{{ module }}', $contents); } + public function testCanMakeSnakeCaseModule(): void + { + $this->artisan('beyond:make:app SuperAdmin'); + + $file = beyond_app_path('SuperAdmin/Providers/SuperAdminServiceProvider.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ module }}', $contents); + } + public function testCanMakeModuleUsingForce(): void { $this->artisan('beyond:make:app Admin'); diff --git a/tests/Commands/MakeControllerCommandTest.php b/tests/Commands/MakeControllerCommandTest.php index d414d35..ccae5bf 100644 --- a/tests/Commands/MakeControllerCommandTest.php +++ b/tests/Commands/MakeControllerCommandTest.php @@ -25,6 +25,18 @@ public function testCanMakeController(): void $this->assertStringNotContainsString('{{ className }}', $contents); } + public function testCanMakeModuleController(): void + { + $this->artisan('beyond:make:controller User.User.UserController'); + + $file = beyond_app_path('User/User/Controllers/UserController.php'); + $contents = file_get_contents($file); + + $this->assertFileExists($file); + $this->assertStringNotContainsString('{{ namespace }}', $contents); + $this->assertStringNotContainsString('{{ className }}', $contents); + } + public function testCanMakeControllerUsingForce(): void { $this->artisan('beyond:make:controller User.UserController');