Skip to content

Commit

Permalink
feat: add app module
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed Jan 16, 2024
1 parent dbafd6a commit ba3075b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 : '',
);
Expand Down
11 changes: 11 additions & 0 deletions tests/Commands/MakeAppCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions tests/Commands/MakeControllerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ba3075b

Please sign in to comment.