Skip to content

Conversation

@RGO230
Copy link
Contributor

@RGO230 RGO230 commented Jun 25, 2025

@RGO230 RGO230 assigned AZabolotnikov and RGO230 and unassigned AZabolotnikov Jun 27, 2025
@RGO230 RGO230 assigned AZabolotnikov and RGO230 and unassigned RGO230 and AZabolotnikov Jul 1, 2025
@RGO230 RGO230 assigned AZabolotnikov and unassigned RGO230 Jul 2, 2025
@AZabolotnikov AZabolotnikov assigned RGO230 and unassigned AZabolotnikov Jul 3, 2025
@RGO230 RGO230 assigned AZabolotnikov and RGO230 and unassigned RGO230 and AZabolotnikov Jul 9, 2025
@RGO230 RGO230 assigned RGO230 and unassigned AZabolotnikov Jul 10, 2025
@RGO230 RGO230 assigned AZabolotnikov and unassigned RGO230 Jul 11, 2025
}

if ($this->classExists('nova', "Nova{$this->model}Test")) {
$this->isNovaResourceExists();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->isNovaResourceExists();
$resource = $this->resourceName ?? $this->getNovaResource();
$this->shortNovaResourceName = Str::afterLast($resource, '\\');
$this->fullNovaResourcePath = "App\\Nova\\{$resource}";

}
}

protected function getNovaResource(): ?string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

return $resources;
}

protected function isValidCommonResourceCheck(string $resource)
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

}
}

protected function allCommonNovaResources(): Generator
Copy link
Contributor

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;
        }
    }
}

Copy link
Contributor

Copilot AI left a 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 NovaModelTest to NovaResourceNameTest format
  • Added --resource-name option 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;
Copy link

Copilot AI Aug 28, 2025

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.

Copilot uses AI. Check for mistakes.
return [
[
'request' => [
'TextField:description_field' => $this->novaSearchParams(['search term']),
Copy link

Copilot AI Aug 28, 2025

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.

Copilot uses AI. Check for mistakes.
{
return [
[
'action' => PublishPostAction::class,
Copy link

Copilot AI Aug 28, 2025

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.

Copilot uses AI. Check for mistakes.
@RGO230 RGO230 assigned AZabolotnikov and unassigned RGO230 Sep 2, 2025
protected function loadNovaFilters()
{
return app("\\App\\Nova\\{$this->novaModelName}")->filters(new NovaRequest());
return app("{$this->fullNovaResourcePath}")->filters(new NovaRequest());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Contributor

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return app("{$this->fullNovaResourcePath}")->actions(new NovaRequest());
return app($this->fullNovaResourcePath)->actions(new NovaRequest());

@AZabolotnikov
Copy link
Contributor

@RGO230 please don't touch this pull request until this request is merged #165

@RGO230 RGO230 closed this Sep 5, 2025
@RGO230 RGO230 deleted the 140-use-NovaResource-class-in-NovaTestGenerator-instead-of-Model branch September 5, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants