From 79baddf94301600a11f6dc2b72c69b944b42eed1 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Mon, 20 Oct 2025 14:55:14 +0300 Subject: [PATCH 01/13] refactor: set resource name in dump/fixtures --- src/Generators/AbstractTestsGenerator.php | 4 ++-- src/Generators/NovaTestGenerator.php | 14 ++++++------- src/Generators/TestsGenerator.php | 7 +++++++ tests/CommandTest.php | 16 +++++++-------- tests/NovaTestGeneratorTest.php | 24 +++++++++++------------ 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/Generators/AbstractTestsGenerator.php b/src/Generators/AbstractTestsGenerator.php index d64520c7..6ea85de8 100644 --- a/src/Generators/AbstractTestsGenerator.php +++ b/src/Generators/AbstractTestsGenerator.php @@ -13,6 +13,7 @@ abstract class AbstractTestsGenerator extends EntityGenerator protected array $fakerProperties = []; protected array $getFields = []; protected bool $withAuth = false; + protected string $entity; const array FIXTURE_TYPES = [ 'create' => ['request', 'response'], @@ -186,7 +187,6 @@ protected function getMockModel($model): array protected function generateFixtures(): void { $object = $this->getFixtureValuesList($this->model); - $entity = Str::snake($this->model); $this->createFixtureFolder(); @@ -195,7 +195,7 @@ protected function generateFixtures(): void foreach ($modifications as $modification) { $excepts = ($modification === 'request') ? ['id'] : []; - $this->generateFixture("{$type}_{$entity}_{$modification}.json", Arr::except($object, $excepts)); + $this->generateFixture("{$type}_" . Str::snake($this->entity) . "_{$modification}.json", Arr::except($object, $excepts)); } } } diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 5e97db10..7905fa0d 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -51,6 +51,8 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); + $this->entity = Str::afterLast($this->novaResourceClassName, '\\'); + parent::generate(); } else { event(new SuccessCreateMessage("Nova is not installed and NovaTest is skipped")); @@ -66,14 +68,12 @@ public function generateTests(): void $actions = $this->getActions(); $filters = $this->collectFilters(); - $resourceClass = Str::afterLast($this->novaResourceClassName, '\\'); - $fileContent = $this->getStub('nova_test', [ 'entity_namespace' => $this->getNamespace('models', $this->modelSubFolder), 'entity' => $this->model, - 'resource_name' => $resourceClass, + 'resource_name' => $this->entity, 'resource_namespace' => $this->novaResourceClassName, - 'snake_resource' => Str::snake($resourceClass), + 'snake_resource' => Str::snake($this->entity), 'dromedary_entity' => Str::lcfirst($this->model), 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, @@ -160,7 +160,7 @@ protected function loadNovaFilters() public function getTestClassName(): string { - return "Nova{$this->model}Test"; + return "Nova{$this->entity}Test"; } protected function isFixtureNeeded($type): bool @@ -218,8 +218,8 @@ protected function getFilters(): array protected function getDumpName(): string { - $modelName = Str::snake($this->model); + $entityName = Str::snake($this->entity); - return "nova_{$modelName}_dump.sql"; + return "nova_{$entityName}_dump.sql"; } } diff --git a/src/Generators/TestsGenerator.php b/src/Generators/TestsGenerator.php index 1fc58d60..afe82cb3 100644 --- a/src/Generators/TestsGenerator.php +++ b/src/Generators/TestsGenerator.php @@ -6,6 +6,13 @@ class TestsGenerator extends AbstractTestsGenerator { + public function generate(): void + { + $this->entity = $this->model; + + parent::generate(); + } + public function getTestClassName(): string { return "{$this->model}Test"; diff --git a/tests/CommandTest.php b/tests/CommandTest.php index b289dce1..6ef6feb5 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -91,10 +91,10 @@ public function testCallCommand() $this->assertGeneratedFileEquals('validation.php', 'lang/en/validation.php'); $this->assertGeneratedFileEquals('nova_resource.php', 'app/Nova/PostResource.php'); $this->assertGeneratedFileEquals('nova_test.php', 'tests/NovaPostResourceTest.php'); - $this->assertGeneratedFileEquals('nova_dump.php', 'tests/fixtures/NovaPostTest/nova_post_dump.sql'); - $this->assertGeneratedFileEquals('create_request.json', 'tests/fixtures/NovaPostTest/create_post_request.json'); - $this->assertGeneratedFileEquals('create_response.json', 'tests/fixtures/NovaPostTest/create_post_response.json'); - $this->assertGeneratedFileEquals('update_request.json', 'tests/fixtures/NovaPostTest/update_post_request.json'); + $this->assertGeneratedFileEquals('nova_dump.php', 'tests/fixtures/NovaPostResourceTest/nova_post_resource_dump.sql'); + $this->assertGeneratedFileEquals('create_request.json', 'tests/fixtures/NovaPostResourceTest/create_post_resource_request.json'); + $this->assertGeneratedFileEquals('create_response.json', 'tests/fixtures/NovaPostResourceTest/create_post_resource_response.json'); + $this->assertGeneratedFileEquals('update_request.json', 'tests/fixtures/NovaPostResourceTest/update_post_resource_request.json'); } public function testCallCommandSubFoldersModel() @@ -137,10 +137,10 @@ public function testCallCommandSubFoldersModel() $this->assertGeneratedFileEquals('create_response.json', 'tests/fixtures/PostTest/create_post_response.json'); $this->assertGeneratedFileEquals('update_request.json', 'tests/fixtures/PostTest/update_post_request.json'); $this->assertGeneratedFileEquals('validation.php', 'lang/en/validation.php'); - $this->assertGeneratedFileEquals('nova_dump.php', 'tests/fixtures/NovaPostTest/nova_post_dump.sql'); - $this->assertGeneratedFileEquals('create_request.json', 'tests/fixtures/NovaPostTest/create_post_request.json'); - $this->assertGeneratedFileEquals('create_response.json', 'tests/fixtures/NovaPostTest/create_post_response.json'); - $this->assertGeneratedFileEquals('update_request.json', 'tests/fixtures/NovaPostTest/update_post_request.json'); + $this->assertGeneratedFileEquals('nova_dump.php', 'tests/fixtures/NovaPostResourceTest/nova_post_resource_dump.sql'); + $this->assertGeneratedFileEquals('create_request.json', 'tests/fixtures/NovaPostResourceTest/create_post_resource_request.json'); + $this->assertGeneratedFileEquals('create_response.json', 'tests/fixtures/NovaPostResourceTest/create_post_resource_response.json'); + $this->assertGeneratedFileEquals('update_request.json', 'tests/fixtures/NovaPostResourceTest/update_post_resource_request.json'); } public function testMakeOnly() diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 84d1b59e..658f6c93 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -107,10 +107,10 @@ public function testNovaTestStubNotExist() ->generate(); $this->assertFileDoesNotExist('tests/NovaWelcomeBonusTest.php'); - $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusTest/nova_welcome_bonus_dump.sql'); - $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_request.json'); - $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_response.json'); - $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/update_welcome_bonus_request.json'); + $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusResourceTest/nova_welcome_bonus_resource_dump.sql'); + $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_request.json'); + $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_response.json'); + $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/update_welcome_bonus_resource_request.json'); $this->assertEventPushed( className: WarningEvent::class, @@ -140,10 +140,10 @@ public function testDumpStubNotExist() ->generate(); $this->assertGeneratedFileEquals('created_resource_test.php', 'tests/NovaWelcomeBonusResourceTest.php'); - $this->assertFileDoesNotExist('tests/fixtures/NovaWelcomeBonusTest/nova_welcome_bonus_dump.sql'); - $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_request.json'); - $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_response.json'); - $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/update_welcome_bonus_request.json'); + $this->assertFileDoesNotExist('tests/fixtures/NovaWelcomeBonusResourceTest/nova_welcome_bonus_resource_dump.sql'); + $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_request.json'); + $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_response.json'); + $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/update_welcome_bonus_resource_request.json'); $this->assertEventPushed( className: WarningEvent::class, @@ -177,10 +177,10 @@ public function testSuccess() ->generate(); $this->assertGeneratedFileEquals('created_resource_test.php', 'tests/NovaWelcomeBonusResourceTest.php'); - $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusTest/nova_welcome_bonus_dump.sql'); - $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_request.json'); - $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_response.json'); - $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/update_welcome_bonus_request.json'); + $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusResourceTest/nova_welcome_bonus_resource_dump.sql'); + $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_request.json'); + $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_response.json'); + $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/update_welcome_bonus_resource_request.json'); } public function testGenerateNovaPackageNotInstall() From 6b3eefecb60446b55207a751d8564c704b434c6e Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Thu, 23 Oct 2025 14:07:38 +0300 Subject: [PATCH 02/13] refactor: use getTestingEntityName --- src/Generators/AbstractTestsGenerator.php | 5 ++-- src/Generators/NovaTestGenerator.php | 30 ++++++++++++----------- src/Generators/TestsGenerator.php | 5 ++++ tests/NovaTestGeneratorTest.php | 3 +++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Generators/AbstractTestsGenerator.php b/src/Generators/AbstractTestsGenerator.php index 6ea85de8..31df9c8b 100644 --- a/src/Generators/AbstractTestsGenerator.php +++ b/src/Generators/AbstractTestsGenerator.php @@ -13,7 +13,6 @@ abstract class AbstractTestsGenerator extends EntityGenerator protected array $fakerProperties = []; protected array $getFields = []; protected bool $withAuth = false; - protected string $entity; const array FIXTURE_TYPES = [ 'create' => ['request', 'response'], @@ -195,7 +194,7 @@ protected function generateFixtures(): void foreach ($modifications as $modification) { $excepts = ($modification === 'request') ? ['id'] : []; - $this->generateFixture("{$type}_" . Str::snake($this->entity) . "_{$modification}.json", Arr::except($object, $excepts)); + $this->generateFixture("{$type}_" . Str::snake($this->getTestingEntityName()) . "_{$modification}.json", Arr::except($object, $excepts)); } } } @@ -259,6 +258,8 @@ abstract protected function isFixtureNeeded($type): bool; abstract protected function generateTests(): void; + abstract protected function getTestingEntityName(): string; + private function filterBadModelField($fields): array { return array_diff($fields, [ diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 0b213a31..9e19147d 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -21,13 +21,6 @@ class NovaTestGenerator extends AbstractTestsGenerator public function generate(): void { if (class_exists(NovaServiceProvider::class)) { - if ($this->classExists('nova', "Nova{$this->model}ResourceTest")) { - - $path = $this->getClassPath('nova', "Nova{$this->model}ResourceTest"); - - throw new ResourceAlreadyExistsException($path); - } - $novaResources = $this->getCommonNovaResources(); if (count($novaResources) > 1) { @@ -51,7 +44,11 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); - $this->entity = Str::afterLast($this->novaResourceClassName, '\\'); + if ($this->classExists('nova', "Nova{$this->getTestingEntityName()}Test")) { + $path = $this->getClassPath('nova', "Nova{$this->getTestingEntityName()}Test"); + + throw new ResourceAlreadyExistsException($path); + } parent::generate(); } else { @@ -71,9 +68,9 @@ public function generateTests(): void $fileContent = $this->getStub('nova_test', [ 'entity_namespace' => $this->getNamespace('models', $this->modelSubFolder), 'entity' => $this->model, - 'resource_name' => $this->entity, + 'resource_name' => $this->getTestingEntityName(), 'resource_namespace' => $this->novaResourceClassName, - 'snake_resource' => Str::snake($this->entity), + 'snake_resource' => Str::snake($this->getTestingEntityName()), 'dromedary_entity' => Str::lcfirst($this->model), 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, @@ -81,9 +78,9 @@ public function generateTests(): void 'models_namespace' => $this->getNamespace('models'), ]); - $this->saveClass('tests', "Nova{$this->model}ResourceTest", $fileContent); + $this->saveClass('tests', $this->getTestClassName(), $fileContent); - event(new SuccessCreateMessage("Created a new Nova test: Nova{$this->model}ResourceTest")); + event(new SuccessCreateMessage("Created a new Nova test: {$this->getTestClassName()}")); } protected function getActions(): array @@ -161,7 +158,7 @@ protected function loadNovaFilters() public function getTestClassName(): string { - return "Nova{$this->entity}Test"; + return "Nova{$this->getTestingEntityName()}Test"; } protected function isFixtureNeeded($type): bool @@ -219,8 +216,13 @@ protected function getFilters(): array protected function getDumpName(): string { - $entityName = Str::snake($this->entity); + $entityName = Str::snake($this->getTestingEntityName()); return "nova_{$entityName}_dump.sql"; } + + protected function getTestingEntityName(): string + { + return Str::afterLast($this->novaResourceClassName, '\\'); + } } diff --git a/src/Generators/TestsGenerator.php b/src/Generators/TestsGenerator.php index afe82cb3..8227a00f 100644 --- a/src/Generators/TestsGenerator.php +++ b/src/Generators/TestsGenerator.php @@ -60,4 +60,9 @@ protected function generateTests(): void event(new SuccessCreateMessage($createMessage)); } + + protected function getTestingEntityName(): string + { + return $this->model; + } } diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 658f6c93..c2be886f 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -68,6 +68,9 @@ public function testGenerateNovaTestAlreadyExists() $this->mockClass(NovaTestGenerator::class, [ $this->classExistsMethodCall(['nova', 'NovaPostResourceTest']), + $this->getCommonNovaResourcesMock([ + 'PostResource', + ]), ]); $this->assertExceptionThrew( From 4d704fab12f6d652afcda5d09301aae2e97fb3f2 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Sun, 26 Oct 2025 15:31:59 +0300 Subject: [PATCH 03/13] fix: remove useless --- src/Generators/TestsGenerator.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Generators/TestsGenerator.php b/src/Generators/TestsGenerator.php index 8227a00f..dcb267cb 100644 --- a/src/Generators/TestsGenerator.php +++ b/src/Generators/TestsGenerator.php @@ -6,13 +6,6 @@ class TestsGenerator extends AbstractTestsGenerator { - public function generate(): void - { - $this->entity = $this->model; - - parent::generate(); - } - public function getTestClassName(): string { return "{$this->model}Test"; From a43a514580b2e73ff23c00fc21c0595468d1c0d8 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Sun, 2 Nov 2025 22:59:28 +0300 Subject: [PATCH 04/13] style:fix --- src/Generators/AbstractTestsGenerator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Generators/AbstractTestsGenerator.php b/src/Generators/AbstractTestsGenerator.php index 31df9c8b..9d118518 100644 --- a/src/Generators/AbstractTestsGenerator.php +++ b/src/Generators/AbstractTestsGenerator.php @@ -189,12 +189,14 @@ protected function generateFixtures(): void $this->createFixtureFolder(); + $entity = Str::snake($this->getTestingEntityName()); + foreach (self::FIXTURE_TYPES as $type => $modifications) { if ($this->isFixtureNeeded($type)) { foreach ($modifications as $modification) { $excepts = ($modification === 'request') ? ['id'] : []; - $this->generateFixture("{$type}_" . Str::snake($this->getTestingEntityName()) . "_{$modification}.json", Arr::except($object, $excepts)); + $this->generateFixture("{$type}_{$entity}_{$modification}.json", Arr::except($object, $excepts)); } } } From 16f9a24a146e4a7fcad3bfa13194892eb8391370 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov <110885041+AZabolotnikov@users.noreply.github.com> Date: Tue, 4 Nov 2025 10:37:31 +0500 Subject: [PATCH 05/13] Apply suggestion from @AZabolotnikov --- src/Generators/NovaTestGenerator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 9e19147d..cb67418c 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -44,8 +44,10 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); - if ($this->classExists('nova', "Nova{$this->getTestingEntityName()}Test")) { - $path = $this->getClassPath('nova', "Nova{$this->getTestingEntityName()}Test"); + $entityName = $this->getTestingEntityName(); + + if ($this->classExists('nova', "Nova{$entityName}Test")) { + $path = $this->getClassPath('nova', "Nova{$entityName}Test"); throw new ResourceAlreadyExistsException($path); } From 32988da30dd1468c067eec4072fc353e4a207b8b Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Tue, 4 Nov 2025 14:24:05 +0300 Subject: [PATCH 06/13] style:fix --- src/Generators/NovaTestGenerator.php | 6 ++---- tests/NovaTestGeneratorTest.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index cb67418c..df153d17 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -44,10 +44,8 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); - $entityName = $this->getTestingEntityName(); - - if ($this->classExists('nova', "Nova{$entityName}Test")) { - $path = $this->getClassPath('nova', "Nova{$entityName}Test"); + if ($this->classExists('nova', $this->getTestClassName())) { + $path = $this->getClassPath('nova', $this->getTestClassName()); throw new ResourceAlreadyExistsException($path); } diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index c2be886f..4cc90741 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -109,7 +109,7 @@ public function testNovaTestStubNotExist() ->setModel('WelcomeBonus') ->generate(); - $this->assertFileDoesNotExist('tests/NovaWelcomeBonusTest.php'); + $this->assertFileDoesNotExist('tests/NovaWelcomeBonusResourceTest.php'); $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusResourceTest/nova_welcome_bonus_resource_dump.sql'); $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_request.json'); $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusResourceTest/create_welcome_bonus_resource_response.json'); From 1d3b358da9a9ae89885cbeadf5729c626c3d0bda Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Tue, 4 Nov 2025 14:43:54 +0300 Subject: [PATCH 07/13] fix: imports in nova test stub --- src/Generators/NovaTestGenerator.php | 10 +++------- stubs/nova_test.blade.php | 2 +- tests/fixtures/CommandTest/nova_test.php | 4 ++-- tests/fixtures/CommandTest/subfolder/nova_test.php | 4 ++-- .../NovaTestGeneratorTest/created_resource_test.php | 4 ++-- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index df153d17..0b396bbf 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -44,11 +44,7 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); - if ($this->classExists('nova', $this->getTestClassName())) { - $path = $this->getClassPath('nova', $this->getTestClassName()); - - throw new ResourceAlreadyExistsException($path); - } + $this->checkResourceExists('nova', $this->getTestClassName(), $this->modelSubFolder); parent::generate(); } else { @@ -66,7 +62,7 @@ public function generateTests(): void $filters = $this->collectFilters(); $fileContent = $this->getStub('nova_test', [ - 'entity_namespace' => $this->getNamespace('models', $this->modelSubFolder), + 'entity_namespace' => $this->generateNamespace('models', $this->modelSubFolder), 'entity' => $this->model, 'resource_name' => $this->getTestingEntityName(), 'resource_namespace' => $this->novaResourceClassName, @@ -75,7 +71,7 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, - 'models_namespace' => $this->getNamespace('models'), + 'models_namespace' => $this->generateNamespace('models', $this->modelSubFolder), ]); $this->saveClass('tests', $this->getTestClassName(), $fileContent); diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 6e81e8aa..03a2c248 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -5,7 +5,7 @@ use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use {{ $resource_namespace }}; -use {{ $models_namespace }}\User; +use Models\User; class Nova{{ $resource_name }}Test extends TestCase { diff --git a/tests/fixtures/CommandTest/nova_test.php b/tests/fixtures/CommandTest/nova_test.php index 67b3183c..30799a7c 100644 --- a/tests/fixtures/CommandTest/nova_test.php +++ b/tests/fixtures/CommandTest/nova_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use RonasIT\Support\Tests\Support\Command\Models\Post; +use Models\Post; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\PostResource; -use RonasIT\Support\Tests\Support\Command\Models\User; +use Models\User; class NovaPostResourceTest extends TestCase { diff --git a/tests/fixtures/CommandTest/subfolder/nova_test.php b/tests/fixtures/CommandTest/subfolder/nova_test.php index b26f67b0..7bca9e92 100644 --- a/tests/fixtures/CommandTest/subfolder/nova_test.php +++ b/tests/fixtures/CommandTest/subfolder/nova_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use RonasIT\Support\Tests\Support\Command\Models\Forum\Post; +use Models\Forum\Post; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\Forum\PostResource; -use RonasIT\Support\Tests\Support\Command\Models\User; +use Models\User; class NovaPostResourceTest extends TestCase { diff --git a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php index 158f73c1..c8c1188a 100644 --- a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php +++ b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use RonasIT\Support\Tests\Support\Models\WelcomeBonus; +use Models\WelcomeBonus; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\WelcomeBonusResource; -use RonasIT\Support\Tests\Support\Models\User; +use Models\User; class NovaWelcomeBonusResourceTest extends TestCase { From c5a3c41f87862c557e1cdf250646b43f74306648 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Tue, 4 Nov 2025 14:49:42 +0300 Subject: [PATCH 08/13] style: remove useless --- src/Generators/NovaTestGenerator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 0b396bbf..6f2d05cb 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -12,7 +12,6 @@ use RecursiveIteratorIterator; use RecursiveDirectoryIterator; use Illuminate\Support\Arr; -use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; class NovaTestGenerator extends AbstractTestsGenerator { From 05ce544cbc807c7f9f2346f7b366fcac28446977 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Fri, 7 Nov 2025 11:39:52 +0300 Subject: [PATCH 09/13] refactor: use models path for user model --- src/Generators/NovaTestGenerator.php | 1 + stubs/nova_test.blade.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 6f2d05cb..644bb782 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -71,6 +71,7 @@ public function generateTests(): void 'actions' => $actions, 'filters' => $filters, 'models_namespace' => $this->generateNamespace('models', $this->modelSubFolder), + 'user_model_path' => $this->generateNamespace('models') . '\User', ]); $this->saveClass('tests', $this->getTestClassName(), $fileContent); diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 03a2c248..b70b533f 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -5,7 +5,7 @@ use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use {{ $resource_namespace }}; -use Models\User; +use {{ $user_model_path }}; class Nova{{ $resource_name }}Test extends TestCase { From 1fb3467a948e2461f8401624fc63700887223eb8 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Mon, 10 Nov 2025 11:58:30 +0300 Subject: [PATCH 10/13] fix: remove useless --- src/Generators/NovaTestGenerator.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 644bb782..98d329e3 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -43,7 +43,7 @@ public function generate(): void $this->novaResourceClassName = Arr::first($novaResources); - $this->checkResourceExists('nova', $this->getTestClassName(), $this->modelSubFolder); + $this->checkResourceExists('nova', $this->getTestClassName()); parent::generate(); } else { @@ -70,7 +70,6 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, - 'models_namespace' => $this->generateNamespace('models', $this->modelSubFolder), 'user_model_path' => $this->generateNamespace('models') . '\User', ]); From 39503c881803be00d2345d444704862a6df8aeb3 Mon Sep 17 00:00:00 2001 From: Ruslan Guskov Date: Tue, 11 Nov 2025 12:10:27 +0300 Subject: [PATCH 11/13] fix: revert user export changes --- src/Generators/NovaTestGenerator.php | 2 +- stubs/nova_test.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 98d329e3..6e428be3 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -70,7 +70,7 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, - 'user_model_path' => $this->generateNamespace('models') . '\User', + 'models_namespace' => $this->generateNamespace('models'), ]); $this->saveClass('tests', $this->getTestClassName(), $fileContent); diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index b70b533f..6e81e8aa 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -5,7 +5,7 @@ use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use {{ $resource_namespace }}; -use {{ $user_model_path }}; +use {{ $models_namespace }}\User; class Nova{{ $resource_name }}Test extends TestCase { From 1e163055ebe6a69bcc575d7dd5c698c7bebd69f0 Mon Sep 17 00:00:00 2001 From: DenTray Date: Wed, 12 Nov 2025 12:25:44 +0600 Subject: [PATCH 12/13] Apply suggestions from code review --- src/Generators/NovaTestGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 6e428be3..2e8b27e6 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -61,7 +61,7 @@ public function generateTests(): void $filters = $this->collectFilters(); $fileContent = $this->getStub('nova_test', [ - 'entity_namespace' => $this->generateNamespace('models', $this->modelSubFolder), + 'entity_namespace' => $this->generateNamespace($this->paths['models'], $this->modelSubFolder), 'entity' => $this->model, 'resource_name' => $this->getTestingEntityName(), 'resource_namespace' => $this->novaResourceClassName, @@ -70,7 +70,7 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, - 'models_namespace' => $this->generateNamespace('models'), + 'models_namespace' => $this->generateNamespace($this->paths['models']), ]); $this->saveClass('tests', $this->getTestClassName(), $fileContent); From 29c4f085129ae9dc77ad59d563fe6e7da7b07af6 Mon Sep 17 00:00:00 2001 From: DenTray Date: Wed, 12 Nov 2025 12:29:06 +0600 Subject: [PATCH 13/13] Apply suggestions from code review --- tests/fixtures/CommandTest/nova_test.php | 4 ++-- tests/fixtures/CommandTest/subfolder/nova_test.php | 4 ++-- .../fixtures/NovaTestGeneratorTest/created_resource_test.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/fixtures/CommandTest/nova_test.php b/tests/fixtures/CommandTest/nova_test.php index 30799a7c..67b3183c 100644 --- a/tests/fixtures/CommandTest/nova_test.php +++ b/tests/fixtures/CommandTest/nova_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use Models\Post; +use RonasIT\Support\Tests\Support\Command\Models\Post; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\PostResource; -use Models\User; +use RonasIT\Support\Tests\Support\Command\Models\User; class NovaPostResourceTest extends TestCase { diff --git a/tests/fixtures/CommandTest/subfolder/nova_test.php b/tests/fixtures/CommandTest/subfolder/nova_test.php index 7bca9e92..b26f67b0 100644 --- a/tests/fixtures/CommandTest/subfolder/nova_test.php +++ b/tests/fixtures/CommandTest/subfolder/nova_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use Models\Forum\Post; +use RonasIT\Support\Tests\Support\Command\Models\Forum\Post; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\Forum\PostResource; -use Models\User; +use RonasIT\Support\Tests\Support\Command\Models\User; class NovaPostResourceTest extends TestCase { diff --git a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php index c8c1188a..158f73c1 100644 --- a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php +++ b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php @@ -2,12 +2,12 @@ namespace App\Tests; -use Models\WelcomeBonus; +use RonasIT\Support\Tests\Support\Models\WelcomeBonus; use PHPUnit\Framework\Attributes\DataProvider; use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\WelcomeBonusResource; -use Models\User; +use RonasIT\Support\Tests\Support\Models\User; class NovaWelcomeBonusResourceTest extends TestCase {