From 232b8b2a742d480e30f02b1ef94d4f886c618073 Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Mon, 20 Oct 2025 15:50:46 +0900 Subject: [PATCH 1/6] fix: add user model import to nova test stub refs: https://github.com/RonasIT/laravel-entity-generator/issues/212 --- stubs/nova_test.blade.php | 1 + tests/fixtures/NovaTestGeneratorTest/created_resource_test.php | 1 + 2 files changed, 2 insertions(+) diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 450a1060..0e3aa3e1 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -5,6 +5,7 @@ use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use {{ $resource_namespace }}; +use App\Models\User; class Nova{{ $resource_name }}Test extends TestCase { diff --git a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php index 0357559a..82c64248 100644 --- a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php +++ b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php @@ -7,6 +7,7 @@ use RonasIT\Support\Testing\ModelTestState; use RonasIT\Support\Traits\NovaTestTrait; use App\Nova\WelcomeBonusResource; +use App\Models\User; class NovaWelcomeBonusResourceTest extends TestCase { From a581b282098431ada49d4e85f02f1632227a64c7 Mon Sep 17 00:00:00 2001 From: Ni Nelli Date: Mon, 20 Oct 2025 16:51:38 +0900 Subject: [PATCH 2/6] refactor: get models directory namespace for user import refs: https://github.com/RonasIT/laravel-entity-generator/issues/212 --- src/Generators/NovaTestGenerator.php | 1 + stubs/nova_test.blade.php | 2 +- tests/NovaTestGeneratorTest.php | 8 +++--- .../NovaTestGeneratorTest/Models/User.php | 25 +++++++++++++++++++ .../Models/WelcomeBonus.php | 25 +++++++++++++++++++ .../created_resource_test.php | 4 +-- 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 tests/Support/NovaTestGeneratorTest/Models/User.php create mode 100644 tests/Support/NovaTestGeneratorTest/Models/WelcomeBonus.php diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 5e97db10..44a2a486 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -78,6 +78,7 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, + 'user_namespace' => $this->getNamespace('models'), ]); $this->saveClass('tests', "Nova{$this->model}ResourceTest", $fileContent); diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 0e3aa3e1..4bc33629 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 App\Models\User; +use {{ $user_namespace }}\User; class Nova{{ $resource_name }}Test extends TestCase { diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 84d1b59e..dee08589 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -3,7 +3,7 @@ namespace RonasIT\Support\Tests; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; -use RonasIT\Support\Tests\Support\Models\WelcomeBonus; +use RonasIT\Support\Tests\Support\NovaTestGeneratorTest\Models\WelcomeBonus; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -83,7 +83,7 @@ className: ResourceAlreadyExistsException::class, public function testNovaTestStubNotExist() { config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', 'entity-generator.stubs.nova_test' => 'incorrect_stub', ]); @@ -125,7 +125,7 @@ public function testDumpStubNotExist() $this->mockNovaRequestClassCall(); config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', 'entity-generator.stubs.dump' => 'incorrect_stub', ]); @@ -154,7 +154,7 @@ className: WarningEvent::class, public function testSuccess() { config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', ]); $this->mockDBTransactionStartRollback(); diff --git a/tests/Support/NovaTestGeneratorTest/Models/User.php b/tests/Support/NovaTestGeneratorTest/Models/User.php new file mode 100644 index 00000000..924f7f5a --- /dev/null +++ b/tests/Support/NovaTestGeneratorTest/Models/User.php @@ -0,0 +1,25 @@ +belongsTo(Role::class); + } +} diff --git a/tests/Support/NovaTestGeneratorTest/Models/WelcomeBonus.php b/tests/Support/NovaTestGeneratorTest/Models/WelcomeBonus.php new file mode 100644 index 00000000..350fedb6 --- /dev/null +++ b/tests/Support/NovaTestGeneratorTest/Models/WelcomeBonus.php @@ -0,0 +1,25 @@ + Date: Mon, 20 Oct 2025 17:03:37 +0900 Subject: [PATCH 3/6] refactor: use general models path for NovaTestGeneratorTest refs: https://github.com/RonasIT/laravel-entity-generator/issues/212 --- tests/NovaTestGeneratorTest.php | 8 +++--- .../Models/User.php | 2 +- .../Models/WelcomeBonus.php | 25 ------------------- tests/fixtures/CommandTest/nova_test.php | 1 + .../CommandTest/subfolder/nova_test.php | 1 + .../created_resource_test.php | 4 +-- 6 files changed, 9 insertions(+), 32 deletions(-) rename tests/Support/{NovaTestGeneratorTest => }/Models/User.php (85%) delete mode 100644 tests/Support/NovaTestGeneratorTest/Models/WelcomeBonus.php diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index dee08589..84d1b59e 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -3,7 +3,7 @@ namespace RonasIT\Support\Tests; use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; -use RonasIT\Support\Tests\Support\NovaTestGeneratorTest\Models\WelcomeBonus; +use RonasIT\Support\Tests\Support\Models\WelcomeBonus; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassNotExistsException; @@ -83,7 +83,7 @@ className: ResourceAlreadyExistsException::class, public function testNovaTestStubNotExist() { config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', 'entity-generator.stubs.nova_test' => 'incorrect_stub', ]); @@ -125,7 +125,7 @@ public function testDumpStubNotExist() $this->mockNovaRequestClassCall(); config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', 'entity-generator.stubs.dump' => 'incorrect_stub', ]); @@ -154,7 +154,7 @@ className: WarningEvent::class, public function testSuccess() { config([ - 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/NovaTestGeneratorTest/Models', + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', ]); $this->mockDBTransactionStartRollback(); diff --git a/tests/Support/NovaTestGeneratorTest/Models/User.php b/tests/Support/Models/User.php similarity index 85% rename from tests/Support/NovaTestGeneratorTest/Models/User.php rename to tests/Support/Models/User.php index 924f7f5a..a4d15a5b 100644 --- a/tests/Support/NovaTestGeneratorTest/Models/User.php +++ b/tests/Support/Models/User.php @@ -1,6 +1,6 @@ Date: Mon, 20 Oct 2025 17:26:08 +0900 Subject: [PATCH 4/6] chore: remove redundant code refs: https://github.com/RonasIT/laravel-entity-generator/issues/212 --- tests/Support/Models/User.php | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 tests/Support/Models/User.php diff --git a/tests/Support/Models/User.php b/tests/Support/Models/User.php deleted file mode 100644 index a4d15a5b..00000000 --- a/tests/Support/Models/User.php +++ /dev/null @@ -1,25 +0,0 @@ -belongsTo(Role::class); - } -} From d453ab6e8a86f5fcdb814cd626e161c7de9606d0 Mon Sep 17 00:00:00 2001 From: DenTray Date: Thu, 23 Oct 2025 13:07:25 +0600 Subject: [PATCH 5/6] Apply suggestion from @DenTray --- stubs/nova_test.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 4bc33629..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_namespace }}\User; +use {{ $models_namespace }}\User; class Nova{{ $resource_name }}Test extends TestCase { From b367b1f8c244ff9435e966d90482450277f570c3 Mon Sep 17 00:00:00 2001 From: DenTray Date: Thu, 23 Oct 2025 13:07:30 +0600 Subject: [PATCH 6/6] Apply suggestion from @DenTray --- src/Generators/NovaTestGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 44a2a486..996c3fa9 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -78,7 +78,7 @@ public function generateTests(): void 'lower_entities' => $this->getPluralName(Str::snake($this->model)), 'actions' => $actions, 'filters' => $filters, - 'user_namespace' => $this->getNamespace('models'), + 'models_namespace' => $this->getNamespace('models'), ]); $this->saveClass('tests', "Nova{$this->model}ResourceTest", $fileContent);