From c5423dc6d13b0308e06ed580a9a8bfc43e10ce91 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Thu, 16 Oct 2025 17:04:55 +0500 Subject: [PATCH 1/6] fix: usage relative file path in ResourceAlreadyExistsException --- src/Generators/EntityGenerator.php | 8 +++++--- tests/ControllerGeneratorTest.php | 2 +- tests/FactoryGeneratorTest.php | 2 +- tests/ModelGeneratorTest.php | 2 +- tests/NovaResourceGeneratorTest.php | 2 +- tests/NovaTestGeneratorTest.php | 2 +- tests/ResourceGeneratorTest.php | 4 ++-- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 44c8cd8..74455dc 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -145,16 +145,18 @@ abstract public function generate(): void; protected function classExists(string $path, string $name, ?string $subFolder = null): bool { - $classPath = $this->getClassPath($path, $name, $subFolder); + $relativePath = $this->getClassPath($path, $name, $subFolder); - return file_exists($classPath); + $absolutePath = base_path($relativePath); + + return file_exists($absolutePath); } protected function getClassPath(string $path, string $name, ?string $subFolder = null): string { $path = $this->getPath($path, $subFolder); - return base_path("{$path}/{$name}.php"); + return "{$path}/{$name}.php"; } protected function saveClass($path, $name, $content, ?string $entityFolder = null): string diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index e37b358..6c6fa7d 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -30,7 +30,7 @@ public function testControllerAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostController cause it already exists. Remove vfs://root/app/Http/Controllers/PostController.php and run command again.', + message: 'Cannot create PostController cause it already exists. Remove app/Http/Controllers/PostController.php and run command again.', ); app(ControllerGenerator::class) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index f96dced..60f4617 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -46,7 +46,7 @@ public function testFactoryClassExists() { $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostFactory cause it already exists. Remove vfs://root/database/factories/PostFactory.php and run command again.', + message: 'Cannot create PostFactory cause it already exists. Remove database/factories/PostFactory.php and run command again.', ); $this->mockFactoryGenerator( diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 41eaddf..e2326b5 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -30,7 +30,7 @@ public function testModelAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create Post cause it already exists. Remove vfs://root/app/Models/Blog/Post.php and run command again.', + message: 'Cannot create Post cause it already exists. Remove app/Models/Blog/Post.php and run command again.', ); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index d6882d3..4efd66c 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -63,7 +63,7 @@ public function testCreateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Nova/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Nova/PostResource.php and run command again.', ); app(NovaResourceGenerator::class) diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 226de1e..84d1b59 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -72,7 +72,7 @@ public function testGenerateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: "Cannot create NovaPostResourceTest cause it already exists. Remove vfs://root/app/Nova/NovaPostResourceTest.php and run command again.", + message: "Cannot create NovaPostResourceTest cause it already exists. Remove app/Nova/NovaPostResourceTest.php and run command again.", ); app(NovaTestGenerator::class) diff --git a/tests/ResourceGeneratorTest.php b/tests/ResourceGeneratorTest.php index 1bb1c78..e5c1e07 100644 --- a/tests/ResourceGeneratorTest.php +++ b/tests/ResourceGeneratorTest.php @@ -20,7 +20,7 @@ public function testResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove vfs://root/app/Http/Resources/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Http/Resources/PostResource.php and run command again.', ); app(ResourceGenerator::class) @@ -37,7 +37,7 @@ public function testCollectionResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostsCollectionResource cause it already exists. Remove vfs://root/app/Http/Resources/PostsCollectionResource.php and run command again.', + message: 'Cannot create PostsCollectionResource cause it already exists. Remove app/Http/Resources/PostsCollectionResource.php and run command again.', ); app(ResourceGenerator::class) From 3fbb2c7dfad115253e9b04f8b8e4ec44f596b628 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Thu, 16 Oct 2025 17:11:28 +0500 Subject: [PATCH 2/6] fix: usage relative file path in ResourceAlreadyExistsException --- src/Generators/NovaTestGenerator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 033717f..4234f35 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -43,7 +43,6 @@ public function generate(): void } if (empty($novaResources)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 $this->throwFailureException( ClassNotExistsException::class, "Cannot create Nova{$this->model}ResourceTest cause {$this->model} Nova resource does not exist.", From 145394d66b0d70063abc4de31c9f17bb9536c745 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Thu, 16 Oct 2025 17:12:59 +0500 Subject: [PATCH 3/6] fix: usage relative file path in ResourceAlreadyExistsException --- 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 4234f35..e74994d 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -6,7 +6,6 @@ use Laravel\Nova\NovaServiceProvider; use Laravel\Nova\Http\Requests\NovaRequest; use RonasIT\Support\Events\SuccessCreateMessage; -use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Exceptions\EntityCreateException; use Generator; @@ -43,6 +42,7 @@ public function generate(): void } if (empty($novaResources)) { + // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 $this->throwFailureException( ClassNotExistsException::class, "Cannot create Nova{$this->model}ResourceTest cause {$this->model} Nova resource does not exist.", From 79ec9881b85a744306ab68e1196d1e1b61e14578 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Thu, 16 Oct 2025 17:16:31 +0500 Subject: [PATCH 4/6] fix: usage relative file path in ResourceAlreadyExistsException --- src/Exceptions/ResourceAlreadyExistsException.php | 2 +- src/Generators/NovaTestGenerator.php | 1 - tests/ControllerGeneratorTest.php | 2 +- tests/FactoryGeneratorTest.php | 2 +- tests/ModelGeneratorTest.php | 2 +- tests/NovaResourceGeneratorTest.php | 2 +- tests/NovaTestGeneratorTest.php | 2 +- tests/ResourceGeneratorTest.php | 4 ++-- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Exceptions/ResourceAlreadyExistsException.php b/src/Exceptions/ResourceAlreadyExistsException.php index 3b1ea7a..70ce2a6 100644 --- a/src/Exceptions/ResourceAlreadyExistsException.php +++ b/src/Exceptions/ResourceAlreadyExistsException.php @@ -12,7 +12,7 @@ public function __construct( ) { $entity = $this->getEntity(); - parent::__construct("Cannot create {$entity} cause it already exists. Remove {$this->filePath} and run command again."); + parent::__construct("Cannot create {$entity} cause it already exists. Remove /{$this->filePath} and run command again."); } protected function getEntity(): string diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index e74994d..5e97db1 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -42,7 +42,6 @@ public function generate(): void } if (empty($novaResources)) { - // TODO: pass $this->modelSubfolder to Exception after refactoring in https://github.com/RonasIT/laravel-entity-generator/issues/179 $this->throwFailureException( ClassNotExistsException::class, "Cannot create Nova{$this->model}ResourceTest cause {$this->model} Nova resource does not exist.", diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index 6c6fa7d..eea90d5 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -30,7 +30,7 @@ public function testControllerAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostController cause it already exists. Remove app/Http/Controllers/PostController.php and run command again.', + message: 'Cannot create PostController cause it already exists. Remove /app/Http/Controllers/PostController.php and run command again.', ); app(ControllerGenerator::class) diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index 60f4617..94071c3 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -46,7 +46,7 @@ public function testFactoryClassExists() { $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostFactory cause it already exists. Remove database/factories/PostFactory.php and run command again.', + message: 'Cannot create PostFactory cause it already exists. Remove /database/factories/PostFactory.php and run command again.', ); $this->mockFactoryGenerator( diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index e2326b5..01f123c 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -30,7 +30,7 @@ public function testModelAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create Post cause it already exists. Remove app/Models/Blog/Post.php and run command again.', + message: 'Cannot create Post cause it already exists. Remove /app/Models/Blog/Post.php and run command again.', ); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 4efd66c..6909442 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -63,7 +63,7 @@ public function testCreateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove app/Nova/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove /app/Nova/PostResource.php and run command again.', ); app(NovaResourceGenerator::class) diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 84d1b59..d15c967 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -72,7 +72,7 @@ public function testGenerateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: "Cannot create NovaPostResourceTest cause it already exists. Remove app/Nova/NovaPostResourceTest.php and run command again.", + message: "Cannot create NovaPostResourceTest cause it already exists. Remove /app/Nova/NovaPostResourceTest.php and run command again.", ); app(NovaTestGenerator::class) diff --git a/tests/ResourceGeneratorTest.php b/tests/ResourceGeneratorTest.php index e5c1e07..f11fab7 100644 --- a/tests/ResourceGeneratorTest.php +++ b/tests/ResourceGeneratorTest.php @@ -20,7 +20,7 @@ public function testResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove app/Http/Resources/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove /app/Http/Resources/PostResource.php and run command again.', ); app(ResourceGenerator::class) @@ -37,7 +37,7 @@ public function testCollectionResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostsCollectionResource cause it already exists. Remove app/Http/Resources/PostsCollectionResource.php and run command again.', + message: 'Cannot create PostsCollectionResource cause it already exists. Remove /app/Http/Resources/PostsCollectionResource.php and run command again.', ); app(ResourceGenerator::class) From df4196b0d467d8ad75e9142a8243bd4311eb0cd9 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Mon, 20 Oct 2025 10:32:15 +0500 Subject: [PATCH 5/6] fix: usage relative file path in ResourceAlreadyExistsException --- tests/ControllerGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index eea90d5..6c6fa7d 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -30,7 +30,7 @@ public function testControllerAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostController cause it already exists. Remove /app/Http/Controllers/PostController.php and run command again.', + message: 'Cannot create PostController cause it already exists. Remove app/Http/Controllers/PostController.php and run command again.', ); app(ControllerGenerator::class) From 8a28f40b90cce285e80aae2a2172971e227f4ea2 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikov Date: Mon, 20 Oct 2025 10:32:41 +0500 Subject: [PATCH 6/6] fix: usage relative file path in ResourceAlreadyExistsException --- src/Exceptions/ResourceAlreadyExistsException.php | 2 +- tests/FactoryGeneratorTest.php | 2 +- tests/ModelGeneratorTest.php | 2 +- tests/NovaResourceGeneratorTest.php | 2 +- tests/NovaTestGeneratorTest.php | 2 +- tests/ResourceGeneratorTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Exceptions/ResourceAlreadyExistsException.php b/src/Exceptions/ResourceAlreadyExistsException.php index 70ce2a6..3b1ea7a 100644 --- a/src/Exceptions/ResourceAlreadyExistsException.php +++ b/src/Exceptions/ResourceAlreadyExistsException.php @@ -12,7 +12,7 @@ public function __construct( ) { $entity = $this->getEntity(); - parent::__construct("Cannot create {$entity} cause it already exists. Remove /{$this->filePath} and run command again."); + parent::__construct("Cannot create {$entity} cause it already exists. Remove {$this->filePath} and run command again."); } protected function getEntity(): string diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index 94071c3..60f4617 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -46,7 +46,7 @@ public function testFactoryClassExists() { $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostFactory cause it already exists. Remove /database/factories/PostFactory.php and run command again.', + message: 'Cannot create PostFactory cause it already exists. Remove database/factories/PostFactory.php and run command again.', ); $this->mockFactoryGenerator( diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php index 01f123c..e2326b5 100644 --- a/tests/ModelGeneratorTest.php +++ b/tests/ModelGeneratorTest.php @@ -30,7 +30,7 @@ public function testModelAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create Post cause it already exists. Remove /app/Models/Blog/Post.php and run command again.', + message: 'Cannot create Post cause it already exists. Remove app/Models/Blog/Post.php and run command again.', ); app(ModelGenerator::class) diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 6909442..4efd66c 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -63,7 +63,7 @@ public function testCreateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove /app/Nova/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Nova/PostResource.php and run command again.', ); app(NovaResourceGenerator::class) diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index d15c967..84d1b59 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -72,7 +72,7 @@ public function testGenerateNovaTestAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: "Cannot create NovaPostResourceTest cause it already exists. Remove /app/Nova/NovaPostResourceTest.php and run command again.", + message: "Cannot create NovaPostResourceTest cause it already exists. Remove app/Nova/NovaPostResourceTest.php and run command again.", ); app(NovaTestGenerator::class) diff --git a/tests/ResourceGeneratorTest.php b/tests/ResourceGeneratorTest.php index f11fab7..e5c1e07 100644 --- a/tests/ResourceGeneratorTest.php +++ b/tests/ResourceGeneratorTest.php @@ -20,7 +20,7 @@ public function testResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostResource cause it already exists. Remove /app/Http/Resources/PostResource.php and run command again.', + message: 'Cannot create PostResource cause it already exists. Remove app/Http/Resources/PostResource.php and run command again.', ); app(ResourceGenerator::class) @@ -37,7 +37,7 @@ public function testCollectionResourceAlreadyExists() $this->assertExceptionThrew( className: ResourceAlreadyExistsException::class, - message: 'Cannot create PostsCollectionResource cause it already exists. Remove /app/Http/Resources/PostsCollectionResource.php and run command again.', + message: 'Cannot create PostsCollectionResource cause it already exists. Remove app/Http/Resources/PostsCollectionResource.php and run command again.', ); app(ResourceGenerator::class)