-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: use resource in generate only nova tests #163
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
refactor: use resource in generate only nova tests #163
Conversation
src/Generators/NovaTestGenerator.php
Outdated
| } | ||
|
|
||
| if ($this->classExists('nova', "Nova{$this->model}Test")) { | ||
| $this->isNovaResourceExists(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $this->isNovaResourceExists(); | |
| $resource = $this->resourceName ?? $this->getNovaResource(); | |
| $this->shortNovaResourceName = Str::afterLast($resource, '\\'); | |
| $this->fullNovaResourcePath = "App\\Nova\\{$resource}"; |
src/Generators/NovaTestGenerator.php
Outdated
| } | ||
| } | ||
|
|
||
| protected function getNovaResource(): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| protected function getNovaResource(): ?string | |
| protected function getNovaResource(): string | |
| { | |
| $commonResources = $this->getCommonNovaResources(); | |
| if (count($commonResources) > 1) { | |
| $commonResources = implode(', ', $commonResources); | |
| $this->throwFailureException( | |
| EntityCreateException::class, | |
| "Cannot create Nova{$this->model}Resource Test cause was found a lot of suitable resources: $commonResources", | |
| "Please, use --resource-name option" | |
| ); | |
| } | |
| return array_pop($commonResources); | |
| } |
src/Generators/NovaTestGenerator.php
Outdated
| return $resources; | ||
| } | ||
|
|
||
| protected function isValidCommonResourceCheck(string $resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please separate the checks to two methods isValidCommonResourceCheck - not need
$this->isNovaResource($class)
$this->isResourceNameContainModel($class)
| } | ||
| } | ||
|
|
||
| protected function getCommonNovaResources(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| protected function getCommonNovaResources(): array | |
| protected function getCommonNovaResources(): array | |
| { | |
| $resources = []; | |
| foreach ($this->getNovaFiles() as $file) { | |
| $relativePath = Str::after($file->getPathname(), $this->novaPath . DIRECTORY_SEPARATOR); | |
| $class = str_replace(['/', '.php'], ['\\', ''], $relativePath); | |
| if ($this->isNovaResource($class) && $this->isResourceNameContainModel($class)) { | |
| $resources[] = $class; | |
| } | |
| } | |
| return $resources; | |
| } |
src/Generators/NovaTestGenerator.php
Outdated
| } | ||
| } | ||
|
|
||
| protected function allCommonNovaResources(): Generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function getNovaFiles(): Generator
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->novaPath));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
yield $file;
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the Nova test generator to use the Laravel Nova Resource class import, addressing GitHub issue #159. The changes improve the structure and naming conventions for Nova test generation and add support for specifying custom resource names.
Key changes:
- Added explicit
use Laravel\Nova\Resource;imports to generated Nova resource files - Renamed Nova test files from
NovaModelTesttoNovaResourceNameTestformat - Added
--resource-nameoption for specifying custom Nova resource names when generating tests
Reviewed Changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| stubs/nova_resource.blade.php | Added explicit Laravel\Nova\Resource import |
| src/Generators/NovaTestGenerator.php | Major refactor to support resource-based naming and custom resource names |
| src/Commands/MakeEntityCommand.php | Added --resource-name command option |
| tests/fixtures/ | Multiple test fixture files updated to reflect new naming conventions |
| tests/Support/ | Updated test support files and mocks for new resource handling |
| composer.json | Added Laravel\Nova namespace mapping for tests |
| ReadMe.md | Updated documentation with new command options |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| { | ||
| use NovaTestTrait; | ||
|
|
||
| protected static User $user; |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing import for User class. The User class is referenced but not imported at the top of the file.
| return [ | ||
| [ | ||
| 'request' => [ | ||
| 'TextField:description_field' => $this->novaSearchParams(['search term']), |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method novaSearchParams is called as an instance method with $this-> but this appears to be in a static context within a data provider method.
| { | ||
| return [ | ||
| [ | ||
| 'action' => PublishPostAction::class, |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing import for PublishPostAction class. The class is referenced but not imported at the top of the file.
| protected function loadNovaFilters() | ||
| { | ||
| return app("\\App\\Nova\\{$this->novaModelName}")->filters(new NovaRequest()); | ||
| return app("{$this->fullNovaResourcePath}")->filters(new NovaRequest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return app("{$this->fullNovaResourcePath}")->filters(new NovaRequest()); | |
| return app($this->fullNovaResourcePath)->filters(new NovaRequest()); |
|
|
||
| protected function isResourceNameContainModel(string $resource): bool | ||
| { | ||
| return Str::afterLast(str_replace('Resource', '', $resource), '\\') === $this->model; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contain or hard equal? Are you sure? If resourse will have name WelcomeBonusDraftResource.php
| protected function loadNovaFields() | ||
| { | ||
| return app("\\App\\Nova\\{$this->novaModelName}")->fields(new NovaRequest()); | ||
| return app("{$this->fullNovaResourcePath}")->fields(new NovaRequest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return app("{$this->fullNovaResourcePath}")->fields(new NovaRequest()); | |
| return app($this->fullNovaResourcePath)->fields(new NovaRequest()); |
| protected function loadNovaActions() | ||
| { | ||
| return app("\\App\\Nova\\{$this->novaModelName}")->actions(new NovaRequest()); | ||
| return app("{$this->fullNovaResourcePath}")->actions(new NovaRequest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return app("{$this->fullNovaResourcePath}")->actions(new NovaRequest()); | |
| return app($this->fullNovaResourcePath)->actions(new NovaRequest()); |
#159