Skip to content

Commit

Permalink
fix: wrong namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed Jul 10, 2024
1 parent f4b912d commit 38ec100
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [akrillia]
2 changes: 1 addition & 1 deletion src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function setNamespace(): void
{
if ($this->isGlobal()) {
$this->namespace = sprintf(
'Support\\%s\\%s',
'Support\\%s%s',
$this->command->getType()->getNamespace(),
$this->directory ? '\\'.$this->directory : '',
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Commands/MakeCastCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function testCanMakeCast(): void
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Support\\Casts', $contents);
$this->assertClassName('TimezoneCast', $contents);
}

public function testCanMakeCastUsingForce(): void
Expand All @@ -26,8 +26,8 @@ public function testCanMakeCastUsingForce(): void
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Support\\Casts', $contents);
$this->assertClassName('TimezoneCast', $contents);

$code = $this->artisan('beyond:make:cast TimezoneCast --force');

Expand Down
12 changes: 6 additions & 6 deletions tests/Commands/MakeRuleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ class MakeRuleCommandTest extends TestCase
{
public function testCanMakeRule(): void
{
$this->artisan('beyond:make:rule User.UniqueUser');
$this->artisan('beyond:make:rule UniqueUser');

$file = beyond_support_path('Rules/UniqueUser.php');
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Support\\Rules', $contents);
$this->assertClassName('UniqueUser', $contents);
}

public function testCanMakeRuleUsingForce(): void
{
$this->artisan('beyond:make:rule User.User/UniqueUser');
$this->artisan('beyond:make:rule User/UniqueUser');

$file = beyond_support_path('Rules/User/UniqueUser.php');
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Support\\Rules\\User', $contents);
$this->assertClassName('UniqueUser', $contents);

$code = $this->artisan('beyond:make:rule User/UniqueUser --force');

Expand Down
8 changes: 4 additions & 4 deletions tests/Commands/MakeScopeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function testCanMakeScope(): void
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Domain\\User\\Scopes', $contents);
$this->assertClassName('ActiveScope', $contents);
}

public function testCanMakeScopeUsingForce(): void
Expand All @@ -26,8 +26,8 @@ public function testCanMakeScopeUsingForce(): void
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertNamespace('Domain\\User\\Scopes', $contents);
$this->assertClassName('ActiveScope', $contents);

$code = $this->artisan('beyond:make:scope User.ActiveScope --force');

Expand Down
3 changes: 2 additions & 1 deletion tests/Commands/MakeServiceProviderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function testCanMakeProvider(): void
$contents = file_get_contents($file);

$this->assertFileExists($file);
$this->assertStringNotContainsString('{{ module }}', $contents);
$this->assertNamespace('Support\\Providers', $contents);
$this->assertClassName('UserServiceProvider', $contents);
}

public function testCanMakeProviderUsingForce(): void
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@ private function removeDirectory(string $directory): void
closedir($handle);
rmdir($directory);
}

protected function assertNamespace(string $namespace, string $contents): void
{
$this->assertStringNotContainsString('{{ namespace }}', $contents);
$this->assertStringContainsString("namespace {$namespace};", $contents);
}

protected function assertClassName(string $className, string $contents): void
{
$this->assertStringNotContainsString('{{ className }}', $contents);
$this->assertStringContainsString("class {$className}", $contents);
}
}

0 comments on commit 38ec100

Please sign in to comment.