Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use default ViewModels namespace as a prefix #43

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/Console/ViewModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ protected function getStub()

protected function getDefaultNamespace($rootNamespace)
{
if ($this->isCustomNamespace()) {
return $rootNamespace;
}

return $rootNamespace.'\ViewModels';
}

Expand All @@ -43,9 +39,4 @@ protected function getOptions(): array
['force', null, InputOption::VALUE_NONE, 'Create the class even if the view-model already exists'],
];
}

protected function isCustomNamespace(): bool
{
return Str::contains($this->argument('name'), '/');
}
}
4 changes: 2 additions & 2 deletions tests/ViewModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public function it_can_create_a_view_model_with_a_custom_namespace()

$this->assertStringContainsString('ViewModel created successfully.', Artisan::output());

$shouldOutputFilePath = $this->app['path'].'/Blog/PostsViewModel.php';
$shouldOutputFilePath = $this->app['path'].'/ViewModels/Blog/PostsViewModel.php';

$this->assertTrue(File::exists($shouldOutputFilePath), 'File exists in custom app/Blog folder');

$contents = File::get($shouldOutputFilePath);

$this->assertStringContainsString('namespace App\Blog;', $contents);
$this->assertStringContainsString('namespace App\ViewModels\Blog;', $contents);

$this->assertStringContainsString('class PostsViewModel extends ViewModel', $contents);
}
Expand Down